Update tests to handle querystrings in page.route handlers

This commit is contained in:
Sebastian Martinez
2024-04-29 13:22:55 +02:00
parent 0eab6dafa6
commit 297c4b8ee1
6 changed files with 55 additions and 30 deletions
+13 -4
View File
@@ -414,7 +414,10 @@ test("only one modal can be open at a time", async ({ page }) => {
test.describe("browser error handling", () => {
test("error appears when folder can't be loaded", async ({ page }) => {
await page.route(
`**/v1/projects/${sourceBrowsingRid}/tree/${aliceMainHead}/src/`,
({ pathname }) =>
pathname.startsWith(
`/api/v1/projects/${sourceBrowsingRid}/tree/${aliceMainHead}/src`,
),
route => route.fulfill({ status: 500 }),
);
@@ -427,7 +430,9 @@ test.describe("browser error handling", () => {
});
test("error appears when file can't be loaded", async ({ page }) => {
await page.route(
`**/v1/projects/${sourceBrowsingRid}/blob/${aliceMainHead}/.hidden`,
({ pathname }) =>
pathname ===
`/api/v1/projects/${sourceBrowsingRid}/blob/${aliceMainHead}/.hidden`,
route => route.fulfill({ status: 500 }),
);
@@ -438,7 +443,9 @@ test.describe("browser error handling", () => {
});
test("error appears when README can't be loaded", async ({ page }) => {
await page.route(
`**/v1/projects/${sourceBrowsingRid}/readme/${aliceMainHead}`,
({ pathname }) =>
pathname ===
`/api/v1/projects/${sourceBrowsingRid}/readme/${aliceMainHead}`,
route => route.fulfill({ status: 500 }),
);
@@ -447,7 +454,9 @@ test.describe("browser error handling", () => {
});
test("error appears when navigating to missing file", async ({ page }) => {
await page.route(
`**/v1/projects/${sourceBrowsingRid}/blob/${aliceMainHead}/.hidden`,
({ pathname }) =>
pathname ===
`/api/v1/projects/${sourceBrowsingRid}/blob/${aliceMainHead}/.hidden`,
route => route.fulfill({ status: 500 }),
);
+10 -7
View File
@@ -28,13 +28,16 @@ test("test issue editing failing", async ({ page, authenticatedPeer }) => {
{ cwd: projectFolder },
);
await page.route(`**/v1/projects/${rid}/issues/*`, async route => {
if (route.request().method() === "PATCH") {
return route.fulfill({ status: 500 });
} else {
return route.fallback();
}
});
await page.route(
({ pathname }) => pathname.startsWith(`/api/v1/projects/${rid}/issues/`),
async route => {
if (route.request().method() === "PATCH") {
return route.fulfill({ status: 500 });
} else {
return route.fallback();
}
},
);
await page.goto(`${authenticatedPeer.uiUrl()}/${rid}/issues`);
await page.getByRole("link", { name: "This issue is going to fail" }).click();
+3 -1
View File
@@ -89,7 +89,9 @@ test("patch page", async ({ page }) => {
test("failed diff loading for a specific revision", async ({ page }) => {
await page.route(
"**/api/v1/projects/rad:z3fpY7nttPPa6MBnAv2DccHzQJnqe/diff/38c225e2a0b47ba59def211f4e4825c31d9463ec/9898da6155467adad511f63bf0fb5aa4156b92ef",
({ pathname }) =>
pathname ===
"/api/v1/projects/rad:z3fpY7nttPPa6MBnAv2DccHzQJnqe/diff/38c225e2a0b47ba59def211f4e4825c31d9463ec/9898da6155467adad511f63bf0fb5aa4156b92ef",
route => route.fulfill({ status: 500 }),
);
+2 -1
View File
@@ -32,7 +32,8 @@ test("load error", async ({ page }) => {
});
await page.route(
"**/api/v1/projects/rad:z4BwwjPCFNVP27FwVbDFgwVwkjcir",
({ pathname }) =>
pathname === "/api/v1/projects/rad:z4BwwjPCFNVP27FwVbDFgwVwkjcir",
route => route.fulfill({ status: 500 }),
);
+11 -7
View File
@@ -16,13 +16,17 @@ test("node page", async ({ page }) => {
});
test("empty pinned projects", async ({ page }) => {
await page.route("**/api/v1/projects?show=pinned", async route => {
await route.fulfill({
status: 200,
contentType: "application/json",
json: [],
});
});
await page.route(
({ hostname, pathname }) =>
pathname === "/api/v1/projects" && hostname === "seed.radicle.garden",
async route => {
await route.fulfill({
status: 200,
contentType: "application/json",
json: [],
});
},
);
await page.goto("/", {
waitUntil: "networkidle",
});
+16 -10
View File
@@ -101,21 +101,27 @@ test("project not found", async ({ page }) => {
});
test("response parse error", async ({ page }) => {
await page.route(`*/**/v1/projects/${sourceBrowsingRid}`, route => {
return route.fulfill({
json: [{ name: 1337 }],
});
});
await page.route(
({ pathname }) => pathname === `/api/v1/projects/${sourceBrowsingRid}`,
route => {
return route.fulfill({
json: [{ name: 1337 }],
});
},
);
await page.goto(sourceBrowsingUrl, { waitUntil: "networkidle" });
await expect(page).toHaveScreenshot();
});
test("response error", async ({ page }) => {
await page.route(`*/**/v1/projects/${sourceBrowsingRid}`, route => {
return route.fulfill({
status: 500,
});
});
await page.route(
({ pathname }) => pathname === `/api/v1/projects/${sourceBrowsingRid}`,
route => {
return route.fulfill({
status: 500,
});
},
);
await page.goto(sourceBrowsingUrl, { waitUntil: "networkidle" });
await expect(page).toHaveScreenshot();
});