Skip to content

[Crane] Fix ignored test with new APIs #491

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

Merged
merged 2 commits into from
May 4, 2021
Merged
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 @@ -25,18 +25,19 @@ import androidx.compose.samples.crane.calendar.model.DaySelectedStatus.NoSelecte
import androidx.compose.samples.crane.calendar.model.DaySelectedStatus.Selected
import androidx.compose.samples.crane.data.DatesRepository
import androidx.compose.samples.crane.ui.CraneTheme
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.SemanticsMatcher
import androidx.compose.ui.test.assertContentDescriptionEquals
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasScrollToKeyAction
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import androidx.compose.ui.test.performScrollToKey
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Before
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import javax.inject.Inject
Expand Down Expand Up @@ -66,11 +67,12 @@ class CalendarTest {
}
}

@Ignore("performScrollTo doesn't work with LazyLists: issuetracker.google.com/178483889")
@ExperimentalTestApi
@Test
fun scrollsToTheBottom() {
composeTestRule.onNodeWithContentDescription("January 1").assertIsDisplayed()
composeTestRule.onNodeWithContentDescription("December 31").performScrollTo().performClick()
composeTestRule.onNode(hasScrollToKeyAction()).performScrollToKey("2020/12/4")
composeTestRule.onNodeWithContentDescription("December 31").performClick()
assert(datesRepository.datesSelected.toString() == "Dec 31")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,12 @@ private fun LazyListScope.itemsCalendarMonth(
item {
DaysOfWeek(modifier = contentModifier)
}
for (week in month.weeks.value) {
item {

month.weeks.value.forEachIndexed { index, week ->
// A custom key needs to be given to these items so that they can be found in tests that
// need scrolling. The format of the key is ${year/month/weekNumber}. Thus,
// the key for the fourth week of December 2020 is "2020/12/4"
item(key = "${month.year}/${month.monthNumber}/${index + 1}") {
Week(
modifier = contentModifier,
week = week,
Expand Down