fix: partial form redirect not working (#2497)

Fixes https://github.com/denoland/fresh/issues/2404
This commit is contained in:
Marvin Hagemeister
2024-06-05 09:42:27 +02:00
committed by GitHub
parent d613c6a6ba
commit fba3f2b845
2 changed files with 74 additions and 8 deletions
+54
View File
@@ -1538,6 +1538,60 @@ Deno.test({
},
});
Deno.test({
name: "partials - submit form redirecct",
fn: async () => {
const app = testApp()
.get("/done", (ctx) => {
return ctx.render(
<Doc>
<Partial name="foo">
<h1 class="done">success</h1>
</Partial>
</Doc>,
);
})
.post("/partial", async (ctx) => {
const data = await ctx.req.formData();
const name = String(data.get("name"));
return new Response(null, {
status: 303,
headers: { Location: `/done?name=${encodeURIComponent(name)}` },
});
})
.get("/", (ctx) => {
return ctx.render(
<Doc>
<div f-client-nav>
<form action="/partial" method="post">
<input name="name" value="foo" />
<Partial name="foo">
<p class="init">init</p>
</Partial>
<SelfCounter />
<button class="update">
update
</button>
</form>
</div>
</Doc>,
);
});
await withBrowserApp(app, async (page, address) => {
await page.goto(address, { waitUntil: "load" });
await page.locator(".ready").wait();
await page.locator(".update").click();
await page.locator(".done").wait();
const pathname = await page.evaluate(() => window.location.pathname);
expect(pathname).toEqual("/done");
});
},
});
Deno.test({
name: "partials - submit form via external submitter",
fn: async () => {