Skip to content

Commit 9ac7047

Browse files
committed
chore: add tests for pagination
1 parent 341bd3d commit 9ac7047

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import type {Page} from '@playwright/test';
2+
3+
import {backend} from '../../utils/constants';
4+
5+
interface NodeMockOptions {
6+
offset: number;
7+
limit: number;
8+
}
9+
10+
export const generateNodeMock = async ({offset, limit}: NodeMockOptions) => {
11+
return Array.from({length: limit}, (_, i) => ({
12+
NodeId: offset + i + 1,
13+
SystemState: {
14+
Host: `host-${offset + i}.test`,
15+
DataCenter: `dc-${Math.floor((offset + i) / 10)}`,
16+
Rack: `rack-${Math.floor((offset + i) / 5)}`,
17+
Version: 'main.b7cfb36',
18+
StartTime: (Date.now() - 4 * 60 * 60 * 1000).toString(), // 4 hours ago
19+
LoadAverage: [0.1, 0.2, 0.3],
20+
NumberOfCpus: 8,
21+
SystemState: 'Green',
22+
MemoryUsed: ((8 + (i % 4)) * 1024 * 1024 * 1024).toString(), // 8-12GB
23+
MemoryLimit: (16 * 1024 * 1024 * 1024).toString(), // 16GB
24+
TotalSessions: 100,
25+
Tenants: ['local'],
26+
},
27+
CpuUsage: 10 + (i % 20),
28+
UptimeSeconds: 4 * 60 * 60, // 4 hours
29+
Disconnected: false,
30+
Tablets: [
31+
{
32+
TabletId: `tablet-${i}-1`,
33+
Type: 'DataShard',
34+
State: 'Active',
35+
Leader: true,
36+
},
37+
{
38+
TabletId: `tablet-${i}-2`,
39+
Type: 'DataShard',
40+
State: 'Active',
41+
Leader: false,
42+
},
43+
],
44+
}));
45+
};
46+
47+
export const setupNodesMock = async (page: Page) => {
48+
await page.route(`${backend}/viewer/json/nodes?*`, async (route) => {
49+
const url = new URL(route.request().url());
50+
const offset = parseInt(url.searchParams.get('offset') || '0', 10);
51+
const limit = parseInt(url.searchParams.get('limit') || '50', 10);
52+
53+
const nodes = await generateNodeMock({offset, limit});
54+
55+
await route.fulfill({
56+
status: 200,
57+
contentType: 'application/json',
58+
body: JSON.stringify({
59+
Overall: 'Green',
60+
Nodes: nodes,
61+
TotalNodes: '100',
62+
FoundNodes: '100',
63+
}),
64+
});
65+
});
66+
};
67+
68+
export const setupSettingsMock = async (page: Page) => {
69+
await page.route(`${backend}/api/settings`, async (route) => {
70+
await route.fulfill({
71+
status: 200,
72+
contentType: 'application/json',
73+
body: JSON.stringify({
74+
theme: 'light',
75+
language: 'en',
76+
autoRefreshInterval: 10000,
77+
}),
78+
});
79+
});
80+
};
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import {expect, test} from '@playwright/test';
2+
3+
import {NodesPage} from '../nodes/NodesPage';
4+
5+
import {setupNodesMock, setupSettingsMock} from './mocks';
6+
import {PaginatedTable} from './paginatedTable';
7+
8+
test.describe('PaginatedTable', () => {
9+
test('loads data in chunks when scrolling', async ({page}) => {
10+
// Setup mocks
11+
await setupNodesMock(page);
12+
await setupSettingsMock(page);
13+
14+
// Navigate to nodes page which uses PaginatedTable
15+
const nodesPage = new NodesPage(page);
16+
await nodesPage.goto();
17+
18+
const paginatedTable = new PaginatedTable(page);
19+
await paginatedTable.waitForTableVisible();
20+
await paginatedTable.waitForTableData();
21+
22+
// Get initial row count (should be first chunk)
23+
const initialVisibleRows = await paginatedTable.getRowCount();
24+
expect(initialVisibleRows).toBeGreaterThan(0);
25+
expect(initialVisibleRows).toBeLessThan(100); // Should not show all rows initially
26+
27+
// Get data from first visible row to verify initial chunk
28+
const firstRowData = await paginatedTable.getRowData(0);
29+
expect(firstRowData['Host']).toBe('host-0.test');
30+
expect(firstRowData['Version']).toBe('main.b7cfb36');
31+
32+
// Scroll to bottom of container
33+
await page.evaluate(() => {
34+
const container = document.querySelector('.ydb-cluster');
35+
if (container) {
36+
// Force scroll to bottom
37+
container.scrollTo({
38+
top: container.scrollHeight,
39+
behavior: 'instant',
40+
});
41+
}
42+
});
43+
44+
await paginatedTable.waitForTableData();
45+
46+
// Get data from last row to verify second chunk loaded
47+
const rowCount = await paginatedTable.getRowCount();
48+
const lastRowData = await paginatedTable.getRowData(rowCount - 1);
49+
expect(lastRowData['Host']).toBe('host-99.test');
50+
expect(lastRowData['Version']).toBe('main.b7cfb36');
51+
52+
// Verify uptime format matches the pattern from nodes.test.ts
53+
const uptimeValues = await paginatedTable.getColumnValues('Uptime');
54+
for (const uptime of uptimeValues) {
55+
expect(uptime).toMatch(/^(\d+d\s)?(\d+):(\d{2}):(\d{2})$/); // Format: DDd? HH:MM:SS
56+
}
57+
});
58+
});

0 commit comments

Comments
 (0)