Skip to content

Commit 6a2f966

Browse files
authored
Merge pull request #117 from joreilly/cmp_ui_tests
Initial CMP UI test
2 parents 4cd5b1e + 95e0718 commit 6a2f966

File tree

5 files changed

+56
-10
lines changed

5 files changed

+56
-10
lines changed

.github/workflows/android.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,5 @@ jobs:
1717
- name: Build android app
1818
run: ./gradlew assembleDebug
1919
- name: Run Unit Tests
20-
run: ./gradlew test
21-
- name: Build iOS shared code
22-
run: ./gradlew :composeApp:compileKotlinIosSimulatorArm64
20+
run: ./gradlew allTests
2321

.github/workflows/build-and-publish-web.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
# If main branch update, deploy to gh-pages
2929
- name: Deploy
3030
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'
31-
uses: JamesIves/[email protected].4
31+
uses: JamesIves/[email protected].8
3232
with:
3333
BRANCH: gh-pages # The branch the action should deploy to.
3434
FOLDER: composeApp/build/dist/wasmJs/productionExecutable # The folder the action should deploy.

composeApp/build.gradle.kts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
2-
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
2+
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
33
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_0
4+
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree
45

56
plugins {
67
alias(libs.plugins.kotlinMultiplatform)
@@ -15,7 +16,6 @@ plugins {
1516
kotlin {
1617
jvmToolchain(17)
1718

18-
@OptIn(org.jetbrains.kotlin.gradle.ExperimentalWasmDsl::class)
1919
wasmJs {
2020
moduleName = "composeApp"
2121
browser {
@@ -27,7 +27,13 @@ kotlin {
2727
}
2828

2929

30-
androidTarget()
30+
androidTarget {
31+
@OptIn(ExperimentalKotlinGradlePluginApi::class)
32+
instrumentedTestVariant.sourceSetTree.set(KotlinSourceSetTree.test)
33+
34+
}
35+
36+
3137
jvm("desktop")
3238

3339
listOf(
@@ -81,6 +87,13 @@ kotlin {
8187
api(libs.compose.adaptive.layout)
8288
}
8389

90+
commonTest.dependencies {
91+
implementation(kotlin("test"))
92+
93+
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
94+
implementation(compose.uiTest)
95+
}
96+
8497
jsMain.dependencies {
8598
implementation(compose.html.core)
8699
implementation(libs.kstore.storage)
@@ -139,7 +152,10 @@ android {
139152
targetSdk = libs.versions.android.targetSdk.get().toInt()
140153
versionCode = 1
141154
versionName = "1.0"
155+
156+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
142157
}
158+
143159
packaging {
144160
resources {
145161
excludes += "/META-INF/{AL2.0,LGPL2.1}"
@@ -157,6 +173,14 @@ android {
157173
dependencies {
158174
debugImplementation(libs.compose.ui.tooling)
159175
}
176+
177+
testOptions {
178+
unitTests {
179+
all {
180+
it.exclude("**/screen/**")
181+
}
182+
}
183+
}
160184
}
161185

162186
compose.desktop {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package dev.johnoreilly.climatetrace.screen
2+
3+
import androidx.compose.material3.Text
4+
import androidx.compose.ui.test.ExperimentalTestApi
5+
import androidx.compose.ui.test.onNodeWithText
6+
import androidx.compose.ui.test.runComposeUiTest
7+
import dev.johnoreilly.climatetrace.remote.Country
8+
import dev.johnoreilly.climatetrace.ui.CountryListView
9+
import kotlin.test.Test
10+
11+
@OptIn(ExperimentalTestApi::class)
12+
class ClimateTraceScreenTest {
13+
private val countryList = listOf<Country>(Country("IRL", "IE", "Ireland", "Europe"))
14+
15+
@Test
16+
fun testCountryListScreen() = runComposeUiTest {
17+
setContent {
18+
CountryListView(countryList, null, {})
19+
}
20+
21+
onNodeWithText("Ireland").assertExists()
22+
}
23+
}
24+

gradle/libs.versions.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ agp = "8.7.1"
88
android-compileSdk = "34"
99
android-minSdk = "24"
1010
android-targetSdk = "34"
11-
androidx-activityCompose = "1.9.2"
12-
compose = "1.7.3"
11+
androidx-activityCompose = "1.9.3"
12+
compose = "1.7.4"
1313
compose-plugin = "1.7.0"
1414
composeAdaptiveLayout = "1.0.0"
1515
harawata-appdirs = "1.2.2"
@@ -21,7 +21,7 @@ kmpObservableViewModel = "1.0.0-BETA-6"
2121
kstore = "0.8.0"
2222
ktor = "3.0.0"
2323
treemapChart = "0.1.1"
24-
voyager= "1.1.0-beta02"
24+
voyager= "1.1.0-beta03"
2525
molecule = "2.0.0"
2626

2727

0 commit comments

Comments
 (0)