Skip to content

Commit 9fa4290

Browse files
committed
chore(qc): extra tests for redirects
1 parent ec25630 commit 9fa4290

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { RequestEvent } from "@builder.io/qwik-city";
2+
3+
export const onGet = (ev: RequestEvent) => {
4+
if (ev.url.pathname === "/qwikcity-test/redirectme/") {
5+
throw ev.redirect(301, "/qwikcity-test/");
6+
}
7+
};

starters/e2e/qwikcity/nav.spec.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -457,20 +457,20 @@ test.describe("actions", () => {
457457
"/qwikcity-test/issue7732/c/?redirected=true",
458458
);
459459
});
460-
// TODO: Fix this test (currently not working because the action redirect adds a `/q-data.json` at the end of the path)
461-
test.fixme(
462-
"action with redirect without query params in a route with query param should redirect to route without query params",
463-
async ({ page }) => {
464-
await page.goto(
465-
"/qwikcity-test/action-redirect-without-search-params/?test=test",
466-
);
467-
const button = page.locator("button");
468-
await button.click();
469-
await page.waitForURL(
470-
"/qwikcity-test/action-redirect-without-search-params-target/",
471-
);
472-
},
473-
);
460+
test("action with redirect without query params in a route with query param should redirect to route without query params", async ({
461+
page,
462+
}) => {
463+
await page.goto(
464+
"/qwikcity-test/action-redirect-without-search-params/?test=test",
465+
);
466+
const button = page.locator("button");
467+
await button.click();
468+
await page.waitForURL(
469+
"/qwikcity-test/action-redirect-without-search-params-target/",
470+
);
471+
const searchParams = new URL(page.url()).searchParams;
472+
expect(searchParams.size).toBe(0);
473+
});
474474
test("media in home page", async ({ page }) => {
475475
await page.goto("/qwikcity-test/");
476476

@@ -521,6 +521,22 @@ test.describe("actions", () => {
521521

522522
await expect(page.locator("#redirected-result")).toHaveText("true");
523523
});
524+
525+
test.only("server plugin q-data redirect from /redirectme to /", async ({
526+
baseURL,
527+
}) => {
528+
const res = await fetch(
529+
new URL("/qwikcity-test/redirectme/q-data.json", baseURL),
530+
{
531+
redirect: "manual",
532+
headers: {
533+
Accept: "application/json",
534+
},
535+
},
536+
);
537+
expect(res.status).toBe(301);
538+
expect(res.headers.get("Location")).toBe("/qwikcity-test/q-data.json");
539+
});
524540
}
525541
});
526542

0 commit comments

Comments
 (0)