Skip to content

Commit

Permalink
[Add] glance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeprubio committed Jul 19, 2024
1 parent 4dd346f commit f578af5
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 10 deletions.
9 changes: 8 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {

defaultConfig {
applicationId ="com.rumosoft.marvelcompose"
minSdk = 21
minSdk = 26
targetSdk = 34
versionCode = 1
versionName = "1.0"
Expand Down Expand Up @@ -106,8 +106,15 @@ dependencies {
androidTestImplementation(libs.hilt.android.testing)
kspAndroidTest(libs.hilt.android.compiler)

androidTestImplementation(libs.glance.testing)
androidTestImplementation(libs.glance.appwidget.testing)

debugImplementation(libs.ui.tooling)
debugImplementation(libs.ui.test.manifest)

debugImplementation(libs.glance.preview)
debugImplementation(libs.glance.appwidget.preview)
debugImplementation(libs.glance.appwidget.host)
}

tasks.withType<Test> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.rumosoft.marvelcompose.presentation.widget

import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.glance.appwidget.testing.unit.runGlanceAppWidgetUnitTest
import androidx.glance.testing.unit.assertHasClickAction
import androidx.glance.testing.unit.hasText
import org.junit.Test

class WidgetContentKtTest {
@Test
fun widgetContent_checkTextContent() = runGlanceAppWidgetUnitTest {
setAppWidgetSize(DpSize(200.dp, 100.dp))

provideComposable {
WidgetContent()
}

onNode(hasText("MARVEL"))
.assertExists()
onNode(hasText("Characters"))
.assertExists()
onNode(hasText("Comics"))
.assertExists()
}

@Test
fun widgetContent_checkClickableButtons() = runGlanceAppWidgetUnitTest {
setAppWidgetSize(DpSize(200.dp, 100.dp))

provideComposable {
WidgetContent()
}

onNode(hasText("Characters"))
.assertHasClickAction()
onNode(hasText("Comics"))
.assertHasClickAction()
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package com.rumosoft.marvelcompose.presentation.widget

import android.content.Context
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.datastore.preferences.core.preferencesOf
import androidx.glance.GlanceId
import androidx.glance.GlanceTheme
import androidx.glance.appwidget.ExperimentalGlanceRemoteViewsApi
import androidx.glance.appwidget.GlanceAppWidget
import androidx.glance.appwidget.provideContent
import androidx.glance.material3.ColorProviders
import androidx.glance.preview.ExperimentalGlancePreviewApi
import androidx.glance.preview.Preview
import com.google.android.glance.appwidget.host.glance.GlanceAppWidgetHostPreview
import com.rumosoft.components.presentation.theme.DarkColorPalette
import com.rumosoft.components.presentation.theme.LightColorPalette

Expand All @@ -25,3 +35,18 @@ class MarvelAppWidget : GlanceAppWidget() {
}
}
}

@OptIn(ExperimentalGlancePreviewApi::class, ExperimentalGlanceRemoteViewsApi::class)
@Preview
@Composable
fun PreviewMarvelAppWidget() {
val displaySize = DpSize(200.dp, 200.dp)
val state = preferencesOf()

GlanceAppWidgetHostPreview(
modifier = Modifier.fillMaxSize(),
glanceAppWidget = MarvelAppWidget(),
state = state,
displaySize = displaySize,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ private fun openDeepLink(context: Context, deepLink: String) {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
}
context.startActivity(intent)
}
}
2 changes: 1 addition & 1 deletion feature-characters/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
compileSdk = 34

defaultConfig {
minSdk = 21
minSdk = 26
testOptions.targetSdk = 34

testApplicationId = "com.rumosoft.marvelcomposetest"
Expand Down
2 changes: 1 addition & 1 deletion feature-comics/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
compileSdk = 34

defaultConfig {
minSdk = 21
minSdk = 26
testOptions.targetSdk = 34

testApplicationId = "com.rumosoft.marvelcomposetest"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
android.enableJetifier=false
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
android.defaults.buildfeatures.buildconfig=false
Expand Down
14 changes: 11 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
agp = "8.5.0"
agp = "8.5.1"
compose-bom = "2024.06.00"
konsist = "0.15.1"
kotlin = "2.0.0"
Expand All @@ -13,7 +13,7 @@ activity-compose = "1.9.0"
retrofit = "2.11.0"
hilt = "2.51.1"
hilt-navigation-compose = "1.2.0"
coil-compose = "2.6.0"
coil-compose = "2.7.0"
window = "1.3.0"
kotlinx-serialization-json = "1.7.1"
navigation-runtime-ktx = "2.7.7"
Expand All @@ -29,14 +29,15 @@ androidx-test-ext-junit = "1.2.1"
espresso = "3.6.1"
junitparams = "1.1.1"
junit-jupiter = "5.10.2"
mockk = "1.13.11"
mockk = "1.13.12"
coroutines-test = "1.8.1"
mockwebserver = "4.12.0"
secrets-gradle-plugin = "2.0.1"
shot = "6.1.0"
versions = "0.51.0"
ksp = "2.0.0-1.0.22"
glance = "1.1.0"
glance-experimental = "0.2.2"
ui-tooling-preview-android = "1.6.8"
test-core = "1.6.1"

Expand Down Expand Up @@ -74,6 +75,13 @@ coil-compose = { group = "io.coil-kt", name = "coil-compose", version.ref = "coi
glance-widget = { group = "androidx.glance", name = "glance-appwidget", version.ref = "glance" }
glance-material3 = { group = "androidx.glance", name = "glance-material3", version.ref = "glance" }

glance-testing = { group = "androidx.glance", name = "glance-testing", version.ref = "glance" }
glance-appwidget-testing = { group = "androidx.glance", name = "glance-appwidget-testing", version.ref = "glance" }

glance-preview = { group = "androidx.glance", name = "glance-preview", version.ref = "glance" }
glance-appwidget-preview = { group = "androidx.glance", name = "glance-appwidget-preview", version.ref = "glance" }
glance-appwidget-host = { group = "com.google.android.glance.tools", name = "appwidget-host", version.ref = "glance-experimental" }

hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" }
hilt-android-compiler = { group = "com.google.dagger", name = "hilt-compiler", version.ref = "hilt" }
hilt-navigation-compose = { group = "androidx.hilt", name = "hilt-navigation-compose", version.ref = "hilt-navigation-compose" }
Expand Down
2 changes: 1 addition & 1 deletion library-components/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
compileSdk = 34

defaultConfig {
minSdk = 21
minSdk = 26
testOptions.targetSdk = 34

testApplicationId = "com.rumosoft.marvelcomposetest"
Expand Down
2 changes: 1 addition & 1 deletion library-marvelapi/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
compileSdk = 34

defaultConfig {
minSdk = 21
minSdk = 26
testOptions.targetSdk = 34

testApplicationId = "com.rumosoft.marvelcomposetest"
Expand Down

0 comments on commit f578af5

Please sign in to comment.