-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgrid-header.component.js
More file actions
139 lines (118 loc) · 4.77 KB
/
Copy pathgrid-header.component.js
File metadata and controls
139 lines (118 loc) · 4.77 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
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
const { expect } = require('@playwright/test');
const { GridRendererComponent } = require('./grid-renderer.component');
class GridHeaderComponent {
constructor(page, gridRootLocator, renderer = undefined) {
this.page = page;
this.gridRoot = gridRootLocator;
this.headers = this.gridRoot.locator('.tabulator-col');
this.renderer = renderer || new GridRendererComponent(page, gridRootLocator);
}
async getColumnNames() {
const titles = this.gridRoot.locator('.tabulator-col .tabulator-col-title');
const count = await titles.count();
const names = [];
for (let index = 0; index < count; index += 1) {
names.push(this._normalizeTitle(await titles.nth(index).innerText()));
}
return names;
}
async countColumns() {
return this.gridRoot.locator('.tabulator-col .tabulator-col-title').count();
}
async expectHasAnyColumns() {
await expect(this.gridRoot.locator('.tabulator-col .tabulator-col-title').first()).toBeVisible();
}
async clickAction(columnName, action) {
const headerTitle = this._headerTitleByName(columnName);
const actionTitleMap = {
rename: 'Rename column',
delete: 'Delete column',
duplicate: 'Duplicate column',
'add-left': 'Add column left',
'add-right': 'Add column right',
'sort-asc': 'Sort ascending',
'sort-desc': 'Sort descending',
'sort-none': 'Clear sort',
};
const title = actionTitleMap[action] || action;
const headerRoot = headerTitle.locator(`xpath=ancestor::*[contains(@class,'tabulator-col')]`);
const actionLocator = headerRoot.locator(`[aria-label="${title}"], [title="${title}"]`).first();
await actionLocator.click();
}
async renameColumn(columnName, newName) {
await this.clickAction(columnName, 'rename');
await this.fillTextInputModal(newName);
}
async addColumnLeft(columnName, newName) {
await this.clickAction(columnName, 'add-left');
await this.fillTextInputModal(newName);
}
async addColumnRight(columnName, newName) {
await this.clickAction(columnName, 'add-right');
await this.fillTextInputModal(newName);
}
async duplicateColumn(columnName, newName) {
await this.clickAction(columnName, 'duplicate');
await this.fillTextInputModal(newName);
}
async deleteColumn(columnName) {
await this.clickAction(columnName, 'delete');
const confirmBackdrop = this.page.locator('#confirm-modal-backdrop');
if ((await confirmBackdrop.count()) > 0 && (await confirmBackdrop.isVisible())) {
await confirmBackdrop.locator('#confirm-modal-ok').click();
await expect(confirmBackdrop).toBeHidden();
}
}
async sortAsc(columnName) {
await this._ensureSortState(columnName, 'asc', 'sort-asc');
await this.renderer.waitForGridSettle({ columnName });
}
async sortDesc(columnName) {
await this._ensureSortState(columnName, 'desc', 'sort-desc');
await this.renderer.waitForGridSettle({ columnName });
}
async clearSort(columnName) {
await this.clickAction(columnName, 'sort-none');
}
async setColumnFilter(columnName, value) {
const header = this._headerTitleByName(columnName).locator(`xpath=ancestor::*[contains(@class,'tabulator-col')]`);
const input = header.locator('.tabulator-header-filter input');
await input.fill(value);
await input.press('Enter');
}
async getColumnFilterValue(columnName) {
const header = this._headerTitleByName(columnName).locator(`xpath=ancestor::*[contains(@class,'tabulator-col')]`);
return header.locator('.tabulator-header-filter input').inputValue();
}
async getColumnSortState(columnName) {
const header = this._headerTitleByName(columnName)
.locator(`xpath=ancestor::*[contains(@class,'tabulator-col')]`)
.first();
return (await header.getAttribute('aria-sort')) || '';
}
async _ensureSortState(columnName, expectedState, action) {
await expect(async () => {
await this.clickAction(columnName, action);
const state = await this.getColumnSortState(columnName);
expect(String(state)).toContain(expectedState);
}).toPass({ timeout: 3000, intervals: [100, 200, 400] });
}
_headerTitleByName(columnName) {
const normalized = this._normalizeTitle(columnName);
return this.gridRoot.locator('.tabulator-col-title', { hasText: normalized }).first();
}
_normalizeTitle(rawText) {
return String(rawText || '')
.split('\n')[0]
.trim();
}
async fillTextInputModal(value) {
const backdrop = this.page.locator('#text-input-modal-backdrop');
await expect(backdrop).toBeVisible();
const input = backdrop.locator('#text-input-modal-field');
await input.fill(String(value ?? ''));
await backdrop.locator('#text-input-modal-ok').click();
await expect(backdrop).toBeHidden();
}
}
module.exports = { GridHeaderComponent };