Skip to content

Commit

Permalink
Merge pull request DroidKaigi#932 from hiesiea/feature/adding_tests_t…
Browse files Browse the repository at this point in the history
…o_BookmarkScreenTest

Adding tests to BookmarkScreenTest
  • Loading branch information
takahirom authored Aug 29, 2023
2 parents 13d0bbb + 0412cf4 commit dac37c0
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DefaultSessionsApiClient internal constructor(
}
}

internal fun SessionsAllResponse.toTimetable(): Timetable {
fun SessionsAllResponse.toTimetable(): Timetable {
val timetableContents = this
val speakerIdToSpeaker: Map<String, TimetableSpeaker> = timetableContents.speakers
.groupBy { it.id }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
package io.github.droidkaigi.confsched2023.testing.robot

import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.isRoot
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.onFirst
import androidx.compose.ui.test.performClick
import com.github.takahirom.roborazzi.captureRoboImage
import io.github.droidkaigi.confsched2023.data.sessions.SessionsApiClient
import io.github.droidkaigi.confsched2023.data.sessions.fake
import io.github.droidkaigi.confsched2023.data.sessions.response.SessionsAllResponse
import io.github.droidkaigi.confsched2023.data.sessions.toTimetable
import io.github.droidkaigi.confsched2023.data.user.UserDataStore
import io.github.droidkaigi.confsched2023.designsystem.theme.KaigiTheme
import io.github.droidkaigi.confsched2023.sessions.BookmarkScreen
import io.github.droidkaigi.confsched2023.sessions.component.BookmarkFilterChipDay1TestTag
import io.github.droidkaigi.confsched2023.sessions.component.BookmarkFilterChipDay2TestTag
import io.github.droidkaigi.confsched2023.sessions.component.BookmarkFilterChipDay3TestTag
import io.github.droidkaigi.confsched2023.sessions.component.TimetableListItemBookmarkIconTestTag
import io.github.droidkaigi.confsched2023.testing.RobotTestRule
import io.github.droidkaigi.confsched2023.testing.coroutines.runTestWithLogging
import kotlinx.coroutines.test.TestDispatcher
import kotlinx.coroutines.test.runTest
import javax.inject.Inject
import kotlin.time.Duration.Companion.seconds

Expand All @@ -18,6 +30,9 @@ class BookmarkScreenRobot @Inject constructor(
@Inject lateinit var robotTestRule: RobotTestRule

@Inject lateinit var sessionsApiClient: SessionsApiClient

@Inject lateinit var userDataStore: UserDataStore

private lateinit var composeTestRule: AndroidComposeTestRule<*, *>

operator fun invoke(
Expand Down Expand Up @@ -47,6 +62,38 @@ class BookmarkScreenRobot @Inject constructor(
.captureRoboImage()
}

fun clickBookmarkFilterChipDay1() {
composeTestRule
.onNode(hasTestTag(BookmarkFilterChipDay1TestTag))
.performClick()
}

fun clickBookmarkFilterChipDay2() {
composeTestRule
.onNode(hasTestTag(BookmarkFilterChipDay2TestTag))
.performClick()
}

fun clickBookmarkFilterChipDay3() {
composeTestRule
.onNode(hasTestTag(BookmarkFilterChipDay3TestTag))
.performClick()
}

fun clickFirstSessionBookmark() {
composeTestRule
.onAllNodes(hasTestTag(TimetableListItemBookmarkIconTestTag))
.onFirst()
.performClick()
waitUntilIdle()
}

fun toggleFavorites() = runTest(testDispatcher) {
SessionsAllResponse.fake().toTimetable().timetableItems.forEach {
userDataStore.toggleFavorite(it.id)
}
}

fun waitUntilIdle() {
composeTestRule.waitForIdle()
testDispatcher.scheduler.advanceUntilIdle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand All @@ -25,6 +26,11 @@ import io.github.droidkaigi.confsched2023.designsystem.theme.KaigiTheme
import io.github.droidkaigi.confsched2023.model.DroidKaigi2023Day
import io.github.droidkaigi.confsched2023.sessions.SessionsStrings

const val BookmarkFilterChipAllTestTag = "BookmarkFilterChipAllTestTag"
const val BookmarkFilterChipDay1TestTag = "BookmarkFilterChipDay1TestTag"
const val BookmarkFilterChipDay2TestTag = "BookmarkFilterChipDay2TestTag"
const val BookmarkFilterChipDay3TestTag = "BookmarkFilterChipDay3TestTag"

@Composable
fun BookmarkFilters(
isAll: Boolean,
Expand All @@ -46,24 +52,28 @@ fun BookmarkFilters(
labelText = SessionsStrings.BookmarkFilterAllChip.asString(),
isSelected = isAll,
onClick = onAllFilterChipClick,
modifier = Modifier.testTag(BookmarkFilterChipAllTestTag),
)
Spacer(modifier = Modifier.size(8.dp))
BookmarkFilterChip(
labelText = DroidKaigi2023Day.Day1.name,
isSelected = isDayFirst,
onClick = onDayFirstChipClick,
modifier = Modifier.testTag(BookmarkFilterChipDay1TestTag),
)
Spacer(modifier = Modifier.size(8.dp))
BookmarkFilterChip(
labelText = DroidKaigi2023Day.Day2.name,
isSelected = isDaySecond,
onClick = onDaySecondChipClick,
modifier = Modifier.testTag(BookmarkFilterChipDay2TestTag),
)
Spacer(modifier = Modifier.size(8.dp))
BookmarkFilterChip(
labelText = DroidKaigi2023Day.Day3.name,
isSelected = isDayThird,
onClick = onDayThirdChipClick,
modifier = Modifier.testTag(BookmarkFilterChipDay3TestTag),
)
}
}
Expand All @@ -74,6 +84,7 @@ private fun BookmarkFilterChip(
labelText: String,
isSelected: Boolean,
onClick: () -> Unit,
modifier: Modifier = Modifier,
) {
val selectedChipColor = FilterChipDefaults.filterChipColors(
containerColor = MaterialTheme.colorScheme.secondaryContainer,
Expand All @@ -88,6 +99,7 @@ private fun BookmarkFilterChip(
label = {
ChipInnerText(labelText)
},
modifier = modifier,
leadingIcon = {
if (isSelected) {
Icon(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,100 @@ class BookmarkScreenTest {

@Test
@Category(ScreenshotTests::class)
fun checkLaunchShot() {
fun checkLaunchEmptyShot() {
bookmarkScreenRobot {
setupBookmarkScreenContent()
checkScreenCapture()
}
}

@Test
@Category(ScreenshotTests::class)
fun checkLaunchNotEmptyShot() {
bookmarkScreenRobot {
toggleFavorites()
setupBookmarkScreenContent()
checkScreenCapture()
}
}

@Test
@Category(ScreenshotTests::class)
fun checkBookmarkFilterChipDay1Shot() {
bookmarkScreenRobot {
toggleFavorites()
setupBookmarkScreenContent()
clickBookmarkFilterChipDay1()
checkScreenCapture()
}
}

@Test
@Category(ScreenshotTests::class)
fun checkBookmarkFilterChipDay2Shot() {
bookmarkScreenRobot {
toggleFavorites()
setupBookmarkScreenContent()
clickBookmarkFilterChipDay2()
checkScreenCapture()
}
}

@Test
@Category(ScreenshotTests::class)
fun checkBookmarkFilterChipDay3Shot() {
bookmarkScreenRobot {
toggleFavorites()
setupBookmarkScreenContent()
clickBookmarkFilterChipDay3()
checkScreenCapture()
}
}

@Test
@Category(ScreenshotTests::class)
fun checkBookmarkFilterChipDay1AndDay2Shot() {
bookmarkScreenRobot {
toggleFavorites()
setupBookmarkScreenContent()
clickBookmarkFilterChipDay1()
clickBookmarkFilterChipDay2()
checkScreenCapture()
}
}

@Test
@Category(ScreenshotTests::class)
fun checkBookmarkFilterChipDay1AndDay3Shot() {
bookmarkScreenRobot {
toggleFavorites()
setupBookmarkScreenContent()
clickBookmarkFilterChipDay1()
clickBookmarkFilterChipDay3()
checkScreenCapture()
}
}

@Test
@Category(ScreenshotTests::class)
fun checkBookmarkFilterChipDay2AndDay3Shot() {
bookmarkScreenRobot {
toggleFavorites()
setupBookmarkScreenContent()
clickBookmarkFilterChipDay2()
clickBookmarkFilterChipDay3()
checkScreenCapture()
}
}

@Test
@Category(ScreenshotTests::class)
fun checkBookmarkToggleShot() {
bookmarkScreenRobot {
toggleFavorites()
setupBookmarkScreenContent()
clickFirstSessionBookmark()
checkScreenCapture()
}
}
}

0 comments on commit dac37c0

Please sign in to comment.