-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
47 changes: 47 additions & 0 deletions
47
precompose/src/commonTest/kotlin/moe/tlaster/precompose/navigation/BackDispatcherTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package moe.tlaster.precompose.navigation | ||
|
||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.test.runTest | ||
import moe.tlaster.precompose.ui.BackDispatcher | ||
import moe.tlaster.precompose.ui.BackHandler | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class BackDispatcherTest { | ||
|
||
@Test | ||
fun onBackPress_should_call_handleBackPress_on_the_last_enabled_handler() { | ||
val dispatcher = BackDispatcher() | ||
val handler1 = object : BackHandler { | ||
override val isEnabled = true | ||
override fun handleBackPress() {} | ||
} | ||
val handler2 = object : BackHandler { | ||
override val isEnabled = true | ||
override fun handleBackPress() {} | ||
} | ||
dispatcher.register(handler1) | ||
dispatcher.register(handler2) | ||
|
||
dispatcher.onBackPress() | ||
|
||
assertEquals(handler2, dispatcher.handlers.last()) | ||
} | ||
|
||
@Test | ||
fun canHandleBackPress_should_return_true_if_any_handler_is_enabled() = runTest { | ||
val dispatcher = BackDispatcher() | ||
val handler1 = object : BackHandler { | ||
override val isEnabled = true | ||
override fun handleBackPress() {} | ||
} | ||
val handler2 = object : BackHandler { | ||
override val isEnabled = true | ||
override fun handleBackPress() {} | ||
} | ||
dispatcher.register(handler1) | ||
dispatcher.register(handler2) | ||
|
||
assertEquals(true, dispatcher.canHandleBackPress.first()) | ||
} | ||
} |