This repository was archived by the owner on Sep 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathTable.ts
More file actions
92 lines (78 loc) · 2.56 KB
/
Table.ts
File metadata and controls
92 lines (78 loc) · 2.56 KB
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
import { expect, Locator, Page } from "@playwright/test";
export class Table {
private readonly _page: Page;
_table: Locator;
private constructor(page: Page, table: Locator) {
this._page = page;
this._table = table;
}
/**
* @param page
* @param tableAriaLabel the unique aria-label that corresponds to the DOM element that contains the Table. E.g. <table aria-label="identifier"></table>
* @returns a new instance of a Toolbar
*/
static async build(page: Page, tableAriaLabel: string) {
const table = page.locator(`table[aria-label="${tableAriaLabel}"]`);
await expect(table).toBeVisible();
const result = new Table(page, table);
await result.waitUntilDataIsLoaded();
return result;
}
async waitUntilDataIsLoaded() {
const rows = this._table.locator(
'xpath=//tbody[not(@aria-label="Table loading")]'
);
await expect(rows.first()).toBeVisible();
const rowsCount = await rows.count();
expect(rowsCount).toBeGreaterThanOrEqual(1);
}
async clickSortBy(columnName: string) {
await this._table
.getByRole("button", { name: columnName, exact: true })
.click();
await this.waitUntilDataIsLoaded();
}
async clickAction(actionName: string, rowIndex: number) {
await this._table
.locator(`button[aria-label="Kebab toggle"]`)
.nth(rowIndex)
.click();
await this._page.getByRole("menuitem", { name: actionName }).click();
}
async verifyTableIsSortedBy(columnName: string, asc: boolean = true) {
await expect(
this._table.getByRole("columnheader", { name: columnName })
).toHaveAttribute("aria-sort", asc ? "ascending" : "descending");
}
async verifyColumnContainsText(columnName: string, expectedValue: string) {
await expect(
this._table.locator(`td[data-label="${columnName}"]`, {
hasText: expectedValue,
})
).toBeVisible();
}
async verifyTableHasNoData() {
await expect(
this._table.locator(`tbody[aria-label="Table empty"]`)
).toBeVisible();
}
async validateNumberOfRows(
expectedRows: {
equal?: number;
greaterThan?: number;
lessThan?: number;
},
columnName: string
) {
const rows = this._table.locator(`td[data-label="${columnName}"]`);
if (expectedRows.equal) {
expect(await rows.count()).toBe(expectedRows.equal);
}
if (expectedRows.greaterThan) {
expect(await rows.count()).toBeGreaterThan(expectedRows.greaterThan);
}
if (expectedRows.lessThan) {
expect(await rows.count()).toBeLessThan(expectedRows.lessThan);
}
}
}