-
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.
Moved screen annotation test to voyager module
- Loading branch information
1 parent
37cadef
commit d70d1de
Showing
6 changed files
with
241 additions
and
100 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
62 changes: 62 additions & 0 deletions
62
integration/voyager/common/test/dev/programadorthi/routing/voyager/Screens.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,62 @@ | ||
package dev.programadorthi.routing.voyager | ||
|
||
import androidx.compose.runtime.Composable | ||
import cafe.adriel.voyager.core.screen.Screen | ||
import dev.programadorthi.routing.annotation.Body | ||
import dev.programadorthi.routing.annotation.Route | ||
|
||
internal val invoked = mutableMapOf<String, List<Any?>>() | ||
|
||
internal data class User( | ||
val id: Int, | ||
val name: String, | ||
) | ||
|
||
@Route("/screen") | ||
class Screen1 : Screen { | ||
@Composable | ||
override fun Content() { | ||
invoked += "/screen" to emptyList() | ||
} | ||
} | ||
|
||
@Route("/screen-object") | ||
object Screen2 : Screen { | ||
@Composable | ||
override fun Content() { | ||
invoked += "/screen-object" to emptyList() | ||
} | ||
} | ||
|
||
@Route("/screen/{id}") | ||
class Screen3(val id: Int) : Screen { | ||
@Composable | ||
override fun Content() { | ||
invoked += "/screen/{id}" to listOf(id) | ||
} | ||
} | ||
|
||
@Route("/screen-with-name/{name}") | ||
class Screen4(val name: String) : Screen { | ||
private var age: Int = -1 | ||
|
||
@Route("/screen-with-age/{age}") | ||
constructor(age: Int) : this("") { | ||
this.age = age | ||
} | ||
|
||
@Composable | ||
override fun Content() { | ||
invoked += "/screen-with-name/{name}" to listOf(name) | ||
invoked += "/screen-with-age/{age}" to listOf(age) | ||
} | ||
} | ||
|
||
@Route("/screen-with-body") | ||
internal class Screen5(@Body val user: User) : Screen { | ||
|
||
@Composable | ||
override fun Content() { | ||
invoked += "/screen-with-body" to listOf(user) | ||
} | ||
} |
154 changes: 154 additions & 0 deletions
154
...on/voyager/jvm/test/dev/programadorthi/routing/voyager/VoyagerRoutingByAnnotationsTest.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,154 @@ | ||
package dev.programadorthi.routing.voyager | ||
|
||
import dev.programadorthi.routing.core.push | ||
import dev.programadorthi.routing.core.pushWithBody | ||
import dev.programadorthi.routing.core.routing | ||
import dev.programadorthi.routing.generated.configure | ||
import dev.programadorthi.routing.voyager.helper.FakeScreen | ||
import dev.programadorthi.routing.voyager.helper.runComposeTest | ||
import kotlin.random.Random | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.advanceTimeBy | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
internal class VoyagerRoutingByAnnotationsTest { | ||
|
||
@Test | ||
fun shouldHandleScreenClass() = | ||
runComposeTest { coroutineContext, composition, clock -> | ||
// GIVEN | ||
val routing = | ||
routing(parentCoroutineContext = coroutineContext) { | ||
configure() | ||
} | ||
|
||
composition.setContent { | ||
VoyagerRouting( | ||
routing = routing, | ||
initialScreen = FakeScreen(), | ||
) | ||
} | ||
|
||
// WHEN | ||
routing.push("/screen") | ||
advanceTimeBy(99) // Ask for routing | ||
clock.sendFrame(0L) // Ask for recomposition | ||
|
||
// THEN | ||
assertEquals(emptyList(), invoked.remove("/screen")) | ||
} | ||
|
||
@Test | ||
fun shouldHandleScreenObject() = | ||
runComposeTest { coroutineContext, composition, clock -> | ||
// GIVEN | ||
val routing = | ||
routing(parentCoroutineContext = coroutineContext) { | ||
configure() | ||
} | ||
|
||
composition.setContent { | ||
VoyagerRouting( | ||
routing = routing, | ||
initialScreen = FakeScreen(), | ||
) | ||
} | ||
|
||
// WHEN | ||
routing.push("/screen-object") | ||
advanceTimeBy(99) // Ask for routing | ||
clock.sendFrame(0L) // Ask for recomposition | ||
|
||
// THEN | ||
assertEquals(emptyList(), invoked.remove("/screen-object")) | ||
} | ||
|
||
@Test | ||
fun shouldHandleScreenWithParameter() = | ||
runComposeTest { coroutineContext, composition, clock -> | ||
// GIVEN | ||
val routing = | ||
routing(parentCoroutineContext = coroutineContext) { | ||
configure() | ||
} | ||
|
||
composition.setContent { | ||
VoyagerRouting( | ||
routing = routing, | ||
initialScreen = FakeScreen(), | ||
) | ||
} | ||
|
||
// WHEN | ||
val nextInt = Random.Default.nextInt() | ||
routing.push("/screen/$nextInt") | ||
advanceTimeBy(99) // Ask for routing | ||
clock.sendFrame(0L) // Ask for recomposition | ||
|
||
// THEN | ||
assertEquals(listOf(nextInt), invoked.remove("/screen/{id}")) | ||
} | ||
|
||
@Test | ||
fun shouldHandleScreenWithMultipleConstructors() = | ||
runComposeTest { coroutineContext, composition, clock -> | ||
// GIVEN | ||
val routing = | ||
routing(parentCoroutineContext = coroutineContext) { | ||
configure() | ||
} | ||
|
||
composition.setContent { | ||
VoyagerRouting( | ||
routing = routing, | ||
initialScreen = FakeScreen(), | ||
) | ||
} | ||
|
||
// WHEN | ||
routing.push("/screen-with-name/Routing") | ||
advanceTimeBy(99) // Ask for routing | ||
clock.sendFrame(0L) // Ask for recomposition | ||
|
||
val fromName = invoked.remove("/screen-with-name/{name}") | ||
|
||
routing.push("/screen-with-age/18") | ||
advanceTimeBy(99) // Ask for routing | ||
clock.sendFrame(0L) // Ask for recomposition | ||
|
||
val fromAge = invoked.remove("/screen-with-age/{age}") | ||
|
||
// THEN | ||
assertEquals(listOf("Routing"), fromName) | ||
assertEquals(listOf(18), fromAge) | ||
} | ||
|
||
@Test | ||
fun shouldHandleScreenWithBody() = | ||
runComposeTest { coroutineContext, composition, clock -> | ||
// GIVEN | ||
val routing = | ||
routing(parentCoroutineContext = coroutineContext) { | ||
configure() | ||
} | ||
|
||
composition.setContent { | ||
VoyagerRouting( | ||
routing = routing, | ||
initialScreen = FakeScreen(), | ||
) | ||
} | ||
|
||
// WHEN | ||
val body = User(id = 456, name = "With Body") | ||
routing.pushWithBody(path = "/screen-with-body", body = body) | ||
advanceTimeBy(99) // Ask for routing | ||
clock.sendFrame(0L) // Ask for recomposition | ||
|
||
// THEN | ||
assertEquals(listOf(body), invoked.remove("/screen-with-body")) | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
41 changes: 0 additions & 41 deletions
41
samples/ksp-sample/src/commonMain/kotlin/dev/programadorthi/routing/sample/Screens.kt
This file was deleted.
Oops, something went wrong.
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