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

[WIP] Add search screen testing #825

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.CustomAccessibilityAction
Expand Down Expand Up @@ -293,7 +294,8 @@ fun SearchTextFieldTopAppBar(
title = {
SearchTextField(
modifier = Modifier
.background(color = backgroundColor),
.background(color = backgroundColor)
.testTag("search"),
searchWord = searchWord,
onSearchWordChange = onSearchWordChange,
onSearchTextAreaClicked = onSearchTextAreaClicked
Expand Down Expand Up @@ -354,6 +356,7 @@ private fun SearchTextField(
placeholder = { Text(stringResource(Strings.search_placeholder)) },
trailingIcon = {
IconButton(
modifier = Modifier.testTag("clearInput"),
onClick = { onSearchWordChange("") }
) {
Icon(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ fun SessionListItem(
val secondLang = lang.secondLang()

Row(
modifier = modifier.fillMaxSize(),
modifier = modifier
.fillMaxSize()
.testTag("session"),
horizontalArrangement = Arrangement.SpaceBetween
) {
Column(modifier = Modifier.weight(1F)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.github.droidkaigi.confsched2022.feature.sessions

import androidx.compose.ui.test.assertAny
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextReplacement
import io.github.droidkaigi.confsched2022.testing.RobotTestRule
import javax.inject.Inject

class SearchScreenRobot @Inject constructor() {

context(RobotTestRule)
fun typeQuery(query: String) {
composeTestRule.onNodeWithTag("search").performTextReplacement(query)
}

context(RobotTestRule)
fun checkSessionExists(title: String) {
composeTestRule.onAllNodes(
matcher = hasTestTag("session") and hasText(title),
).assertAny(hasText(title))
}

context(RobotTestRule)
fun clearInput() {
composeTestRule.onNodeWithTag("clearInput").performClick()
}

operator fun invoke(
robotTestRule: RobotTestRule,
function: context(RobotTestRule) SearchScreenRobot.() -> Unit
) {
robotTestRule.composeTestRule.setContent {
SearchRoot(onItemClick = {})
}
function(robotTestRule, this@SearchScreenRobot)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.github.droidkaigi.confsched2022.feature.sessions

import androidx.test.ext.junit.runners.AndroidJUnit4
import dagger.hilt.android.testing.HiltAndroidTest
import io.github.droidkaigi.confsched2022.model.DroidKaigiSchedule
import io.github.droidkaigi.confsched2022.model.TimetableItem.Session
import io.github.droidkaigi.confsched2022.model.fake
import io.github.droidkaigi.confsched2022.testing.RobotTestRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import javax.inject.Inject

@RunWith(AndroidJUnit4::class)
@HiltAndroidTest
class SearchScreenTest {

@get:Rule val robotTestRule = RobotTestRule(this)
@Inject lateinit var searchScreenRobot: SearchScreenRobot

@Test
fun searchWithResult() {
searchScreenRobot(robotTestRule) {
DroidKaigiSchedule.fake().dayToTimetable.forEach { (_, timeTable) ->
timeTable.contents.forEach inner@{
if (it.timetableItem !is Session) return@inner
val query = it.timetableItem.title.currentLangTitle
typeQuery(query)
checkSessionExists(query)
}
}
}
}
}