Wait for idling resources

This commit is contained in:
Alex Gabor 2022-03-01 17:35:43 +02:00
parent 4feb92d4ed
commit 6ddd057e66
3 changed files with 11 additions and 14 deletions

View file

@ -5,8 +5,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import org.fnives.test.showcase.network.mockserver.scenario.auth.AuthScenario
import org.fnives.test.showcase.testutils.MockServerScenarioSetupResetingTestRule
import org.fnives.test.showcase.testutils.idling.MainDispatcherTestRule
import org.fnives.test.showcase.testutils.idling.anyResourceIdling
import org.fnives.test.showcase.ui.compose.ComposeActivity
import org.fnives.test.showcase.ui.compose.TestShowCaseApp
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -32,12 +32,10 @@ class AuthComposeInstrumentedTest : KoinTest {
val ruleOrder: RuleChain = RuleChain.outerRule(mockServerScenarioSetupTestRule)
.around(mainDispatcherTestRule)
@Before
fun setup() {
robot = ComposeLoginRobot(composeTestRule)
composeTestRule.setContent {
TestShowCaseApp()
}
}
// @After
@ -51,16 +49,18 @@ class AuthComposeInstrumentedTest : KoinTest {
mockServerScenarioSetup.setScenario(
AuthScenario.Success(password = "alma", username = "banan")
)
composeTestRule.mainClock.advanceTimeBy(500L)
composeTestRule.mainClock.advanceTimeUntil { anyResourceIdling() }
composeTestRule.waitForIdle()
robot
.setPassword("alma")
.setUsername("banan")
.assertPassword("alma")
.assertUsername("banan")
.assertPassword("alma")
.clickOnLogin()
// .assertLoadingBeforeRequests()
mainDispatcherTestRule.advanceUntilIdleWithIdlingResources()
// mainDispatcherTestRule.advanceUntilIdleWithIdlingResources()
// robot.assertNavigatedToHome()
}

View file

@ -1,10 +1,7 @@
package org.fnives.test.showcase.ui
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.*
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput
import org.fnives.test.showcase.ui.compose.screen.auth.AuthScreenTag
class ComposeLoginRobot(
@ -20,11 +17,11 @@ class ComposeLoginRobot(
}
fun assertPassword(password: String): ComposeLoginRobot = apply {
composeTestRule.onNodeWithTag(AuthScreenTag.PasswordInput).assertTextEquals(password)
composeTestRule.onNodeWithTag(AuthScreenTag.PasswordInput).assertTextContains(password)
}
fun assertUsername(username: String): ComposeLoginRobot = apply {
composeTestRule.onNodeWithTag(AuthScreenTag.UsernameInput).assertTextEquals(username)
composeTestRule.onNodeWithTag(AuthScreenTag.UsernameInput).assertTextContains(username)
}
fun clickOnLogin(): ComposeLoginRobot = apply {

View file

@ -22,13 +22,13 @@ class MainDispatcherTestRule : TestRule {
@Throws(Throwable::class)
override fun evaluate() {
val dispatcher = StandardTestDispatcher()
Dispatchers.setMain(dispatcher)
// Dispatchers.setMain(dispatcher)
testDispatcher = dispatcher
DatabaseInitialization.dispatcher = dispatcher
try {
base.evaluate()
} finally {
Dispatchers.resetMain()
// Dispatchers.resetMain()
}
}
}