This repository has been archived by the owner on Aug 7, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
search.spec.js
145 lines (115 loc) · 4.58 KB
/
search.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// @ts-check
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
const defaultUsers = 9;
test("Search has title", async ({ page }) => {
await page.goto("/search");
await expect(page).toHaveTitle(/Search/);
});
test("Navigate to the Search page", async ({ page }) => {
await page.goto("/");
await page
.getByRole("navigation")
.getByRole("link", { name: "Search" })
.click();
await page.waitForLoadState("domcontentloaded");
await expect(page.locator("h1")).toHaveText("Search");
});
test("Search works correctly", async ({ page }) => {
// 1. navigate to search page
await page.goto("/search");
// 2. show no users are listed
await expect(page.locator("main li")).toHaveCount(defaultUsers);
// 3. type in search and check that user with the name exist and check a name doesn't exist
const input = page.locator("[name='keyword']");
await input.type("_test-profile-user-1");
await page.locator("[type='submit']").click();
await expect(page.locator("main li")).toHaveCount(1);
});
test("Search page has random results when no search term used", async ({
page,
}) => {
await page.goto("/search");
const input = page.locator("[name='keyword']");
await input.fill("");
await page.locator("[type='submit']").click();
await expect(page.locator("main li")).toHaveCount(defaultUsers);
});
test("Search page shows random results after typing 1 characters", async ({
page,
}) => {
await page.goto("/search");
const input = page.locator("[name='keyword']");
await input.type("e");
await page.locator("[type='submit']").click();
await expect(page.locator("main li")).toHaveCount(defaultUsers);
});
test("Search page shows results after typing 3 characters", async ({
page,
}) => {
await page.goto("/search");
const input = page.locator("[name='keyword']");
await input.type("aka");
await page.locator("[type='submit']").click();
await expect(page.locator("main li")).toContainText(["aka"]);
});
test("Search term persistence after navigating back", async ({ page }) => {
// 1. Perform search
await page.goto("/search");
const input = page.locator("[name='keyword']");
const searchTerm = "_test-profile-user-1";
const searchName = "Test User Name 1";
await input.fill(searchTerm);
await page.locator("[type='submit']").click();
// 2. Navigate to profile
await expect(page).toHaveURL(`/search?userSearchParam=${searchTerm}`);
await page.waitForLoadState("domcontentloaded");
await page.locator(`a h2:has-text('${searchTerm}')`).click();
await page.waitForURL(`/${searchTerm}`);
// 3. Check if the profile is displayed
await expect(page).toHaveURL(`/${searchTerm}`);
await expect(page.locator("h1")).toHaveText(`${searchName}`);
// 4. Go back and check that search term is still here
await page.goBack();
const inputAfterNavigation = page.locator("[name='keyword']");
const inputFieldValue = await inputAfterNavigation.inputValue();
expect(inputFieldValue).toBe(searchTerm);
});
test("find the profile after providing concise name", async ({ page }) => {
const searchTerm = "_test-profile-user-1";
// 1. Start from the homepage
await page.goto("/");
// 2. look for and click on the search element
const searchLink = page.locator(
"nav ul:first-child > li:first-child > a[href='/search']",
);
await searchLink.click();
// 3. find the input field and type the whole name
const input = page.locator("[name='keyword']");
await input.fill(searchTerm);
await page.locator("[type='submit']").click();
// 4. select and click on the profile by matching name string
const profileHeader = page.locator(`h2:has-text('${searchTerm}')`);
const profileHeaderText = await profileHeader.innerText();
await expect(profileHeaderText).toContain(searchTerm);
});
test.describe("accessibility tests (light)", () => {
test.use({ colorScheme: "light" });
test("should pass axe wcag accessibility tests (light)", async ({ page }) => {
await page.goto("/search");
const accessibilityScanResults = await new AxeBuilder({ page })
.withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"])
.analyze();
expect(accessibilityScanResults.violations).toEqual([]);
});
});
test.describe("accessibility tests (dark)", () => {
test.use({ colorScheme: "dark" });
test("should pass axe wcag accessibility tests (dark)", async ({ page }) => {
await page.goto("/search");
const accessibilityScanResults = await new AxeBuilder({ page })
.withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"])
.analyze();
expect(accessibilityScanResults.violations).toEqual([]);
});
});