-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add tests for :core:navigation (#481)
* fix: mute videos by default * update build scripts * refactor: wrap adapter around navigator in NavigationCoordinator * add test for NavigationCoordinator * add test for DrawerCoordinator
- Loading branch information
Showing
9 changed files
with
328 additions
and
6 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
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
15 changes: 15 additions & 0 deletions
15
...Main/kotlin/com/livefast/eattrash/raccoonforfriendica/core/navigation/NavigatorAdapter.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,15 @@ | ||
package com.livefast.eattrash.raccoonforfriendica.core.navigation | ||
|
||
import cafe.adriel.voyager.core.screen.Screen | ||
|
||
interface NavigatorAdapter { | ||
val canPop: Boolean | ||
|
||
fun push(screen: Screen) | ||
|
||
fun pop() | ||
|
||
fun popUntilRoot() | ||
|
||
fun replace(screen: Screen) | ||
} |
27 changes: 27 additions & 0 deletions
27
...Main/kotlin/com/livefast/eattrash/raccoonforfriendica/core/navigation/VoyagerNavigator.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,27 @@ | ||
package com.livefast.eattrash.raccoonforfriendica.core.navigation | ||
|
||
import cafe.adriel.voyager.core.screen.Screen | ||
import cafe.adriel.voyager.navigator.Navigator | ||
|
||
data class VoyagerNavigator( | ||
val adaptee: Navigator, | ||
) : NavigatorAdapter { | ||
override val canPop: Boolean | ||
get() = adaptee.canPop | ||
|
||
override fun push(screen: Screen) { | ||
adaptee.push(screen) | ||
} | ||
|
||
override fun pop() { | ||
adaptee.pop() | ||
} | ||
|
||
override fun popUntilRoot() { | ||
adaptee.popUntilRoot() | ||
} | ||
|
||
override fun replace(screen: Screen) { | ||
adaptee.replace(screen) | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...com/livefast/eattrash/raccoonforfriendica/core/navigation/DefaultDrawerCoordinatorTest.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,63 @@ | ||
package com.livefast.eattrash.raccoonforfriendica.core.navigation | ||
|
||
import app.cash.turbine.test | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.test.runTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFalse | ||
import kotlin.test.assertTrue | ||
|
||
class DefaultDrawerCoordinatorTest { | ||
private val sut = DefaultDrawerCoordinator() | ||
|
||
@Test | ||
fun `when toggleDrawer then event is emitted`() = | ||
runTest { | ||
launch { | ||
sut.toggleDrawer() | ||
} | ||
|
||
sut.events.test { | ||
val evt = awaitItem() | ||
assertEquals(DrawerEvent.Toggle, evt) | ||
} | ||
} | ||
|
||
@Test | ||
fun `when closeDrawer then event is emitted`() = | ||
runTest { | ||
launch { | ||
sut.closeDrawer() | ||
} | ||
|
||
sut.events.test { | ||
val evt = awaitItem() | ||
assertEquals(DrawerEvent.Close, evt) | ||
} | ||
} | ||
|
||
@Test | ||
fun `when setGesturesEnabled then state is updated`() = | ||
runTest { | ||
val initial = sut.gesturesEnabled.value | ||
assertTrue(initial) | ||
|
||
sut.setGesturesEnabled(false) | ||
|
||
val value = sut.gesturesEnabled.value | ||
assertFalse(value) | ||
} | ||
|
||
@Test | ||
fun `when sendEvent then event is emitted`() = | ||
runTest { | ||
launch { | ||
sut.sendEvent(DrawerEvent.Toggle) | ||
} | ||
sut.events.test { | ||
val evt = awaitItem() | ||
assertEquals(DrawerEvent.Toggle, evt) | ||
} | ||
} | ||
} |
Oops, something went wrong.