-
-
Save tiwiz/989c74f5d63e8340fee67df7a5fac100 to your computer and use it in GitHub Desktop.
This test verifies that the SplashScreenManager works as expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SplashScreenManagerTest { | |
@Test | |
fun when_user_is_not_logged_login_activity_should_be_invoked() { | |
Intents.init() | |
val activityScenario: ActivityScenario<TestActivity> = | |
ActivityScenario.launch(TestActivity::class.java) | |
activityScenario.onActivity { | |
val storage = PreferencesStorage(it) | |
val tokenManager = TokenManager(storage) | |
val intentFactory = SplashIntentFactory(it, tokenManager) | |
it.clearToken() | |
SplashTimingManager(it, intentFactory, 0) | |
} | |
activityScenario.moveToState(Lifecycle.State.STARTED) | |
intended(hasComponent(LoginActivity::class.java.name)) | |
Intents.release() | |
activityScenario.close() | |
} | |
@Test | |
fun when_user_is_logged_home_activity_should_be_invoked() { | |
Intents.init() | |
val activityScenario: ActivityScenario<TestActivity> = ActivityScenario.launch(TestActivity::class.java) | |
activityScenario.onActivity { | |
val storage = PreferencesStorage(it) | |
val tokenManager = TokenManager(storage) | |
val intentFactory = SplashIntentFactory(it, tokenManager) | |
it returnToken "AnyToken123!" | |
SplashTimingManager(it, intentFactory, 0) | |
} | |
activityScenario.moveToState(Lifecycle.State.STARTED) | |
intended(hasComponent(HomeActivity::class.java.name)) | |
Intents.release() | |
activityScenario.close() | |
} | |
@Test | |
fun when_user_exits_the_app_before_time_is_elapsed_no_intents_should_be_fired() { | |
Intents.init() | |
val activityScenario: ActivityScenario<TestActivity> = ActivityScenario.launch(TestActivity::class.java) | |
activityScenario.onActivity { | |
val storage = PreferencesStorage(it) | |
val tokenManager = TokenManager(storage) | |
val intentFactory = SplashIntentFactory(it, tokenManager) | |
it returnToken "AnyToken123!" | |
SplashTimingManager(it, intentFactory, 10000) | |
} | |
activityScenario.moveToState(Lifecycle.State.STARTED) | |
activityScenario.moveToState(Lifecycle.State.DESTROYED) | |
getIntents().map { it.component?.className }.forEach { | |
assertThat(it).doesNotContain("Login") | |
assertThat(it).doesNotContain("Home") | |
} | |
Intents.release() | |
activityScenario.close() | |
} | |
@After | |
fun tearDown() { | |
ApplicationProvider.getApplicationContext<Application>().clearToken() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a way to get the called activity (activity B for example), using a scenario from the caller activity (activity A) using androidX apis?