From 9807caa5aea43a7c12d834bab82584bc87453328 Mon Sep 17 00:00:00 2001 From: Gergely Hegedus Date: Mon, 18 Jul 2022 21:50:44 +0300 Subject: [PATCH 1/3] Issue#107 Update Restoration tests so it points out error all the time --- .../org/fnives/test/showcase/ui/AuthComposeInstrumentedTest.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/androidTest/java/org/fnives/test/showcase/ui/AuthComposeInstrumentedTest.kt b/app/src/androidTest/java/org/fnives/test/showcase/ui/AuthComposeInstrumentedTest.kt index 3e8c5a6..171e0a8 100644 --- a/app/src/androidTest/java/org/fnives/test/showcase/ui/AuthComposeInstrumentedTest.kt +++ b/app/src/androidTest/java/org/fnives/test/showcase/ui/AuthComposeInstrumentedTest.kt @@ -175,6 +175,7 @@ class AuthComposeInstrumentedTest : KoinTest { .assertPassword("banan") stateRestorationTester.emulateSavedInstanceStateRestore() + composeTestRule.mainClock.advanceTimeBy(SPLASH_DELAY) // ensure all time based operation run navigationRobot.assertAuthScreen() robot.assertUsername("alma") From 4a0b6634dc153d7654a89261bbf0e784f0063f81 Mon Sep 17 00:00:00 2001 From: Gergely Hegedus Date: Mon, 18 Jul 2022 21:52:37 +0300 Subject: [PATCH 2/3] Issue#107 Update instruction set to include time advancement --- codekata/compose.instructionset.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/codekata/compose.instructionset.md b/codekata/compose.instructionset.md index ce50776..5b461ba 100644 --- a/codekata/compose.instructionset.md +++ b/codekata/compose.instructionset.md @@ -184,7 +184,7 @@ mockServerScenarioSetup.setScenario( Then we wait a bit, more precisely we wait for the app to navigate us correctly to AuthScreen since we're not logged in: ```kotlin -composeTestRule.mainClock.advanceTimeBy(510L) +composeTestRule.mainClock.advanceTimeBy(600L) ``` We assert that we are indeed on the correct screen @@ -227,7 +227,7 @@ Next up we verify what happens if the user doesn't set their password. We don't First we check that we are in the write place: ```kotlin -composeTestRule.mainClock.advanceTimeBy(510L) +composeTestRule.mainClock.advanceTimeBy(600L) navigationRobot.assertAuthScreen() ``` @@ -252,7 +252,7 @@ This will be really similar as the previous test, so try to do it on your own. T Still, here is the complete code: ```kotlin -composeTestRule.mainClock.advanceTimeBy(510L) +composeTestRule.mainClock.advanceTimeBy(600L) navigationRobot.assertAuthScreen() robot @@ -277,7 +277,7 @@ mockServerScenarioSetup.setScenario( Now input the credentials and fire the event: ```kotlin -composeTestRule.mainClock.advanceTimeBy(510L) +composeTestRule.mainClock.advanceTimeBy(600L) navigationRobot.assertAuthScreen() robot.setUsername("alma") .setPassword("banan") @@ -310,7 +310,7 @@ mockServerScenarioSetup.setScenario( AuthScenario.GenericError(username = "alma", password = "banan") ) -composeTestRule.mainClock.advanceTimeBy(510L) +composeTestRule.mainClock.advanceTimeBy(600L) navigationRobot.assertAuthScreen() robot.setUsername("alma") .setPassword("banan") @@ -342,8 +342,10 @@ Then in `setup()`, we need to `setContent` on `stateRestorationTester` instead o Now for the actual test, we first setup the content then we trigger restoration by calling `stateRestorationTester.emulateSavedInstanceStateRestore()`, afterwards we can verify that the content is recreated in the correct way: +> Note: We also add the time advancement, to ensure no time based effect messes up anything! + ```kotlin -composeTestRule.mainClock.advanceTimeBy(510L) +composeTestRule.mainClock.advanceTimeBy(600L) navigationRobot.assertAuthScreen() robot.setUsername("alma") .setPassword("banan") @@ -351,6 +353,7 @@ robot.setUsername("alma") .assertPassword("banan") stateRestorationTester.emulateSavedInstanceStateRestore() +composeTestRule.mainClock.advanceTimeBy(600L) navigationRobot.assertAuthScreen() robot.assertUsername("alma") From c10b674333fda95b3701fc1b23827c36e2f12f64 Mon Sep 17 00:00:00 2001 From: Gergely Hegedus Date: Mon, 18 Jul 2022 21:54:49 +0300 Subject: [PATCH 3/3] Issue#107 Fix issue with auth screen state restoration --- .../org/fnives/test/showcase/compose/screen/AppNavigation.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/fnives/test/showcase/compose/screen/AppNavigation.kt b/app/src/main/java/org/fnives/test/showcase/compose/screen/AppNavigation.kt index 076011b..7cf38bf 100644 --- a/app/src/main/java/org/fnives/test/showcase/compose/screen/AppNavigation.kt +++ b/app/src/main/java/org/fnives/test/showcase/compose/screen/AppNavigation.kt @@ -24,9 +24,11 @@ fun AppNavigation(isUserLogeInUseCase: IsUserLoggedInUseCase = get()) { val navController = rememberNavController() LaunchedEffect(isUserLogeInUseCase) { + val loginStateRoute = if (isUserLogeInUseCase.invoke()) RouteTag.HOME else RouteTag.AUTH + if (navController.currentDestination?.route == loginStateRoute) return@LaunchedEffect delay(500) navController.navigate( - route = if (isUserLogeInUseCase.invoke()) RouteTag.HOME else RouteTag.AUTH, + route = loginStateRoute, navOptions = NavOptions.Builder().setPopUpTo(route = RouteTag.SPLASH, inclusive = true).build() ) }