From dd43d082a02d7c933b95345561d6d1190a02e2c4 Mon Sep 17 00:00:00 2001 From: Jay Ohms Date: Wed, 21 Jul 2021 12:15:56 -0400 Subject: [PATCH] Add a test to validate the current REPLACE presentation behavior when navigating to the same path, but the query params differ. This is helpful if we want to change the behavior brought up in #157. --- .../dev/hotwire/turbo/nav/TurboNavRule.kt | 2 +- .../dev/hotwire/turbo/nav/TurboNavRuleTest.kt | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) 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 3b89d1b4..34d779a4 100644 --- a/turbo/src/main/kotlin/dev/hotwire/turbo/nav/TurboNavRule.kt +++ b/turbo/src/main/kotlin/dev/hotwire/turbo/nav/TurboNavRule.kt @@ -137,6 +137,6 @@ internal class TurboNavRule( return false } - return URI(first).path == URI(second).path + return Uri.parse(first).path == Uri.parse(second).path } } 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 064d61e8..a8c46660 100644 --- a/turbo/src/test/kotlin/dev/hotwire/turbo/nav/TurboNavRuleTest.kt +++ b/turbo/src/test/kotlin/dev/hotwire/turbo/nav/TurboNavRuleTest.kt @@ -37,6 +37,7 @@ class TurboNavRuleTest { private val refreshUrl = "https://hotwired.dev/custom/refresh" private val resumeUrl = "https://hotwired.dev/custom/resume" private val modalRootUrl = "https://hotwired.dev/custom/modal" + private val filterUrl = "https://hotwired.dev/feature?filter=true" private val webDestinationId = 1 private val webModalDestinationId = 2 @@ -250,6 +251,28 @@ class TurboNavRuleTest { assertThat(rule.newNavOptions).isEqualTo(navOptions) } + @Test + fun `navigate to the same path with query params`() { + controller.navigate(webDestinationId, locationArgs(featureUrl)) + val rule = getNavigatorRule(filterUrl) + + // 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(filterUrl) + assertThat(rule.newPresentationContext).isEqualTo(TurboNavPresentationContext.DEFAULT) + assertThat(rule.newPresentation).isEqualTo(TurboNavPresentation.REPLACE) + assertThat(rule.newNavigationMode).isEqualTo(TurboNavMode.IN_CONTEXT) + assertThat(rule.newModalResult).isNull() + assertThat(rule.newDestinationUri).isEqualTo(webUri) + assertThat(rule.newDestination).isNotNull() + assertThat(rule.newNavOptions).isEqualTo(navOptions) + } + private fun getNavigatorRule( location: String, visitOptions: TurboVisitOptions = TurboVisitOptions(),