Skip to content

Commit

Permalink
Fix navigating to the turbo-root does not use Turbo Drive
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Nov 21, 2024
1 parent ea54ae5 commit dd2d2b5
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/core/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,5 @@ function getLastPathComponent(url) {
}

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

function addTrailingSlash(value) {
return value.endsWith("/") ? value : value + "/"
url.origin + url.pathname
}
18 changes: 18 additions & 0 deletions src/tests/fixtures/root/index.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-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>
17 changes: 17 additions & 0 deletions src/tests/fixtures/root/page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!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_test.js
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 dd2d2b5

Please sign in to comment.