feat: support scroll restoration for partials (#1858)

This commit is contained in:
Marvin Hagemeister
2023-10-05 10:00:56 +02:00
committed by GitHub
parent 9018024b7e
commit add696faeb
7 changed files with 423 additions and 6 deletions
+27 -1
View File
@@ -1,4 +1,4 @@
import { assertEquals, assertMatch } from "$std/testing/asserts.ts";
import { assert, assertEquals, assertMatch } from "$std/testing/asserts.ts";
import { Page } from "./deps.ts";
import {
assertNoComments,
@@ -835,6 +835,32 @@ Deno.test("allow opting out of client navigation", async () => {
);
});
Deno.test("restore scroll position", async () => {
await withPageName(
"./tests/fixture_partials/main.ts",
async (page, address) => {
const initialUrl = `${address}/scroll_restoration`;
await page.goto(initialUrl);
await page.waitForSelector(".status-initial");
await page.evaluate(() => {
document.querySelector(".update-link")?.scrollIntoView({
behavior: "instant",
});
});
await page.click(".update-link");
await page.waitForSelector(".status-updated");
await page.goBack();
await page.waitForSelector(".status-initial");
const scroll = await page.evaluate(() => ({ scrollX, scrollY }));
assert(scroll.scrollY > 100, `Page did not scroll ${scroll.scrollY}`);
},
);
});
Deno.test("shows loading indicator if trigger outside island", async () => {
await withPageName(
"./tests/fixture_partials/main.ts",