Skip to content

Commit 1c70c15

Browse files
committed
fix(e2e tests): better navigation
1 parent 4a33b4c commit 1c70c15

File tree

5 files changed

+35
-59
lines changed

5 files changed

+35
-59
lines changed

starters/apps/qwikrouter-test/src/routes/(common)/blog/layout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default component$(() => {
1111
<ul>
1212
<li>
1313
<Link
14+
// note missing / at the end of the href
1415
href="/qwikrouter-test/blog/what-is-resumability"
1516
data-test-link="blog-resumability"
1617
>
@@ -19,7 +20,7 @@ export default component$(() => {
1920
</li>
2021
<li>
2122
<Link
22-
href="/qwikrouter-test/blog/serializing-props"
23+
href="/qwikrouter-test/blog/serializing-props/"
2324
data-test-link="blog-serializing-props"
2425
>
2526
Serializing Props

starters/apps/qwikrouter-test/src/routes/(common)/products/[id]/index.tsx

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -102,40 +102,6 @@ export default component$(() => {
102102
added.
103103
</Link>
104104
</li>
105-
<li>
106-
<Link
107-
href="/qwikrouter-test/products/shirt-rewrite/"
108-
data-test-link="products-shirt-rewrite"
109-
>
110-
T-Shirt (Rewrite to /products/tshirt)
111-
</Link>
112-
</li>
113-
<li>
114-
<Link
115-
href="/qwikrouter-test/products/shirt-rewrite/?search=true"
116-
data-test-link="products-shirt-rewrite-with-search"
117-
>
118-
T-Shirt (Rewrite to /products/tshirt)
119-
</Link>
120-
</li>
121-
<li>
122-
<Link
123-
href="/qwikrouter-test/products/shirt-rewrite"
124-
data-test-link="products-shirt-rewrite-no-trailing-slash"
125-
>
126-
T-Shirt (Rewrite to /products/tshirt) Also trailing slash should be
127-
added.
128-
</Link>
129-
</li>
130-
<li>
131-
<Link
132-
href="/qwikrouter-test/products/shirt-rewrite-absolute-url/"
133-
data-test-link="products-shirt-rewrite-absolute-url"
134-
>
135-
T-Shirt (Rewrite to /products/tshirt) Also trailing slash should be
136-
added.
137-
</Link>
138-
</li>
139105
<li>
140106
<Link
141107
href="/qwikrouter-test/products/hoodie/"

starters/e2e/qwikrouter/auth.e2e.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function tests() {
6767
await page.keyboard.type("dev");
6868

6969
/*********** Successful Sign In, Dashboard ***********/
70-
await linkNavigate(ctx, "[data-test-sign-in]", 200);
70+
await linkNavigate(ctx, "[data-test-sign-in]", 302);
7171

7272
await assertPage(ctx, {
7373
pathname: "/qwikrouter-test/dashboard/",
@@ -85,7 +85,7 @@ function tests() {
8585
});
8686

8787
/*********** Go to Dashboard settings, shouldn't redirect if signed in ***********/
88-
await linkNavigate(ctx, '[data-test-link="dashboard-settings"]');
88+
await page.locator('[data-test-link="dashboard-settings"]').click();
8989
await assertPage(ctx, {
9090
pathname: "/qwikrouter-test/dashboard/settings/",
9191
title: "Dashboard Settings - Qwik",
@@ -94,7 +94,7 @@ function tests() {
9494
});
9595

9696
/*********** Sign out ***********/
97-
await linkNavigate(ctx, '[data-test-link="dashboard-sign-out"]');
97+
await page.locator('[data-test-link="dashboard-sign-out"]').click();
9898
await assertPage(ctx, {
9999
pathname: "/qwikrouter-test/sign-in/",
100100
});

starters/e2e/qwikrouter/page.e2e.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function tests() {
4444
});
4545

4646
/*********** Blog: resumability ***********/
47-
await linkNavigate(ctx, '[data-test-link="blog-resumability"]');
47+
await linkNavigate(ctx, '[data-test-link="blog-resumability"]', 301);
4848
await assertPage(ctx, {
4949
pathname: "/qwikrouter-test/blog/what-is-resumability/",
5050
title: "Blog: what-is-resumability - Qwik",
@@ -108,7 +108,7 @@ function tests() {
108108

109109
if (!javaScriptEnabled) {
110110
/*********** Products: shirt (301 redirect to /products/tshirt) ***********/
111-
await linkNavigate(ctx, '[data-test-link="products-shirt"]');
111+
await linkNavigate(ctx, '[data-test-link="products-shirt"]', 301);
112112
await assertPage(ctx, {
113113
pathname: "/qwikrouter-test/products/tshirt/",
114114
title: "Product tshirt - Qwik",
@@ -118,9 +118,9 @@ function tests() {
118118
});
119119

120120
/*********** Products: shirt (rewrite to /products/tshirt) ***********/
121-
await linkNavigate(ctx, '[data-test-link="products-shirt-rewrite"]');
121+
await linkNavigate(ctx, '[data-test-link="products-shirt-rewrite"]', 200);
122122
await assertPage(ctx, {
123-
pathname: "/qwikcity-test/products/shirt-rewrite/",
123+
pathname: "/qwikrouter-test/products/shirt-rewrite/",
124124
title: "Product tshirt - Qwik",
125125
layoutHierarchy: ["root"],
126126
h1: "Product: tshirt",
@@ -133,7 +133,7 @@ function tests() {
133133
'[data-test-link="products-shirt-rewrite-with-search"]',
134134
);
135135
await assertPage(ctx, {
136-
pathname: "/qwikcity-test/products/shirt-rewrite/",
136+
pathname: "/qwikrouter-test/products/shirt-rewrite/",
137137
title: "Product tshirt - Qwik",
138138
layoutHierarchy: ["root"],
139139
h1: "Product: tshirt",
@@ -151,15 +151,16 @@ function tests() {
151151
title: "500 Internal Server Error",
152152
});
153153
// Recover from error
154-
await setPage(ctx, "/qwikcity-test/products/hat/");
154+
await setPage(ctx, "/qwikrouter-test/products/hat/");
155155

156156
/*********** Products: shirt (rewrite to /products/tshirt) ***********/
157157
await linkNavigate(
158158
ctx,
159159
'[data-test-link="products-shirt-rewrite-no-trailing-slash"]',
160+
301,
160161
);
161162
await assertPage(ctx, {
162-
pathname: "/qwikcity-test/products/shirt-rewrite/",
163+
pathname: "/qwikrouter-test/products/shirt-rewrite/",
163164
title: "Product tshirt - Qwik",
164165
layoutHierarchy: ["root"],
165166
h1: "Product: tshirt",

starters/e2e/qwikrouter/util.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,32 @@ export async function linkNavigate(
105105
expect(true, `Link selector ${linkSelector} not found`).toBe(false);
106106
}
107107

108-
const href = await link.getAttribute("href")!;
109-
console.log(` ${href}`);
108+
const href = (await link.getAttribute("href"))!;
109+
console.log(` nav> ${href}`);
110110

111111
if (ctx.javaScriptEnabled) {
112-
// SPA
112+
const promise =
113+
href &&
114+
page.waitForURL(href.endsWith("/") ? href : href + "/", {
115+
timeout: 5000,
116+
waitUntil: "networkidle",
117+
});
113118
await link.click();
114-
await page.waitForTimeout(500);
119+
// give time for the head to update
120+
await new Promise((resolve) => setTimeout(resolve, 100));
121+
await promise;
115122
} else {
116-
// MPA
117-
const [rsp] = await Promise.all([page.waitForNavigation(), link.click()]);
118-
119-
const rspStatus = rsp!.status();
120-
if (rspStatus !== responseStatus) {
121-
const content = await rsp?.text();
122-
expect(rspStatus, `${href} (${rspStatus})\n${content}`).toBe(
123-
responseStatus,
124-
);
125-
}
123+
// if we didn't get a href, just wait for the next request
124+
const requestPromise = page.waitForRequest(href ? href : () => true, {
125+
timeout: 5000,
126+
});
127+
await link.click();
128+
const request = (await requestPromise)!;
129+
const response = await request.response();
130+
expect(
131+
response?.status(),
132+
`Expected status ${responseStatus} for ${href}`,
133+
).toBe(responseStatus);
126134
}
127135
}
128136

0 commit comments

Comments
 (0)