diff --git a/tests/fixtures_islands/OptOutPartialLink.tsx b/tests/fixtures_islands/OptOutPartialLink.tsx new file mode 100644 index 00000000..09cfe5f0 --- /dev/null +++ b/tests/fixtures_islands/OptOutPartialLink.tsx @@ -0,0 +1,7 @@ +export function OptOutPartialLink(props: { href: string; partial: string }) { + return ( +
+ link +
+ ); +} diff --git a/tests/partials_test.tsx b/tests/partials_test.tsx index d716a087..2dedcd80 100644 --- a/tests/partials_test.tsx +++ b/tests/partials_test.tsx @@ -19,6 +19,7 @@ import { expect } from "@std/expect"; import { PartialInIsland } from "./fixtures_islands/PartialInIsland.tsx"; import { FakeServer } from "../src/test_utils.ts"; import { JsonIsland } from "./fixtures_islands/JsonIsland.tsx"; +import { OptOutPartialLink } from "./fixtures_islands/OptOutPartialLink.tsx"; import * as path from "@std/path"; import { getBuildCache, setBuildCache } from "../src/app.ts"; import { retry } from "@std/async/retry"; @@ -33,11 +34,13 @@ function testApp(): App { const selfCounter = getIsland("SelfCounter.tsx"); const partialInIsland = getIsland("PartialInIsland.tsx"); const jsonIsland = getIsland("JsonIsland.tsx"); + const optOutPartialLink = getIsland("OptOutPartialLink.tsx"); const app = new App() .island(selfCounter, "SelfCounter", SelfCounter) .island(partialInIsland, "PartialInIsland", PartialInIsland) .island(jsonIsland, "JsonIsland", JsonIsland) + .island(optOutPartialLink, "OptOutPartialLink", OptOutPartialLink) .use(staticFiles()); setBuildCache(app, getBuildCache(allIslandApp)); @@ -1394,6 +1397,68 @@ Deno.test({ sanitizeOps: false, }); +Deno.test({ + name: "partials - opt out of partial navigation in island", + fn: async () => { + const app = testApp() + .get("/partial", (ctx) => { + return ctx.render( + + +

Fail

+
+
, + ); + }) + .get("/foo", (ctx) => + ctx.render( + + +

done

+ +
+
, + )) + .get("/", (ctx) => { + return ctx.render( + +
+
+ +
+ +

init

+ +
+
+
, + ); + }); + + await withBrowserApp(app, async (page, address) => { + await retry(async () => { + await page.goto(address, { waitUntil: "load" }); + await page.locator(".ready").wait(); + + await page.locator(".increment").click(); + await waitForText(page, ".output", "1"); + + await Promise.all([ + page.waitForNavigation(), + page.locator(".update").click(), + ]); + await page.waitForSelector(".done"); + + const url = new URL(page.url!); + expect(url.pathname).toEqual("/foo"); + await waitForText(page, ".output", "0"); + }); + }); + }, + sanitizeResources: false, + sanitizeOps: false, +}); + Deno.test({ name: "partials - restore scroll position", fn: async () => { diff --git a/tests/test_utils.tsx b/tests/test_utils.tsx index 65313f8b..18445d7a 100644 --- a/tests/test_utils.tsx +++ b/tests/test_utils.tsx @@ -26,6 +26,7 @@ import { Multiple1, Multiple2 } from "./fixtures_islands/Multiple.tsx"; import { Foo } from "./fixture_island_groups/routes/foo/(_islands)/Foo.tsx"; import { NodeProcess } from "./fixtures_islands/NodeProcess.tsx"; import { FreshAttrs } from "./fixtures_islands/FreshAttrs.tsx"; +import { OptOutPartialLink } from "./fixtures_islands/OptOutPartialLink.tsx"; export function getIsland(pathname: string) { return path.join( @@ -397,6 +398,11 @@ export const allIslandApp = new App() .island(getIsland("SelfCounter.tsx"), "SelfCounter", SelfCounter) .island(getIsland("NodeProcess.tsx"), "NodeProcess", NodeProcess) .island(getIsland("FreshAttrs.tsx"), "FreshAttrs", FreshAttrs) + .island( + getIsland("OptOutPartialLink.tsx"), + "OptOutPartialLink", + OptOutPartialLink, + ) .island( getIsland("../fixture_island_groups/routes/foo/(_islands)/Foo.tsx"), "Foo",