Issue#41 Remove waitForIdle since onNode already calls it

This commit is contained in:
Gergely Hegedus 2022-09-28 19:01:38 +03:00
parent f03c9f7bf2
commit a4b1e50f0f
3 changed files with 2 additions and 16 deletions

View file

@ -220,12 +220,12 @@ composeTestRule.mainClock.autoAdvance = true // Let clock auto advance again
Lastly we check the navigation was correct, meaning we should be on the home screen:
```kotlin
composeTestRule.waitForIdle() // wait for login network call idling resource
navigationRobot.assertHomeScreen()
```
> waitForIdle is necessary to wait for the Coroutine then the Network Call to finish. The Network call is running on OkHttps's own thread, so we use IdlingResources to synchronize with it. This is done in the ComposeNetworkSynchronizationTestRule.
> Note: Any node interactions call waitForIdle which waits for the Coroutine then the Network Call to finish. The Network call is running on OkHttps's own thread, so we use IdlingResources to synchronize with it. This is done in the ComposeNetworkSynchronizationTestRule.
> waitForIdle blocks the current thread while the Resources are busy. There is an alternative awaitIdle() which can be useful in runTest suspendable tests, feel free to look inside the Interface of ComposeTestRule.
> If you don't interact with a node but want to synchronize, then you will need waitForIdle. For example to verify something was called or written into like FakeLocalStorage in this example
> Basically since we have OkHttpIdlingResource as an EspressoIdlingResource we adapt that to Compose's IdlingResource class and register it with the ComposeTestRule and unregister it at the end.
### 2. `emptyPasswordShowsProperErrorMessage`
@ -247,7 +247,6 @@ robot.setUsername("banan")
Finally we let coroutines go and verify the error is shown and we have not navigated:
```kotlin
composeTestRule.waitForIdle()
robot.assertErrorIsShown(R.string.password_is_invalid)
.assertNotLoading()
navigationRobot.assertAuthScreen()
@ -267,7 +266,6 @@ robot
.assertPassword("banan")
.clickOnLogin()
composeTestRule.waitForIdle()
robot.assertErrorIsShown(R.string.username_is_invalid)
.assertNotLoading()
navigationRobot.assertAuthScreen()
@ -300,7 +298,6 @@ composeTestRule.mainClock.autoAdvance = true
Now at the end verify the error is shown properly:
```kotlin
composeTestRule.waitForIdle()
robot.assertErrorIsShown(R.string.credentials_invalid)
.assertNotLoading()
navigationRobot.assertAuthScreen()
@ -330,7 +327,6 @@ composeTestRule.mainClock.advanceTimeByFrame()
robot.assertLoading()
composeTestRule.mainClock.autoAdvance = true
composeTestRule.waitForIdle()
robot.assertErrorIsShown(R.string.something_went_wrong)
.assertNotLoading()
navigationRobot.assertAuthScreen()