-
Notifications
You must be signed in to change notification settings - Fork 1
/
Employee.test.ts
100 lines (79 loc) · 2.89 KB
/
Employee.test.ts
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
import { test, Page, expect } from "@playwright/test";
let page: Page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
// Click the Confirm button in the dialog that appears when the request is successful.
page.on("dialog", (dialog) => dialog.accept());
await page.goto("/employees");
await page.waitForLoadState("networkidle");
});
test.afterAll(async () => {
await page.close();
});
test.describe("Employee page", () => {
test("Reading employee", async () => {
expect(
await page.getByRole("table").getByRole("row").allTextContents()
).toStrictEqual([
// table header
"IDName",
// table contents
"1foo",
"2bar",
"3baz",
"4error employee",
]);
});
test("Creating employee", async () => {
await page.locator("text=/Create new employee/i").click();
await expect(page).toHaveURL(/.*new/);
await page.locator("data-testid=input-name").fill("foobar");
await Promise.all([
page.waitForResponse((res) => res.url().includes("/employee")),
page.locator("input[type=submit]").click(),
]);
// Make sure the updated values are reflected after the page is reloaded
await page.reload();
await expect(page.locator('text="foobar"')).toBeVisible();
});
test("Updating employee", async () => {
const nameInput = page.locator("data-testid=input-name");
const oldName = await page.getByRole("cell", { name: "baz" }).textContent();
const targetEmployeeIdLink = page
.getByRole("row", { name: oldName! })
.getByRole("cell")
.first()
.getByRole("link");
// Render Input Element with employee name
await targetEmployeeIdLink.click();
await expect(nameInput).toBeVisible();
await expect(await nameInput.inputValue()).toBe(oldName);
// Fill new name and submit
await nameInput.fill("bazfoobar");
await Promise.all([
page.waitForResponse((res) => res.url().includes("/employee")),
page.locator("input[type=submit]").click(),
]);
// Make sure the updated values are reflected after the page is reloaded
await page.reload();
await expect(page.getByRole("cell", { name: "bazfoobar" })).toBeVisible();
});
test("Deleting employee", async () => {
// Employee name is exist is fail
const name = (await page.getByRole("cell", { name: "baz" }).textContent())!;
const employeeIdLink = page
.getByRole("row", { name })
.getByRole("cell")
.first()
.getByRole("link");
// Render Input Element with employee name
await employeeIdLink.click();
await Promise.all([
page.waitForResponse((res) => res.url().includes("/employee")),
page.getByRole("button", { name: "Remove" }).click(),
]);
// Make sure the updated values are reflected after the page is reloaded
await page.reload();
await expect(page.getByRole("cell", { name })).toHaveCount(0);
});
});