Skip to content

Commit 848aea3

Browse files
committed
chore: tests
1 parent 2fd8ba2 commit 848aea3

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

tests/suites/bridge/bridge.test.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import {expect, test} from '@playwright/test';
2+
3+
import {backend, nodesPage} from '../../utils/constants';
4+
import {ClusterNodesTable, ClusterStorageTable} from '../paginatedTable/paginatedTable';
5+
import {StoragePage} from '../storage/StoragePage';
6+
7+
import {mockCapabilities, mockNodesWithPile, mockStorageGroupsWithPile} from './mocks';
8+
9+
test.describe('Bridge mode - Nodes table', () => {
10+
test('off: no Pile Name column and no group-by option', async ({page}) => {
11+
await mockCapabilities(page, false);
12+
await page.route(`${backend}/viewer/json/nodes?*`, (route) => route.continue());
13+
await page.goto(`/${nodesPage}`);
14+
const table = new ClusterNodesTable(page);
15+
await table.waitForTableToLoad();
16+
const headers = await table.getHeaders();
17+
expect(headers.join(' ')).not.toContain('Pile Name');
18+
// open columns setup and ensure Pile Name not present
19+
await table.getControls().openColumnSetup();
20+
expect(await table.getControls().isColumnVisible('PileName')).toBeFalsy();
21+
});
22+
23+
test('on: shows Pile Name column', async ({page}) => {
24+
await mockCapabilities(page, true);
25+
await mockNodesWithPile(page);
26+
await page.goto(`/${nodesPage}`);
27+
const table = new ClusterNodesTable(page);
28+
await table.waitForTableToLoad();
29+
const headers = await table.getHeaders();
30+
expect(headers.join(' ')).toContain('Pile Name');
31+
});
32+
});
33+
34+
test.describe('Bridge mode - Storage nodes', () => {
35+
test('on: shows Pile Name', async ({page}) => {
36+
await mockCapabilities(page, true);
37+
await mockNodesWithPile(page);
38+
const storage = new StoragePage(page);
39+
await storage.goto({visible: 'all'});
40+
const table = new ClusterStorageTable(page);
41+
await table.waitForTableToLoad();
42+
const headers = await table.getHeaders();
43+
expect(headers.join(' ')).toContain('Pile Name');
44+
});
45+
46+
test('off: hides Pile Name', async ({page}) => {
47+
await mockCapabilities(page, false);
48+
const storage = new StoragePage(page);
49+
await storage.goto({visible: 'all'});
50+
const table = new ClusterStorageTable(page);
51+
await table.waitForTableToLoad();
52+
const headers = await table.getHeaders();
53+
expect(headers.join(' ')).not.toContain('Pile Name');
54+
});
55+
});
56+
57+
test.describe('Bridge mode - Storage groups', () => {
58+
test('on: shows Pile Name and group-by option', async ({page}) => {
59+
await mockCapabilities(page, true);
60+
await mockStorageGroupsWithPile(page);
61+
const storage = new StoragePage(page);
62+
await storage.goto({visible: 'all', type: 'groups'});
63+
const table = new ClusterStorageTable(page);
64+
await table.waitForTableToLoad();
65+
const headers = await table.getHeaders();
66+
expect(headers.join(' ')).toContain('Pile Name');
67+
});
68+
69+
test('off: hides Pile Name and group-by option', async ({page}) => {
70+
await mockCapabilities(page, false);
71+
const storage = new StoragePage(page);
72+
await storage.goto({visible: 'all', type: 'groups'});
73+
const table = new ClusterStorageTable(page);
74+
await table.waitForTableToLoad();
75+
const headers = await table.getHeaders();
76+
expect(headers.join(' ')).not.toContain('Pile Name');
77+
});
78+
});

tests/suites/bridge/mocks.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import type {Page, Route} from '@playwright/test';
2+
3+
import {backend} from '../../utils/constants';
4+
5+
export const mockCapabilities = (page: Page, enabled: boolean) => {
6+
return page.route(`${backend}/viewer/json/capabilities?*`, async (route: Route) => {
7+
await route.fulfill({
8+
status: 200,
9+
contentType: 'application/json',
10+
body: JSON.stringify({Database: '/local', Capabilities: {BridgeModeEnabled: enabled}}),
11+
});
12+
});
13+
};
14+
15+
export const mockNodesWithPile = (page: Page) => {
16+
return page.route(`${backend}/viewer/json/nodes?*`, async (route: Route) => {
17+
await route.fulfill({
18+
status: 200,
19+
contentType: 'application/json',
20+
body: JSON.stringify({
21+
FoundNodes: 1,
22+
TotalNodes: 1,
23+
Nodes: [{NodeId: 1, SystemState: {}, PileName: 'r1'}],
24+
}),
25+
});
26+
});
27+
};
28+
29+
export const mockStorageGroupsWithPile = (page: Page) => {
30+
return page.route(`${backend}/storage/groups?*`, async (route: Route) => {
31+
await route.fulfill({
32+
status: 200,
33+
contentType: 'application/json',
34+
body: JSON.stringify({
35+
FoundGroups: 1,
36+
TotalGroups: 1,
37+
StorageGroups: [{GroupId: '1', PoolName: 'p', MediaType: 'NVME', PileName: 'r1'}],
38+
}),
39+
});
40+
});
41+
};

tests/suites/paginatedTable/paginatedTable.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ export class PaginatedTable {
127127
return this.controls;
128128
}
129129

130+
async getHeaders(): Promise<string[]> {
131+
return this.headCells.allTextContents();
132+
}
133+
130134
async waitForTableVisible() {
131135
await this.tableSelector.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT});
132136
}

0 commit comments

Comments
 (0)