Skip to content

Commit bacb36b

Browse files
committed
Move e2e 404 test utility functions to specific file
1 parent 1310faf commit bacb36b

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

e2e/tests/404.spec.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
*/
1616

1717
import {test, expect} from '@playwright/test';
18-
19-
const BASE_URL = 'http://localhost:5555';
18+
import { BASE_URL, expect404PageButtons, goTo404Page } from './utils';
2019

2120
test('Bad URL redirection to 404 page', async ({page}) => {
2221
const badUrls = [
@@ -52,35 +51,14 @@ test('Bad URL redirection to 404 page', async ({page}) => {
5251
}
5352
});
5453

55-
async function goTo404Page(page, query: string): Promise<void> {
56-
await page.goto(`${BASE_URL}/features/${query}`);
57-
await expect(page).toHaveURL(
58-
`${BASE_URL}/errors-404/feature-not-found?q=${query}`,
59-
);
60-
61-
const response = await page.context().request.fetch(page.url());
62-
expect(response.status()).toBe(404);
63-
}
64-
65-
async function expectButtons(page, {hasSearch}: {hasSearch: boolean}) {
66-
await expect(page.locator('#error-action-home-btn')).toBeVisible();
67-
await expect(page.locator('#error-action-report')).toBeVisible();
68-
69-
if (hasSearch) {
70-
await expect(page.locator('#error-action-search-btn')).toBeVisible();
71-
} else {
72-
await expect(page.locator('#error-action-search-btn')).toHaveCount(0);
73-
}
74-
}
75-
7654
test('shows similar features and all buttons when results exist', async ({
7755
page,
7856
}) => {
7957
const query = 'g';
8058
await goTo404Page(page, query);
8159

8260
await expect(page.locator('.similar-features-container')).toBeVisible();
83-
await expectButtons(page, {hasSearch: true});
61+
await expect404PageButtons(page, {hasSearch: true});
8462

8563
const similarContainerButton = page.locator('#error-action-search-btn');
8664
const pageContainer = page.locator('.page-container');
@@ -102,7 +80,7 @@ test('shows only home and report buttons when no similar features found', async
10280
await goTo404Page(page, query);
10381

10482
await expect(page.locator('.similar-features-container')).toHaveCount(0);
105-
await expectButtons(page, {hasSearch: false});
83+
await expect404PageButtons(page, {hasSearch: false});
10684

10785
await expect(page.locator('#error-detailed-message')).toContainText(
10886
`We could not find Feature ID: ${query}`,

e2e/tests/utils.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {Page, expect} from '@playwright/test';
1818

1919
const DEFAULT_FAKE_NOW = 'Dec 1 2020 12:34:56';
2020

21+
export const BASE_URL = 'http://localhost:5555';
22+
2123
export async function setupFakeNow(
2224
page: Page,
2325
fakeNowDateString = DEFAULT_FAKE_NOW,
@@ -86,3 +88,24 @@ export async function loginAsUser(page: Page, username: string) {
8688
await popup.getByText(username).click();
8789
await popup.waitForEvent('close');
8890
}
91+
92+
export async function goTo404Page(page, query: string): Promise<void> {
93+
await page.goto(`${BASE_URL}/features/${query}`);
94+
await expect(page).toHaveURL(
95+
`${BASE_URL}/errors-404/feature-not-found?q=${query}`,
96+
);
97+
98+
const response = await page.context().request.fetch(page.url());
99+
expect(response.status()).toBe(404);
100+
}
101+
102+
export async function expect404PageButtons(page, {hasSearch}: {hasSearch: boolean}) {
103+
await expect(page.locator('#error-action-home-btn')).toBeVisible();
104+
await expect(page.locator('#error-action-report')).toBeVisible();
105+
106+
if (hasSearch) {
107+
await expect(page.locator('#error-action-search-btn')).toBeVisible();
108+
} else {
109+
await expect(page.locator('#error-action-search-btn')).toHaveCount(0);
110+
}
111+
}

0 commit comments

Comments
 (0)