Skip to content

Commit

Permalink
Add a test to validate the current REPLACE presentation behavior when…
Browse files Browse the repository at this point in the history
… navigating to the same path, but the query params differ. This is helpful if we want to change the behavior brought up in #157.
  • Loading branch information
jayohms committed Jul 21, 2021
1 parent 6c1ea13 commit dd43d08
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
23 changes: 23 additions & 0 deletions turbo/src/test/kotlin/dev/hotwire/turbo/nav/TurboNavRuleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit dd43d08

Please sign in to comment.