Skip to content

Commit

Permalink
Test: Add clues
Browse files Browse the repository at this point in the history
  • Loading branch information
raquo committed Nov 9, 2024
1 parent 0218c7e commit a26499b
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions js/src/test/scala/com/raquo/waypoint/BasePathSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,20 @@ class BasePathSpec extends UnitSpec {
)

it("segment routes - parse urls - match") {
def testHomeRoute(homeRoute: Route[HomePage.type, Unit]) = {
if (basePath.nonEmpty) {
expectPageRelative(homeRoute, origin, s"$basePath", Some(HomePage))
} else {
// (basePath + url) must be a relative URL, so if basePath is empty, url can't also be empty, it must start with `/`
expectPageRelativeFailure(homeRoute, origin, s"$basePath")
def testHomeRoute(homeRoute: Route[HomePage.type, Unit], clue: String) = {
withClue(clue) {
if (basePath.nonEmpty) {
expectPageRelative(homeRoute, origin, s"$basePath", Some(HomePage))
} else {
// (basePath + url) must be a relative URL, so if basePath is empty, url can't also be empty, it must start with `/`
expectPageRelativeFailure(homeRoute, origin, s"$basePath")
}
expectPageRelative(homeRoute, origin, s"$basePath/", Some(HomePage))
}
expectPageRelative(homeRoute, origin, s"$basePath/", Some(HomePage))
}

testHomeRoute(homeRoute)
testHomeRoute(homeRouteTotal)
testHomeRoute(homeRoute, clue = "homeRoute")
testHomeRoute(homeRouteTotal, clue = "homeRouteTotal")

expectPageRelative(libraryRoute, origin, s"$basePath/app/library/1234", Some(LibraryPage(libraryId = 1234)))
expectPageRelative(libraryRoute, origin, s"$basePath/app/library/100?hello=world", Some(LibraryPage(libraryId = 100)))
Expand Down Expand Up @@ -202,14 +204,16 @@ class BasePathSpec extends UnitSpec {

expectPageRelative(libraryRoute, origin, "/app/library/1234", if (basePath.isEmpty) Some(LibraryPage(1234)) else None)

def testHomeRoute(homeRoute: Route[HomePage.type, Unit]) = {
if (Utils.basePathHasEmptyFragment(basePath)) {
val basePathWithoutFragment = Utils.basePathWithoutFragment(basePath)
expectPageRelative(homeRoute, origin, s"$basePathWithoutFragment", Some(HomePage))
def testHomeRoute(homeRoute: Route[HomePage.type, Unit], clue: String) = {
withClue(clue) {
if (Utils.basePathHasEmptyFragment(basePath)) {
val basePathWithoutFragment = Utils.basePathWithoutFragment(basePath)
expectPageRelative(homeRoute, origin, s"$basePathWithoutFragment", Some(HomePage))
}
}
}
testHomeRoute(homeRoute)
testHomeRoute(homeRouteTotal)
testHomeRoute(homeRoute, clue = "homeRoute")
testHomeRoute(homeRouteTotal, clue = "homeRouteTotal")

// @TODO[API] I mean... these are not absolute urls...
expectPageAbsoluteFailure(libraryRoute, origin, "//app/library/1234")
Expand Down

0 comments on commit a26499b

Please sign in to comment.