-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpaginatedTable.ts
253 lines (216 loc) · 8.73 KB
/
paginatedTable.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
import type {Locator, Page} from '@playwright/test';
import {VISIBILITY_TIMEOUT} from '../tenant/TenantPage';
export class TableControls {
protected page: Page;
protected tableSelector: Locator;
protected searchInput: Locator;
protected radioButtons: Locator;
protected countLabel: Locator;
protected refreshButton: Locator;
protected refreshIntervalSelect: Locator;
protected columnSetupButton: Locator;
protected columnSetupPopup: Locator;
constructor(page: Page, tableSelector: Locator) {
this.page = page;
this.tableSelector = tableSelector;
this.searchInput = this.tableSelector.locator('.ydb-search input');
this.radioButtons = this.tableSelector.locator('.g-radio-button');
this.countLabel = this.tableSelector.locator('.ydb-entities-count .g-label__content');
this.refreshButton = page.locator('.auto-refresh-control button[aria-label="Refresh"]');
this.refreshIntervalSelect = page.getByTestId('ydb-autorefresh-select');
this.columnSetupButton = this.tableSelector.locator(
'.g-tree-select.g-table-column-setup button',
);
this.columnSetupPopup = page.locator('.g-popup .g-select-popup.g-tree-select__popup');
}
async search(searchTerm: string) {
await this.searchInput.fill(searchTerm);
}
async selectRadioOption(groupIndex: number, optionText: string) {
const radioGroup = this.radioButtons.nth(groupIndex);
const option = radioGroup.locator(`.g-radio-button__option:has-text("${optionText}")`);
await option.evaluate((el) => (el as HTMLElement).click());
}
async getCount(): Promise<number> {
const countText = await this.countLabel.innerText();
const match = countText.match(/: (\d+)/);
return match ? parseInt(match[1], 10) : 0;
}
async clickRefreshButton() {
await this.refreshButton.click();
}
async setRefreshInterval(interval: string) {
await this.refreshIntervalSelect.click();
await this.page.locator('.g-select-list__option', {hasText: interval}).click();
}
async getRefreshInterval(): Promise<string> {
const text = await this.refreshIntervalSelect
.locator('.g-select-control__option-text')
.innerText();
return text;
}
async openColumnSetup() {
await this.columnSetupButton.click();
await this.columnSetupPopup.waitFor({state: 'visible'});
}
async setColumnChecked(columnName: string) {
const columnOption = this.columnSetupPopup.locator(`[data-list-item="${columnName}"]`);
const checkIcon = columnOption.locator('.g-icon.g-color-text_color_info');
const isVisible = await checkIcon.isVisible();
if (!isVisible) {
await columnOption.click();
}
}
async setColumnUnchecked(columnName: string) {
const columnOption = this.columnSetupPopup.locator(`[data-list-item="${columnName}"]`);
const checkIcon = columnOption.locator('.g-icon.g-color-text_color_info');
const isVisible = await checkIcon.isVisible();
if (isVisible) {
await columnOption.click();
}
}
async applyColumnVisibility() {
const applyButton = this.columnSetupPopup.locator('button:has-text("Apply")');
await applyButton.click();
await this.columnSetupPopup.waitFor({state: 'hidden'});
}
async getVisibleColumnsCount(): Promise<string> {
const statusText = await this.columnSetupButton
.locator('.g-table-column-setup__status')
.innerText();
return statusText;
}
async isColumnVisible(columnName: string): Promise<boolean> {
const columnOption = this.columnSetupPopup.locator(`[data-list-item="${columnName}"]`);
const checkIcon = columnOption.locator('.g-icon.g-color-text_color_info');
return await checkIcon.isVisible();
}
}
export class PaginatedTable {
protected controls: TableControls;
protected page: Page;
private tableSelector: Locator;
private tableRows: Locator;
private emptyTableRows: Locator;
private headCells: Locator;
private scrollContainer: string;
constructor(page: Page, scrollContainer = '.ydb-cluster') {
this.page = page;
this.tableSelector = page.locator('.ydb-table-with-controls-layout');
this.headCells = this.tableSelector.locator('.ydb-paginated-table__head-cell');
this.tableRows = this.tableSelector.locator('.ydb-paginated-table__row');
this.emptyTableRows = this.tableSelector.locator('.ydb-paginated-table__row_empty');
this.scrollContainer = scrollContainer;
this.controls = new TableControls(page, this.tableSelector);
}
getControls(): TableControls {
return this.controls;
}
async waitForTableVisible() {
await this.tableSelector.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT});
}
async getCount(): Promise<number> {
return this.controls.getCount();
}
async search(searchTerm: string) {
await this.controls.search(searchTerm);
}
async getColumnValues(columnName: string): Promise<string[]> {
const columnIndex = await this.getColumnIndex(columnName);
return this.tableRows.evaluateAll(
(rows, index) =>
rows.map(
(row) =>
row.querySelector(`td:nth-child(${index + 1})`)?.textContent?.trim() || '',
),
columnIndex,
);
}
async getRowData(rowIndex: number): Promise<Record<string, string>> {
const rowCells = this.tableRows.nth(rowIndex).locator('td');
const headerCount = await this.headCells.count();
const rowData: Record<string, string> = {};
for (let i = 0; i < headerCount; i++) {
const headerText = (await this.headCells.nth(i).innerText()).trim().replace(/\n/g, ' ');
const cellText = (await rowCells.nth(i).innerText()).trim().replace(/\n/g, ' ');
rowData[headerText] = cellText;
}
return rowData;
}
async getRowCount(): Promise<number> {
return this.tableRows.count();
}
async getEmptyDataMessageLocator() {
return this.emptyTableRows.nth(0);
}
async waitForTableToLoad() {
await this.tableSelector.waitFor({state: 'visible'});
}
async waitForTableData(timeout = 2000) {
await this.page.waitForFunction(
() => {
const rows = document.querySelectorAll('.ydb-paginated-table__row');
const loadingRows = document.querySelectorAll('.ydb-paginated-table__row_loading');
return (
rows.length > 0 &&
rows[0].querySelectorAll('td').length > 0 &&
loadingRows.length === 0
);
},
{timeout},
);
await this.page.waitForTimeout(1000);
}
async sortByColumn(columnName: string) {
const columnHeader = this.tableSelector.locator(
`.ydb-paginated-table__head-cell:has-text("${columnName}")`,
);
await columnHeader.click();
await this.page.waitForTimeout(1000);
await this.waitForTableData();
}
async scrollToBottom() {
await this.page.evaluate((selector) => {
const container = document.querySelector(selector);
if (container) {
container.scrollTo({top: container.scrollHeight, behavior: 'instant'});
}
}, this.scrollContainer);
}
async scrollToMiddle() {
await this.page.evaluate((selector) => {
const container = document.querySelector(selector);
if (container) {
container.scrollTo({
top: Math.floor(container.scrollHeight / 2),
behavior: 'instant',
});
}
}, this.scrollContainer);
}
private async getColumnIndex(columnName: string): Promise<number> {
const count = await this.headCells.count();
for (let i = 0; i < count; i++) {
const cellText = (await this.headCells.nth(i).innerText()).trim().replace(/\n/g, ' ');
if (cellText === columnName) {
return i;
}
}
throw new Error(`Column "${columnName}" not found`);
}
}
export class ClusterNodesTable extends PaginatedTable {
constructor(page: Page) {
super(page, '.ydb-cluster');
}
}
export class ClusterStorageTable extends PaginatedTable {
constructor(page: Page) {
super(page, '.ydb-cluster');
}
}
export class DiagnosticsNodesTable extends PaginatedTable {
constructor(page: Page) {
super(page, '.kv-tenant-diagnostics__page-wrapper');
}
}