From e74c7989d956524b87dd54b76960bbec2d9c5f2f Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 22 Apr 2023 17:59:35 +0930 Subject: [PATCH] Fix navigation to the turbo-root not using Turbo Drive closes #912 --- src/core/url.ts | 6 +----- src/tests/fixtures/root/index.html | 19 +++++++++++++++++++ src/tests/fixtures/root/page.html | 18 ++++++++++++++++++ src/tests/functional/root_tests.ts | 27 +++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 src/tests/fixtures/root/index.html create mode 100644 src/tests/fixtures/root/page.html create mode 100644 src/tests/functional/root_tests.ts diff --git a/src/core/url.ts b/src/core/url.ts index 0e45d8f2b..3364f53ba 100644 --- a/src/core/url.ts +++ b/src/core/url.ts @@ -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; } diff --git a/src/tests/fixtures/root/index.html b/src/tests/fixtures/root/index.html new file mode 100644 index 000000000..f1b71ff4a --- /dev/null +++ b/src/tests/fixtures/root/index.html @@ -0,0 +1,19 @@ + + + + + Turbo + + + + + +
+

Root

+

Link to page inside root

+

Link to page outside root

+
+ +
+ + diff --git a/src/tests/fixtures/root/page.html b/src/tests/fixtures/root/page.html new file mode 100644 index 000000000..1bc7ac184 --- /dev/null +++ b/src/tests/fixtures/root/page.html @@ -0,0 +1,18 @@ + + + + + Turbo + + + + + +
+

Root

+

Link to root

+
+ +
+ + diff --git a/src/tests/functional/root_tests.ts b/src/tests/functional/root_tests.ts new file mode 100644 index 000000000..5d4bad25f --- /dev/null +++ b/src/tests/functional/root_tests.ts @@ -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") +}) \ No newline at end of file