fix: don't scroll on fragment links in partials (#1906)

This commit is contained in:
Marvin Hagemeister
2023-10-11 10:30:31 +02:00
committed by GitHub
parent 36ea0385ed
commit a1f0d4a5bd
4 changed files with 211 additions and 115 deletions
+17 -2
View File
@@ -939,8 +939,7 @@ Deno.test("fragment navigation should not cause loop", async () => {
const logs: string[] = [];
page.on("console", (msg) => logs.push(msg.text()));
const initialUrl = `${address}/fragment_nav`;
await page.goto(initialUrl);
await page.goto(`${address}/fragment_nav`);
await page.waitForSelector(".partial-text");
await page.click("a");
@@ -951,6 +950,22 @@ Deno.test("fragment navigation should not cause loop", async () => {
);
});
Deno.test("fragment navigation should not scroll to top", async () => {
await withPageName(
"./tests/fixture_partials/main.ts",
async (page, address) => {
await page.goto(`${address}/fragment_nav_scroll`);
await page.waitForSelector(".partial-text");
await page.click("a");
await page.waitForFunction(() => location.hash === "#foo");
const scroll = await page.evaluate(() => window.scrollY);
assert(scroll > 0, `Did not scroll to fragment`);
},
);
});
Deno.test("active links without client nav", async () => {
await withFakeServe(
"./tests/fixture_partials/main.ts",