feat(server): add isPartial to context types (#1977)

This commit is contained in:
Reed von Redwitz
2023-10-26 22:26:36 +02:00
committed by GitHub
parent 7ad4610e3a
commit 63ac1e6362
13 changed files with 333 additions and 121 deletions
+74
View File
@@ -1423,3 +1423,77 @@ Deno.test("errors on duplicate partial name", async () => {
},
);
});
Deno.test("normal visit to handler page", async () => {
await withFakeServe(
"./tests/fixture_partials/main.ts",
async (server) => {
const html = await server.getHtml("/isPartial/handler");
assertEquals(JSON.parse(html.querySelector("pre")!.textContent!), {
isPartial: false,
notSetFromMiddleware: true,
});
},
);
});
Deno.test("normal visit to async page", async () => {
await withFakeServe(
"./tests/fixture_partials/main.ts",
async (server) => {
const html = await server.getHtml("/isPartial/async");
assertEquals(JSON.parse(html.querySelector("pre")!.textContent!), {
isPartial: false,
notSetFromMiddleware: true,
});
},
);
});
Deno.test("partials visit to handler page", async () => {
await withPageName(
"./tests/fixture_partials/main.ts",
async (page, address) => {
await page.goto(`${address}/isPartial`);
await page.waitForSelector(".output");
const href = await page.$eval(".handler-update-link", (el) => el.href);
await page.click(".handler-update-link");
await page.waitForSelector("pre");
assertEquals(href, await page.url());
await assertNoPageComments(page);
const result = await page.$eval("pre", (el) => {
return el.textContent;
});
assertEquals(JSON.parse(result), {
isPartial: true,
setFromMiddleware: true,
});
},
);
});
Deno.test("partials visit to async page", async () => {
await withPageName(
"./tests/fixture_partials/main.ts",
async (page, address) => {
await page.goto(`${address}/isPartial`);
await page.waitForSelector(".output");
const href = await page.$eval(".async-update-link", (el) => el.href);
await page.click(".async-update-link");
await page.waitForSelector("pre");
assertEquals(href, await page.url());
await assertNoPageComments(page);
const result = await page.$eval("pre", (el) => {
return el.textContent;
});
assertEquals(JSON.parse(result), {
isPartial: true,
setFromMiddleware: true,
});
},
);
});