Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ Migrate remaining UI tests to Compose Multiplatform #701

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions features/search/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import extension.setFrameworkBaseName
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree

plugins {
id("com.escodro.multiplatform")
Expand Down Expand Up @@ -31,6 +33,22 @@ kotlin {
implementation(kotlin("test"))
implementation(projects.libraries.test)
implementation(libs.kotlinx.datetime)

@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.uiTest)
}

androidTarget {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
instrumentedTestVariant {
sourceSetTree.set(KotlinSourceSetTree.test)

dependencies {
implementation(libs.test.junit4.android)
implementation(libs.test.uiautomator)
debugImplementation(libs.test.manifest)
}
}
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.escodro.search

import androidx.compose.ui.graphics.Color
import androidx.compose.ui.test.ComposeUiTest
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.runComposeUiTest
import com.escodro.resources.Res
import com.escodro.resources.search_cd_empty_list
import com.escodro.resources.search_header_empty
import com.escodro.search.model.TaskSearchItem
import com.escodro.search.presentation.SearchScaffold
import com.escodro.search.presentation.SearchViewState
import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.runBlocking
import org.jetbrains.compose.resources.getString
import kotlin.test.Test

@OptIn(ExperimentalTestApi::class)
internal class SearchSectionTest {

@Test
fun when_view_is_opened_then_empty_view_is_shown() = runComposeUiTest {
// Given an empty state
val state = SearchViewState.Empty

// When the view is loaded
loadTaskList(state)

// Assert that the empty view is loaded
val header = runBlocking { getString(Res.string.search_header_empty) }
val contentDescription = runBlocking { getString(Res.string.search_cd_empty_list) }
onNodeWithText(text = header).assertExists()
onNodeWithContentDescription(label = contentDescription)
}

@Test
fun when_view_has_items_than_items_are_shown() = runComposeUiTest {
// Given a success state
val item1 = TaskSearchItem(1, false, "Buy cocoa", Color.Yellow, false)
val item2 = TaskSearchItem(1, false, "Send gift", Color.Green, false)
val queryList = persistentListOf(item1, item2)
val state = SearchViewState.Loaded(queryList)

// When the view is loaded
loadTaskList(state)

// Assert that the item are shown on the list
onNodeWithText(text = item1.title, useUnmergedTree = true).assertExists()
onNodeWithText(text = item2.title, useUnmergedTree = true).assertExists()
}

private fun ComposeUiTest.loadTaskList(state: SearchViewState) {
setContent {
SearchScaffold(
viewState = state,
onItemClick = {},
query = "",
setQuery = {},
)
}
}
}
18 changes: 18 additions & 0 deletions features/task/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import extension.setFrameworkBaseName
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree

plugins {
id("com.escodro.multiplatform")
Expand Down Expand Up @@ -38,6 +40,22 @@ kotlin {
implementation(kotlin("test"))
implementation(projects.libraries.test)
implementation(libs.kotlinx.datetime)

@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.uiTest)
}

androidTarget {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
instrumentedTestVariant {
sourceSetTree.set(KotlinSourceSetTree.test)

dependencies {
implementation(libs.test.junit4.android)
implementation(libs.test.uiautomator)
debugImplementation(libs.test.manifest)
}
}
}
}
}
Expand Down

This file was deleted.

Loading
Loading