From a83575d05b20e90676f945bd4a01ae1887b06691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sznajder?= Date: Fri, 1 Sep 2023 10:15:42 +0200 Subject: [PATCH 1/2] Allow animation customization for replace_root presentation --- .../main/assets/json/test-configuration.json | 9 +++++++ .../dev/hotwire/turbo/nav/TurboNavRule.kt | 6 +++++ .../dev/hotwire/turbo/nav/TurboNavRuleTest.kt | 27 +++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/turbo/src/main/assets/json/test-configuration.json b/turbo/src/main/assets/json/test-configuration.json index 3cbeabaf..badbdb58 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": [ + "/toolbar/" + ], + "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 7a44db0d..46c49379 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(newDestination.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/nav/TurboNavRuleTest.kt b/turbo/src/test/kotlin/dev/hotwire/turbo/nav/TurboNavRuleTest.kt index cba10de6..304671d8 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 toolbarUrl = "https://hotwired.dev/toolbar/first" 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(webHomeDestinationId, locationArgs(homeUrl)) + val rule = getNavigatorRule(toolbarUrl) + + // Current destination + assertThat(rule.previousLocation).isEqualTo(homeUrl) + assertThat(rule.currentLocation).isEqualTo(homeUrl) + assertThat(rule.currentPresentationContext).isEqualTo(TurboNavPresentationContext.DEFAULT) + assertThat(rule.isAtStartDestination).isFalse() + + // New destination + assertThat(rule.newLocation).isEqualTo(toolbarUrl) + 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)) From 092da8296025717eca7c3e74c7fbfbf61be35f4c Mon Sep 17 00:00:00 2001 From: Jay Ohms Date: Fri, 23 Feb 2024 14:34:56 -0500 Subject: [PATCH 2/2] Fix tests --- turbo/src/main/assets/json/test-configuration.json | 2 +- .../config/TurboPathConfigurationRepositoryTest.kt | 2 +- .../hotwire/turbo/config/TurboPathConfigurationTest.kt | 2 +- .../kotlin/dev/hotwire/turbo/nav/TurboNavRuleTest.kt | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/turbo/src/main/assets/json/test-configuration.json b/turbo/src/main/assets/json/test-configuration.json index badbdb58..ea951360 100644 --- a/turbo/src/main/assets/json/test-configuration.json +++ b/turbo/src/main/assets/json/test-configuration.json @@ -25,7 +25,7 @@ }, { "patterns": [ - "/toolbar/" + "/new-home" ], "properties": { "uri": "turbo://fragment/web/home", 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 304671d8..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,7 +31,7 @@ class TurboNavRuleTest { private lateinit var pathConfiguration: TurboPathConfiguration private val homeUrl = "https://hotwired.dev/home" - private val toolbarUrl = "https://hotwired.dev/toolbar/first" + 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" @@ -146,17 +146,17 @@ class TurboNavRuleTest { @Test fun `replace root when navigating in default context`() { - controller.navigate(webHomeDestinationId, locationArgs(homeUrl)) - val rule = getNavigatorRule(toolbarUrl) + controller.navigate(webDestinationId, locationArgs(featureUrl)) + val rule = getNavigatorRule(newHomeUrl) // Current destination assertThat(rule.previousLocation).isEqualTo(homeUrl) - assertThat(rule.currentLocation).isEqualTo(homeUrl) + assertThat(rule.currentLocation).isEqualTo(featureUrl) assertThat(rule.currentPresentationContext).isEqualTo(TurboNavPresentationContext.DEFAULT) assertThat(rule.isAtStartDestination).isFalse() // New destination - assertThat(rule.newLocation).isEqualTo(toolbarUrl) + assertThat(rule.newLocation).isEqualTo(newHomeUrl) assertThat(rule.newPresentationContext).isEqualTo(TurboNavPresentationContext.DEFAULT) assertThat(rule.newPresentation).isEqualTo(TurboNavPresentation.REPLACE_ROOT) assertThat(rule.newQueryStringPresentation).isEqualTo(TurboNavQueryStringPresentation.DEFAULT)