feat: mark active or ancestor links (#1840)

This commit is contained in:
Marvin Hagemeister
2023-10-02 18:22:44 +02:00
committed by GitHub
parent d638c526f5
commit 4295dbe85d
11 changed files with 304 additions and 138 deletions
+23 -2
View File
@@ -891,7 +891,6 @@ Deno.test("fragment navigation should not cause loop", async () => {
await withPageName(
"./tests/fixture_partials/main.ts",
async (page, address) => {
page.setDefaultTimeout(2000);
const logs: string[] = [];
page.on("console", (msg) => logs.push(msg.text()));
@@ -907,6 +906,28 @@ Deno.test("fragment navigation should not cause loop", async () => {
);
});
Deno.test("active links without client nav", async () => {
await withFakeServe(
"./tests/fixture_partials/main.ts",
async (server) => {
let doc = await server.getHtml(`/active_nav`);
assertSelector(doc, "a[href='/'][data-ancestor]");
// Current
assertNotSelector(doc, "a[href='/active_nav'][data-ancestor]");
assertSelector(doc, "a[href='/active_nav'][data-current]");
// Unrelated links
assertNotSelector(doc, "a[href='/active_nav/foo'][data-ancestor]");
assertNotSelector(doc, "a[href='/active_nav/foo/bar'][data-ancestor]");
doc = await server.getHtml(`/active_nav/foo`);
assertSelector(doc, "a[href='/active_nav/foo'][data-current]");
assertSelector(doc, "a[href='/active_nav'][data-ancestor]");
assertSelector(doc, "a[href='/'][data-ancestor]");
},
);
});
// TODO Head merging
// TODO Active links
// TODO Children Keys