Skip to content

Commit

Permalink
[#354] [Sample] Add initial HomeScreenTest
Browse files Browse the repository at this point in the history
  • Loading branch information
luongvo committed Jan 11, 2023
1 parent a496023 commit 28984b3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 13 deletions.
26 changes: 18 additions & 8 deletions sample-compose/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ android {
targetSdk = Versions.ANDROID_TARGET_SDK_VERSION
versionCode = Versions.ANDROID_VERSION_CODE
versionName = Versions.ANDROID_VERSION_NAME
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
Expand Down Expand Up @@ -87,6 +88,12 @@ android {
compose = true
}

packagingOptions {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1,*.md}"
}
}

lint {
checkDependencies = true
xmlReport = true
Expand All @@ -101,6 +108,13 @@ android {
}
}
}
animationsDisabled = true
// https://github.com/mockk/mockk/issues/297#issuecomment-901924678
packagingOptions {
jniLibs {
useLegacyPackaging = true
}
}
}
}

Expand Down Expand Up @@ -145,15 +159,11 @@ dependencies {
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.KOTLINX_COROUTINES_VERSION}")
testImplementation("io.kotest:kotest-assertions-core:${Versions.TEST_KOTEST_VERSION}")
testImplementation("junit:junit:${Versions.TEST_JUNIT_VERSION}")
testImplementation("androidx.test:core:${Versions.TEST_ANDROIDX_CORE_VERSION}")
testImplementation("androidx.test:runner:${Versions.TEST_RUNNER_VERSION}")
testImplementation("androidx.test:rules:${Versions.TEST_RUNNER_VERSION}")
testImplementation("androidx.test.ext:junit-ktx:${Versions.TEST_JUNIT_ANDROIDX_EXT_VERSION}")
testImplementation("com.google.dagger:hilt-android-testing:${Versions.HILT_VERSION}")
testImplementation("org.jetbrains.kotlin:kotlin-reflect:${Versions.KOTLIN_REFLECT_VERSION}")
testImplementation("io.mockk:mockk:${Versions.TEST_MOCKK_VERSION}")
testImplementation("app.cash.turbine:turbine:${Versions.TEST_TURBINE}")

kaptTest("com.google.dagger:hilt-android-compiler:${Versions.HILT_VERSION}")
testAnnotationProcessor("com.google.dagger:hilt-android-compiler:${Versions.HILT_VERSION}")
androidTestImplementation("androidx.test:core:${Versions.TEST_ANDROIDX_CORE_VERSION}")
// Need to have BOM for androidTestImplementation https://github.com/gradle/gradle/issues/23347
androidTestImplementation(platform("androidx.compose:compose-bom:${Versions.COMPOSE_BOM_VERSION}"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package co.nimblehq.sample.compose.ui.screens.home

import androidx.activity.compose.setContent
import androidx.compose.ui.test.*
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import co.nimblehq.sample.compose.ui.AppDestination
import co.nimblehq.sample.compose.ui.screens.MainActivity
import org.junit.*
import org.junit.runner.RunWith

@ExperimentalTestApi
@RunWith(AndroidJUnit4::class)
class HomeScreenTest {

@get:Rule
val composeRule = createAndroidComposeRule<MainActivity>()

private var expectedAppDestination: AppDestination? = null

@Before
fun setup() {
composeRule.activity.setContent {
HomeScreen(
navigator = { destination -> expectedAppDestination = destination }
)
}
}

@Test
fun when_entering_the_Home_screen__it_shows_UI_correctly() {
composeRule.run {
onNodeWithText("Home").assertIsDisplayed()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ fun HomeScreen(
val showLoading: IsLoading by viewModel.showLoading.collectAsState()
val uiModels: List<UiModel> by viewModel.uiModels.collectAsState()

CameraPermission()
// TODO test permission
// CameraPermission()

HomeScreenContent(
uiModels = uiModels,
Expand Down
6 changes: 2 additions & 4 deletions sample-compose/buildSrc/src/main/java/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ object Versions {
const val CHUCKER_VERSION = "3.5.2"
const val COMPOSE_BOM_VERSION = "2022.12.00"
const val COMPOSE_COMPILER_VERSION = "1.3.2"
const val COMPOSE_NAVIGATION_VERSION = "2.5.1"
const val COMPOSE_NAVIGATION_VERSION = "2.5.2"

const val HILT_VERSION = "2.44"
const val HILT_NAVIGATION_COMPOSE_VERSION = "1.0.0"

const val JAVAX_INJECT_VERSION = "1"

const val KOTLIN_REFLECT_VERSION = "1.7.20"
const val KOTLIN_VERSION = "1.7.20"
const val KOTLINX_COROUTINES_VERSION = "1.6.4"
const val KOVER_VERSION = "0.6.0"
Expand All @@ -42,8 +41,7 @@ object Versions {
const val DETEKT_VERSION = "1.21.0"

// Testing libraries
const val TEST_ANDROIDX_CORE_VERSION = "1.4.0"
const val TEST_JUNIT_ANDROIDX_EXT_VERSION = "1.1.2"
const val TEST_ANDROIDX_CORE_VERSION = "1.5.0"
const val TEST_JUNIT_VERSION = "4.13.2"
const val TEST_KOTEST_VERSION = "4.6.3"
const val TEST_MOCKK_VERSION = "1.10.6"
Expand Down

0 comments on commit 28984b3

Please sign in to comment.