Skip to content

Commit

Permalink
Fix navigation to the turbo-root not using Turbo Drive
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyzerner committed Apr 22, 2023
1 parent 4593d06 commit e74c798
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/core/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,5 @@ function getLastPathComponent(url: URL) {
}

function getPrefix(url: URL) {
return addTrailingSlash(url.origin + url.pathname)
}

function addTrailingSlash(value: string) {
return value.endsWith("/") ? value : value + "/"
return url.origin + url.pathname;
}
19 changes: 19 additions & 0 deletions src/tests/fixtures/root/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html id="html">
<head>
<meta charset="utf-8">
<title>Turbo</title>
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script>
<script src="/src/tests/fixtures/test.js"></script>
<meta name="turbo-root" content="/src/tests/fixtures/root">
</head>
<body>
<section>
<h1>Root</h1>
<p><a id="link-page-inside" href="/src/tests/fixtures/root/page.html">Link to page inside root</a></p>
<p><a id="link-page-outside" href="/src/tests/fixtures/one.html">Link to page outside root</a></p>
</section>

<div id="messages"></div>
</body>
</html>
18 changes: 18 additions & 0 deletions src/tests/fixtures/root/page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html id="html">
<head>
<meta charset="utf-8">
<title>Turbo</title>
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script>
<script src="/src/tests/fixtures/test.js"></script>
<meta name="turbo-root" content="/src/tests/fixtures/root">
</head>
<body>
<section>
<h1>Root</h1>
<p><a id="link-root" href="/src/tests/fixtures/root">Link to root</a></p>
</section>

<div id="messages"></div>
</body>
</html>
27 changes: 27 additions & 0 deletions src/tests/functional/root_tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { test } from "@playwright/test"
import { assert } from "chai"
import { nextBody, pathname, visitAction } from "../helpers/page"

test("test visiting a location inside the root", async ({ page }) => {
page.goto("/src/tests/fixtures/root/index.html")
page.click("#link-page-inside")
await nextBody(page)
assert.equal(pathname(page.url()), "/src/tests/fixtures/root/page.html")
assert.notEqual(await visitAction(page), "load")
})

test("test visiting the root itself", async ({ page }) => {
page.goto("/src/tests/fixtures/root/page.html")
page.click("#link-root")
await nextBody(page)
assert.equal(pathname(page.url()), "/src/tests/fixtures/root/")
assert.notEqual(await visitAction(page), "load")
})

test("test visiting a location outside the root", async ({ page }) => {
page.goto("/src/tests/fixtures/root/index.html")
page.click("#link-page-outside")
await nextBody(page)
assert.equal(pathname(page.url()), "/src/tests/fixtures/one.html")
assert.equal(await visitAction(page), "load")
})

0 comments on commit e74c798

Please sign in to comment.