diff --git a/turbo/src/main/assets/json/test-configuration.json b/turbo/src/main/assets/json/test-configuration.json index 3cbeabaf..ea951360 100644 --- a/turbo/src/main/assets/json/test-configuration.json +++ b/turbo/src/main/assets/json/test-configuration.json @@ -23,6 +23,15 @@ "presentation": "clear_all" } }, + { + "patterns": [ + "/new-home" + ], + "properties": { + "uri": "turbo://fragment/web/home", + "presentation": "replace_root" + } + }, { "patterns": [ "/feature" diff --git a/turbo/src/main/kotlin/dev/hotwire/turbo/nav/TurboNavRule.kt b/turbo/src/main/kotlin/dev/hotwire/turbo/nav/TurboNavRule.kt index c41078ae..564abec4 100644 --- a/turbo/src/main/kotlin/dev/hotwire/turbo/nav/TurboNavRule.kt +++ b/turbo/src/main/kotlin/dev/hotwire/turbo/nav/TurboNavRule.kt @@ -81,6 +81,12 @@ internal class TurboNavRule( if (newPresentation == TurboNavPresentation.REPLACE_ROOT && newDestination != null) { return navOptions { popUpTo(controller.graph.id) { inclusive = true } + anim { + enter = navOptions.enterAnim + exit = navOptions.exitAnim + popEnter = navOptions.popEnterAnim + popExit = navOptions.popExitAnim + } } } diff --git a/turbo/src/test/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationRepositoryTest.kt b/turbo/src/test/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationRepositoryTest.kt index 7aa69158..553eb063 100644 --- a/turbo/src/test/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationRepositoryTest.kt +++ b/turbo/src/test/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationRepositoryTest.kt @@ -51,7 +51,7 @@ class TurboPathConfigurationRepositoryTest : BaseRepositoryTest() { assertThat(json).isNotNull() val config = load(json) - assertThat(config?.rules?.size).isEqualTo(9) + assertThat(config?.rules?.size).isEqualTo(10) } @Test diff --git a/turbo/src/test/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationTest.kt b/turbo/src/test/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationTest.kt index c6c8efdb..00b3158f 100644 --- a/turbo/src/test/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationTest.kt +++ b/turbo/src/test/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationTest.kt @@ -38,7 +38,7 @@ class TurboPathConfigurationTest : BaseRepositoryTest() { @Test fun assetConfigurationIsLoaded() { - assertThat(pathConfiguration.rules.size).isEqualTo(9) + assertThat(pathConfiguration.rules.size).isEqualTo(10) } @Test diff --git a/turbo/src/test/kotlin/dev/hotwire/turbo/nav/TurboNavRuleTest.kt b/turbo/src/test/kotlin/dev/hotwire/turbo/nav/TurboNavRuleTest.kt index cba10de6..52b78cba 100644 --- a/turbo/src/test/kotlin/dev/hotwire/turbo/nav/TurboNavRuleTest.kt +++ b/turbo/src/test/kotlin/dev/hotwire/turbo/nav/TurboNavRuleTest.kt @@ -31,6 +31,7 @@ class TurboNavRuleTest { private lateinit var pathConfiguration: TurboPathConfiguration private val homeUrl = "https://hotwired.dev/home" + private val newHomeUrl = "https://hotwired.dev/new-home" private val featureUrl = "https://hotwired.dev/feature" private val newUrl = "https://hotwired.dev/feature/new" private val editUrl = "https://hotwired.dev/feature/edit" @@ -143,6 +144,32 @@ class TurboNavRuleTest { assertThat(rule.newNavOptions).isEqualTo(navOptions) } + @Test + fun `replace root when navigating in default context`() { + controller.navigate(webDestinationId, locationArgs(featureUrl)) + val rule = getNavigatorRule(newHomeUrl) + + // Current destination + assertThat(rule.previousLocation).isEqualTo(homeUrl) + assertThat(rule.currentLocation).isEqualTo(featureUrl) + assertThat(rule.currentPresentationContext).isEqualTo(TurboNavPresentationContext.DEFAULT) + assertThat(rule.isAtStartDestination).isFalse() + + // New destination + assertThat(rule.newLocation).isEqualTo(newHomeUrl) + assertThat(rule.newPresentationContext).isEqualTo(TurboNavPresentationContext.DEFAULT) + assertThat(rule.newPresentation).isEqualTo(TurboNavPresentation.REPLACE_ROOT) + assertThat(rule.newQueryStringPresentation).isEqualTo(TurboNavQueryStringPresentation.DEFAULT) + assertThat(rule.newNavigationMode).isEqualTo(TurboNavMode.IN_CONTEXT) + assertThat(rule.newModalResult).isNull() + assertThat(rule.newDestinationUri).isEqualTo(webHomeUri) + assertThat(rule.newDestination).isNotNull() + assertThat(rule.newNavOptions.enterAnim).isEqualTo(navOptions.enterAnim) + assertThat(rule.newNavOptions.exitAnim).isEqualTo(navOptions.exitAnim) + assertThat(rule.newNavOptions.popEnterAnim).isEqualTo(navOptions.popEnterAnim) + assertThat(rule.newNavOptions.popExitAnim).isEqualTo(navOptions.popExitAnim) + } + @Test fun `navigate back to feature from modal context`() { controller.navigate(webDestinationId, locationArgs(featureUrl))