Restore Home viewport across See all navigation
This commit is contained in:
parent
14a74ac43b
commit
9c8fceb18c
9 changed files with 125 additions and 45 deletions
|
|
@ -18,6 +18,7 @@ import io.mockk.mockk
|
|||
import java.util.UUID
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Assert.assertSame
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
|
@ -32,9 +33,25 @@ import org.robolectric.annotation.Config
|
|||
class HomeSeeAllNavigationTest {
|
||||
@get:Rule val rule = createAndroidComposeRule<ComponentActivity>()
|
||||
|
||||
@Test fun personalMovieContinuationReachesTheEighteenthTitleAndReturnsToHome() {
|
||||
@Test fun personalMovieContinuationReachesTheEighteenthTitleAndReturnsToHome() = continuation("pk-m", 5) { grid ->
|
||||
assertEquals(18, grid.items.size)
|
||||
repeat(2) { press(Key.DirectionDown) }
|
||||
repeat(5) { press(Key.DirectionRight) }
|
||||
rule.onNodeWithText("Bleach the Movie: Fade to Black").assertIsDisplayed()
|
||||
assertEquals("movie-bleach-the-movie-fade-to-black-2008", grid.focusedTitle?.id)
|
||||
}
|
||||
|
||||
@Test fun horizontallyScrolledContinuationRestoresTheExactHomeViewport() = continuation("trending", 20) { grid ->
|
||||
press(Key.DirectionDown)
|
||||
assertEquals(6, grid.index)
|
||||
rule.onNodeWithTag("library-grid").assertIsDisplayed()
|
||||
}
|
||||
|
||||
private fun continuation(rowId: String, expectedColumn: Int, exerciseGrid: (LibraryGridState) -> Unit) {
|
||||
rule.mainClock.autoAdvance = false
|
||||
val snapshot = HomeFixture(rule.activity).snapshot("justin")
|
||||
val row = snapshot.rows.first { it.id == "pk-m" }
|
||||
val row = snapshot.rows.first { it.id == rowId }
|
||||
val cardTag = "home-card:$rowId:$expectedColumn"
|
||||
val navigation = NavigationManager()
|
||||
val lists = WolfskinSeeAllLists()
|
||||
val shell = ShellState(listOf(ShellPerson("justin", "Justin", "J", true)), "justin") {
|
||||
|
|
@ -58,24 +75,56 @@ class HomeSeeAllNavigationTest {
|
|||
else WolfskinLibraryContent(rule.activity, route, shell, user, "fixture", facade, navigation, lists, modifier)
|
||||
} }
|
||||
}
|
||||
rule.onNodeWithTag("home-card:pk-m:5").assertIsDisplayed()
|
||||
settle()
|
||||
rule.onNodeWithTag(cardTag).assertIsDisplayed()
|
||||
val home = shell.view
|
||||
val track = home.home.tracks.getValue(rowId)
|
||||
val verticalIndex = home.listState.firstVisibleItemIndex
|
||||
val verticalOffset = home.listState.firstVisibleItemScrollOffset
|
||||
val rowOffset = home.listState.layoutInfo.visibleItemsInfo.first { it.key == rowId }.offset
|
||||
val horizontalIndex = track.firstVisibleItemIndex
|
||||
val horizontalOffset = track.firstVisibleItemScrollOffset
|
||||
press(Key.DirectionCenter)
|
||||
assertEquals("seeall/justin/pk-m", (navigation.backStack.last() as Destination.Wolfskin).route)
|
||||
val grid = requireNotNull(lists.get("justin/pk-m"))
|
||||
assertEquals(18, grid.items.size)
|
||||
repeat(2) { press(Key.DirectionDown) }
|
||||
repeat(5) { press(Key.DirectionRight) }
|
||||
rule.onNodeWithText("Bleach the Movie: Fade to Black").assertIsDisplayed()
|
||||
assertEquals("movie-bleach-the-movie-fade-to-black-2008", grid.focusedTitle?.id)
|
||||
press(Key.Back)
|
||||
rule.waitForIdle()
|
||||
assertTrue(navigation.backStack.last() is Destination.Home)
|
||||
assertEquals(row.id, snapshot.rows[shell.view.row].id)
|
||||
assertEquals(5, shell.view.cards[row.id])
|
||||
rule.onNodeWithTag("home-card:pk-m:5").assertIsDisplayed()
|
||||
assertEquals("seeall/justin/$rowId", (navigation.backStack.last() as Destination.Wolfskin).route)
|
||||
val grid = requireNotNull(lists.get("justin/$rowId"))
|
||||
try {
|
||||
rule.onNodeWithTag("library-grid").assertIsDisplayed()
|
||||
exerciseGrid(grid)
|
||||
press(Key.Back)
|
||||
rule.waitForIdle()
|
||||
assertTrue(navigation.backStack.last() is Destination.Home)
|
||||
assertEquals(row.id, snapshot.rows[shell.view.row].id)
|
||||
assertEquals(expectedColumn, shell.view.cards[row.id])
|
||||
assertSame("Home retains its original route memory", home, shell.view)
|
||||
assertSame("Home retains its original horizontal state", track, home.home.tracks.getValue(rowId))
|
||||
assertEquals("Vertical first item", verticalIndex, home.listState.firstVisibleItemIndex)
|
||||
assertEquals("Vertical pixel offset", verticalOffset, home.listState.firstVisibleItemScrollOffset)
|
||||
assertEquals("Selected row pixel offset", rowOffset, home.listState.layoutInfo.visibleItemsInfo.first { it.key == rowId }.offset)
|
||||
assertEquals("Horizontal first item", horizontalIndex, track.firstVisibleItemIndex)
|
||||
assertEquals("Horizontal pixel offset", horizontalOffset, track.firstVisibleItemScrollOffset)
|
||||
rule.onNodeWithTag(cardTag).assertIsDisplayed()
|
||||
} catch (failure: AssertionError) {
|
||||
throw AssertionError(
|
||||
"Expected $rowId:$expectedColumn vertical=$verticalIndex/$verticalOffset row-offset=$rowOffset horizontal=$horizontalIndex/$horizontalOffset; " +
|
||||
"actual route=${shell.route} row=${home.row} card=${home.cards[rowId]} nav=${shell.navFocused} handler=${shell.contentFocus?.javaClass?.simpleName} grid=${grid.index} " +
|
||||
"vertical=${home.listState.firstVisibleItemIndex}/${home.listState.firstVisibleItemScrollOffset} horizontal=${track.firstVisibleItemIndex}/${track.firstVisibleItemScrollOffset} " +
|
||||
"visible-rows=${home.listState.layoutInfo.visibleItemsInfo.map { it.key to it.offset }}",
|
||||
failure,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun press(key: Key) {
|
||||
rule.onNodeWithTag("wolfskin-shell").performKeyInput { pressKey(key) }
|
||||
settle()
|
||||
}
|
||||
|
||||
private fun settle() {
|
||||
repeat(3) {
|
||||
rule.mainClock.advanceTimeByFrame()
|
||||
rule.waitForIdle()
|
||||
}
|
||||
rule.mainClock.advanceTimeBy(1_000)
|
||||
rule.waitForIdle()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue