Skip to content

Commit

Permalink
Merge pull request #160 from arkivanov/update-kotlin-and-compose-vers…
Browse files Browse the repository at this point in the history
…ions

Update Kotlin to 1.5.10, Jetpack Compose to 1.0.0-beta08, JetBrains Compose to 4.0.0
  • Loading branch information
arkivanov authored Jun 2, 2021
2 parents b8313ac + ec9475f commit be56233
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
api-level: 21
arch: x86
disable-animations: true
script: ./gradlew :extensions-compose-jetbrains:connectedDebugAndroidTest :extensions-compose-jetpack:connectedDebugAndroidTest --stacktrace
script: ./gradlew :extensions-compose-jetpack:connectedDebugAndroidTest --stacktrace
macos-build:
name: Build on Macos
runs-on: macos-latest
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
decompose_version = '0.2.4'
kotlin_version = "1.4.32"
decompose_version = '0.2.5'
kotlin_version = "1.5.10"
junit_version = "4.13.2"
compose_kotlin_compiler_version = kotlin_version
compose_jetpack_version = '1.0.0-beta05'
compose_jetbrains_version = '0.4.0-build184'
compose_jetpack_version = '1.0.0-beta08'
compose_jetbrains_version = '0.4.0'
reaktive_version = '1.1.21'
mvikotlin_version = '2.0.0'
androidx_appcompat_version = '1.2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import com.arkivanov.decompose.RouterState
import com.arkivanov.decompose.extensions.compose.jetbrains.animation.child.crossfade
import com.arkivanov.decompose.extensions.compose.jetbrains.animation.child.crossfadeScale
import com.arkivanov.decompose.extensions.compose.jetbrains.animation.child.slide
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -34,60 +36,71 @@ class ChildrenTest(

@Test
fun WHEN_active_child_and_no_back_stack_THEN_active_child_displayed() {
val state = mutableStateOf(routerState(activeConfig = Config.A))
runBlocking(Dispatchers.Main) {
val state = mutableStateOf(routerState(activeConfig = Config.A))

setContent(state)
setContent(state)

composeRule.onNodeWithText(text = "ChildA", substring = true).assertExists()
composeRule.onNodeWithText(text = "ChildA", substring = true).assertExists()
}
}

@Test
fun GIVEN_child_A_displayed_WHEN_push_child_B_THEN_child_B_displayed() {
val state = mutableStateOf(routerState(activeConfig = Config.A))
setContent(state)
runBlocking(Dispatchers.Main) {
val state = mutableStateOf(routerState(activeConfig = Config.A))
setContent(state)

state.setValueOnIdle(routerState(activeConfig = Config.B, backstack = listOf(Config.A)))
state.setValueOnIdle(routerState(activeConfig = Config.B, backstack = listOf(Config.A)))

composeRule.onNodeWithText(text = "ChildB", substring = true).assertExists()
composeRule.onNodeWithText(text = "ChildB", substring = true).assertExists()
}
}

@Test
fun GIVEN_child_B_displayed_and_child_A_in_back_stack_WHEN_pop_child_B_THEN_child_A_displayed() {
val state = mutableStateOf(routerState(activeConfig = Config.A))
setContent(state)
state.setValueOnIdle(routerState(activeConfig = Config.B, backstack = listOf(Config.A)))
runBlocking(Dispatchers.Main) {
val state = mutableStateOf(routerState(activeConfig = Config.A))
setContent(state)
state.setValueOnIdle(routerState(activeConfig = Config.B, backstack = listOf(Config.A)))

state.setValueOnIdle(routerState(activeConfig = Config.A))
state.setValueOnIdle(routerState(activeConfig = Config.A))

composeRule.onNodeWithText(text = "ChildA", substring = true).assertExists()
composeRule.onNodeWithText(text = "ChildA", substring = true).assertExists()
}
}

@Test
fun GIVEN_child_B_displayed_and_child_A_in_back_stack_WHEN_pop_child_B_THEN_state_restored_for_child_A() {
val state = mutableStateOf(routerState(activeConfig = Config.A))
setContent(state)
composeRule.onNodeWithText(text = "ChildA=0").performClick()
state.setValueOnIdle(routerState(activeConfig = Config.B, backstack = listOf(Config.A)))
runBlocking(Dispatchers.Main) {
val state = mutableStateOf(routerState(activeConfig = Config.A))
setContent(state)
composeRule.onNodeWithText(text = "ChildA=0").performClick()
state.setValueOnIdle(routerState(activeConfig = Config.B, backstack = listOf(Config.A)))

state.setValueOnIdle(routerState(activeConfig = Config.A))
state.setValueOnIdle(routerState(activeConfig = Config.A))

composeRule.onNodeWithText(text = "ChildA=1").assertExists()
composeRule.onNodeWithText(text = "ChildA=1").assertExists()
}
}

@Test
fun GIVEN_child_B_displayed_and_child_A_in_back_stack_WHEN_pop_child_B_and_push_child_B_THEN_state_not_restored_for_child_B() {
val state = mutableStateOf(routerState(activeConfig = Config.A))
setContent(state)
state.setValueOnIdle(routerState(activeConfig = Config.B, backstack = listOf(Config.A)))
composeRule.onNodeWithText(text = "ChildB=0").performClick()
runBlocking(Dispatchers.Main) {
val state = mutableStateOf(routerState(activeConfig = Config.A))
setContent(state)

state.setValueOnIdle(routerState(activeConfig = Config.A))
state.setValueOnIdle(routerState(activeConfig = Config.B, backstack = listOf(Config.A)))
state.setValueOnIdle(routerState(activeConfig = Config.B, backstack = listOf(Config.A)))
composeRule.onNodeWithText(text = "ChildB=0").performClick()

composeRule.onNodeWithText(text = "ChildB=0").assertExists()
state.setValueOnIdle(routerState(activeConfig = Config.A))
state.setValueOnIdle(routerState(activeConfig = Config.B, backstack = listOf(Config.A)))

composeRule.onNodeWithText(text = "ChildB=0").assertExists()
}
}

private fun setContent(state: State<out RouterState<Config, Config>>) {
private suspend fun setContent(state: State<RouterState<Config, Config>>) {
composeRule.setContent {
Children(state.value, animation) { child ->
when (child.configuration) {
Expand Down Expand Up @@ -116,12 +129,14 @@ class ChildrenTest(
)
}

private fun <T> MutableState<T>.setValueOnIdle(value: T) {
private suspend fun <T> MutableState<T>.setValueOnIdle(value: T) {
runOnIdle { this.value = value }
runOnIdle {}
}

private fun runOnIdle(block: () -> Unit) {
composeRule.runOnIdle(block)
private suspend fun runOnIdle(block: () -> Unit) {
composeRule.awaitIdle()
block()
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class ChildrenTest(
composeRule.onNodeWithText(text = "ChildB=0").assertExists()
}

private fun setContent(state: State<out RouterState<Config, Config>>) {
private fun setContent(state: State<RouterState<Config, Config>>) {
composeRule.setContent {
Children(state.value, animation) { child ->
when (child.configuration) {
Expand Down Expand Up @@ -118,6 +118,7 @@ class ChildrenTest(

private fun <T> MutableState<T>.setValueOnIdle(value: T) {
runOnIdle { this.value = value }
runOnIdle {}
}

private fun runOnIdle(block: () -> Unit) {
Expand Down

0 comments on commit be56233

Please sign in to comment.