-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpaginatedTable.test.ts
143 lines (110 loc) · 5.84 KB
/
paginatedTable.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
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
import {expect, test} from '@playwright/test';
import {NodesPage} from '../nodes/NodesPage';
import {setupEmptyNodesMock, setupLargeNodesMock, setupNodesMock} from './mocks';
import {ClusterNodesTable} from './paginatedTable';
test.describe('PaginatedTable', () => {
test('loads data in chunks when scrolling', async ({page}) => {
// Setup mocks
await setupNodesMock(page);
// Navigate to nodes page which uses PaginatedTable
const nodesPage = new NodesPage(page);
await nodesPage.goto();
const paginatedTable = new ClusterNodesTable(page);
await paginatedTable.waitForTableVisible();
await paginatedTable.waitForTableData();
// Get initial row count (should be first chunk)
const initialVisibleRows = await paginatedTable.getRowCount();
expect(initialVisibleRows).toBeGreaterThan(0);
expect(initialVisibleRows).toBeLessThan(100); // Should not show all rows initially
// Get data from first visible row to verify initial chunk
const firstRowData = await paginatedTable.getRowData(0);
expect(firstRowData['Host']).toBe('host-0.test');
expect(firstRowData['Version']).toBe('main.b7cfb36');
await paginatedTable.scrollToBottom();
await paginatedTable.waitForTableData();
// Get data from last row to verify second chunk loaded
const rowCount = await paginatedTable.getRowCount();
const lastRowData = await paginatedTable.getRowData(rowCount - 1);
expect(lastRowData['Host']).toBe('host-99.test');
expect(lastRowData['Version']).toBe('main.b7cfb36');
// Verify uptime format matches the pattern from nodes.test.ts
const uptimeValues = await paginatedTable.getColumnValues('Uptime');
for (const uptime of uptimeValues) {
expect(uptime).toMatch(/^(\d+d\s)?(\d+):(\d{2}):(\d{2})$/); // Format: DDd? HH:MM:SS
}
});
test('loads data when scrolling to middle of table', async ({page}) => {
// Setup mocks with large dataset
await setupLargeNodesMock(page);
// Navigate to nodes page which uses PaginatedTable
const nodesPage = new NodesPage(page);
await nodesPage.goto();
const paginatedTable = new ClusterNodesTable(page);
await paginatedTable.waitForTableVisible();
await paginatedTable.waitForTableData();
// Get initial row count
const initialVisibleRows = await paginatedTable.getRowCount();
expect(initialVisibleRows).toBeGreaterThan(0);
expect(initialVisibleRows).toBeLessThan(1000); // Should not show all rows initially
// Scroll to middle of container
await paginatedTable.scrollToMiddle();
await paginatedTable.waitForTableData();
// Get data from middle rows to verify middle chunk loaded
const rowCount = await paginatedTable.getRowCount();
const middleRowIndex = Math.floor(rowCount / 2);
const middleRowData = await paginatedTable.getRowData(middleRowIndex);
expect(middleRowData['Host']).toBe('host-500.test');
expect(middleRowData['Version']).toBe('main.b7cfb36');
});
test('displays empty state when no data is present', async ({page}) => {
// Setup mocks with empty data
await setupEmptyNodesMock(page);
const nodesPage = new NodesPage(page);
await nodesPage.goto();
const paginatedTable = new ClusterNodesTable(page);
await paginatedTable.waitForTableVisible();
// Verify empty state
const rowCount = await paginatedTable.getRowCount();
expect(rowCount).toBe(1);
const emptyDataMessage = await paginatedTable.getEmptyDataMessageLocator();
await expect(emptyDataMessage).toContainText('No such nodes');
});
test('handles 10 pages of data correctly', async ({page}) => {
// Setup mocks with 1000 nodes (100 per page * 10 pages)
await setupLargeNodesMock(page);
const nodesPage = new NodesPage(page);
await nodesPage.goto();
const paginatedTable = new ClusterNodesTable(page);
await paginatedTable.waitForTableVisible();
await paginatedTable.waitForTableData();
// Verify initial data load
const initialRowCount = await paginatedTable.getRowCount();
expect(initialRowCount).toBeGreaterThan(0);
expect(initialRowCount).toBeLessThan(1000); // Should not load all rows at once
await paginatedTable.scrollToBottom();
await paginatedTable.waitForTableData();
// Verify we can load data from the last page
const finalRowCount = await paginatedTable.getRowCount();
const lastRowData = await paginatedTable.getRowData(finalRowCount - 1);
expect(lastRowData['Host']).toBe('host-999.test'); // Last node in 1000 nodes (0-999)
});
test('handles 100 pages of data correctly', async ({page}) => {
// Setup mocks with 10000 nodes (100 per page * 10 pages)
await setupLargeNodesMock(page, 10000);
const nodesPage = new NodesPage(page);
await nodesPage.goto();
const paginatedTable = new ClusterNodesTable(page);
await paginatedTable.waitForTableVisible();
await paginatedTable.waitForTableData();
// Verify initial data load
const initialRowCount = await paginatedTable.getRowCount();
expect(initialRowCount).toBeGreaterThan(0);
expect(initialRowCount).toBeLessThan(10000); // Should not load all rows at once
await paginatedTable.scrollToBottom();
await paginatedTable.waitForTableData();
// Verify we can load data from the last page
const finalRowCount = await paginatedTable.getRowCount();
const lastRowData = await paginatedTable.getRowData(finalRowCount - 1);
expect(lastRowData['Host']).toBe('host-9999.test'); // Last node in 1000 nodes (0-999)
});
});