Skip to content

Commit 9be9e15

Browse files
committed
chore: e2e test
1 parent 8f14bb5 commit 9be9e15

File tree

7 files changed

+102
-1
lines changed

7 files changed

+102
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useLocation } from "@builder.io/qwik-city";
2+
import { component$ } from "@builder.io/qwik";
3+
4+
export default component$(() => {
5+
const location = useLocation();
6+
7+
return (
8+
<div>
9+
<h1>
10+
Should <strong>not</strong> have searchParams
11+
</h1>
12+
<pre>{JSON.stringify(location.url.searchParams.get("id"))}</pre>
13+
</div>
14+
);
15+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { routeAction$, Form } from "@builder.io/qwik-city";
2+
import { component$ } from "@builder.io/qwik";
3+
4+
export const useAction = routeAction$((_, event) => {
5+
throw event.redirect(
6+
302,
7+
"/qwikcity-test/action-redirect-without-search-params-target/",
8+
);
9+
});
10+
11+
export default component$(() => {
12+
const action = useAction();
13+
14+
return (
15+
<Form action={action}>
16+
<h1>Should have searchParams on the url</h1>
17+
<button type="submit">Submit</button>
18+
</Form>
19+
);
20+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { component$ } from "@builder.io/qwik";
2+
3+
export default component$(() => {
4+
return <div>empty default route A</div>;
5+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { component$ } from "@builder.io/qwik";
2+
import type { RequestHandler } from "@builder.io/qwik-city";
3+
4+
export const onGet: RequestHandler<void> = ({ redirect }) => {
5+
throw redirect(302, `/qwikcity-test/issue7732/c/?redirected=true`);
6+
};
7+
8+
export default component$(() => {
9+
return <div>B route with redirect</div>;
10+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { component$ } from "@builder.io/qwik";
2+
3+
export default component$(() => {
4+
return <div>route C should have redirected=true params</div>;
5+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { component$, Slot } from "@builder.io/qwik";
2+
import { Link } from "@builder.io/qwik-city";
3+
4+
export default component$(() => {
5+
return (
6+
<>
7+
<div style={{ display: "flex", gap: "10px" }}>
8+
<Link href="/issue7732/a/" id="issue7732-link-a">
9+
A
10+
</Link>
11+
12+
<Link
13+
href="/qwikcity-test/issue7732/b/?shouldOverrideRedirect=no"
14+
id="issue7732-link-b"
15+
>
16+
B
17+
</Link>
18+
<Link href="/issue7732/c/" id="issue7732-link-c">
19+
C
20+
</Link>
21+
</div>
22+
<Slot />
23+
</>
24+
);
25+
});

starters/e2e/qwikcity/nav.spec.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { $ } from "bun";
12
import {
23
assertPage,
34
getScrollHeight,
@@ -447,7 +448,27 @@ test.describe("actions", () => {
447448
await expect(result).toHaveText("3");
448449
}
449450
});
450-
451+
test("issue7732 link/useNavigate should not override loader/middleware redirect", async ({
452+
page,
453+
}) => {
454+
await page.goto("/qwikcity-test/issue7732/a/");
455+
const link = page.locator("#issue7732-link-b");
456+
await link.click();
457+
await expect(page).toHaveURL(
458+
"/qwikcity-test/issue7732/c/?redirected=true",
459+
);
460+
});
461+
// TODO: Fix this test (currently not working because the action redirect adds a `/q-data.json` at the end of the path)
462+
// test("action with redirect without query params in a route with query param should redirect to route without query params", async ({
463+
// page,
464+
// }) => {
465+
// await page.goto("/qwikcity-test/action-redirect-without-search-params/?test=test");
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+
// });
451472
test("media in home page", async ({ page }) => {
452473
await page.goto("/qwikcity-test/");
453474

0 commit comments

Comments
 (0)