Skip to content

Commit 67a7d8b

Browse files
Anton StandrikAnton Standrik
authored andcommitted
fix: add tests
1 parent cc91699 commit 67a7d8b

File tree

5 files changed

+102
-7
lines changed

5 files changed

+102
-7
lines changed

tests/suites/tenant/queryEditor/queryTemplates.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ test.describe('Query Templates', () => {
9191
await page.waitForTimeout(500);
9292

9393
// Try to switch to Select query
94-
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.DropTable);
94+
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.SelectQuery);
9595
await page.waitForTimeout(500);
9696

9797
// Verify unsaved changes modal appears
@@ -111,7 +111,7 @@ test.describe('Query Templates', () => {
111111
const initialContent = await queryEditor.editorTextArea.inputValue();
112112

113113
// Try to switch to Select query
114-
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.DropTable);
114+
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.SelectQuery);
115115
await page.waitForTimeout(500);
116116

117117
// Click Cancel in the modal
@@ -134,7 +134,7 @@ test.describe('Query Templates', () => {
134134
const initialContent = await queryEditor.editorTextArea.inputValue();
135135

136136
// Try to switch to Select query
137-
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.DropTable);
137+
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.SelectQuery);
138138
await page.waitForTimeout(500);
139139

140140
// Click Don't save in the modal
@@ -158,7 +158,7 @@ test.describe('Query Templates', () => {
158158
await page.waitForTimeout(500);
159159

160160
// Try to switch to Select query
161-
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.DropTable);
161+
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.SelectQuery);
162162
await page.waitForTimeout(500);
163163

164164
// Click Save query in the modal

tests/suites/tenant/summary/ActionsMenu.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class ActionsMenu {
2525
}
2626

2727
async clickItem(itemText: string): Promise<void> {
28-
const menuItem = this.menu.locator(`.g-menu__item-content:text("${itemText}")`);
28+
const menuItem = this.menu.locator(`.g-menu__item-content:has-text("${itemText}")`);
2929
await menuItem.click();
3030
}
3131

@@ -35,6 +35,13 @@ export class ActionsMenu {
3535
return className.includes('g-menu__item_selected');
3636
}
3737

38+
async isItemLoading(itemText: string): Promise<boolean> {
39+
const menuItem = this.menu.locator(`.g-menu__item:has-text("${itemText}")`);
40+
const className = (await menuItem.getAttribute('class')) || '';
41+
const hasSpinner = await menuItem.locator('.g-spin').isVisible();
42+
return className.includes('g-menu__item_disabled') && hasSpinner;
43+
}
44+
3845
async getTableTemplates(): Promise<RowTableAction[]> {
3946
const items = this.menu.locator('.g-menu__item-content');
4047
const contents = await items.allTextContents();

tests/suites/tenant/summary/ObjectSummary.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,18 @@ export class ObjectSummary {
8282
return this.actionsMenu.isVisible();
8383
}
8484

85+
async isActionItemLoading(itemText: string): Promise<boolean> {
86+
return this.actionsMenu.isItemLoading(itemText);
87+
}
88+
8589
async getActionsMenuItems(): Promise<string[]> {
8690
return this.actionsMenu.getItems();
8791
}
8892

8993
async clickActionsMenuItem(itemText: string): Promise<void> {
94+
if (await this.isActionItemLoading(itemText)) {
95+
await new Promise((resolve) => setTimeout(resolve, 1000));
96+
}
9097
await this.actionsMenu.clickItem(itemText);
9198
}
9299

@@ -107,6 +114,6 @@ export class ObjectSummary {
107114

108115
async clickActionMenuItem(treeItemText: string, menuItemText: string): Promise<void> {
109116
await this.clickActionsButton(treeItemText);
110-
await this.actionsMenu.clickItem(menuItemText);
117+
await this.clickActionsMenuItem(menuItemText);
111118
}
112119
}

tests/suites/tenant/summary/objectSummary.test.ts

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import {expect, test} from '@playwright/test';
22

3-
import {dsVslotsSchema, dsVslotsTableName, tenantName} from '../../../utils/constants';
3+
import {wait} from '../../../../src/utils';
4+
import {
5+
backend,
6+
dsStoragePoolsTableName,
7+
dsVslotsSchema,
8+
dsVslotsTableName,
9+
tenantName,
10+
} from '../../../utils/constants';
411
import {TenantPage} from '../TenantPage';
512
import {QueryEditor} from '../queryEditor/models/QueryEditor';
13+
import {UnsavedChangesModal} from '../queryEditor/models/UnsavedChangesModal';
614

715
import {ObjectSummary, ObjectSummaryTab} from './ObjectSummary';
816
import {RowTableAction} from './types';
@@ -81,4 +89,75 @@ test.describe('Object Summary', async () => {
8189
await expect(queryEditor.editorTextArea).toBeVisible();
8290
await expect(queryEditor.editorTextArea).not.toBeEmpty();
8391
});
92+
93+
test('Select and Upsert actions show loading state', async ({page}) => {
94+
await page.route(`${backend}/viewer/json/describe?*`, async (route) => {
95+
await wait(1000);
96+
await route.continue();
97+
});
98+
99+
const objectSummary = new ObjectSummary(page);
100+
await expect(objectSummary.isTreeVisible()).resolves.toBe(true);
101+
102+
// Open actions menu
103+
await objectSummary.clickActionsButton(dsStoragePoolsTableName);
104+
await expect(objectSummary.isActionsMenuVisible()).resolves.toBe(true);
105+
106+
// Verify loading states
107+
await expect(objectSummary.isActionItemLoading(RowTableAction.SelectQuery)).resolves.toBe(
108+
true,
109+
);
110+
await expect(objectSummary.isActionItemLoading(RowTableAction.UpsertQuery)).resolves.toBe(
111+
true,
112+
);
113+
});
114+
115+
test('Monaco editor shows column list after select query loading completes', async ({page}) => {
116+
const objectSummary = new ObjectSummary(page);
117+
const queryEditor = new QueryEditor(page);
118+
119+
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.SelectQuery);
120+
121+
const selectContent = await queryEditor.editorTextArea.inputValue();
122+
expect(selectContent).toContain('SELECT');
123+
expect(selectContent).toContain('FROM');
124+
expect(selectContent).toMatch(/`\w+`,\s*`\w+`/); // At least two backticked columns
125+
});
126+
127+
test('Monaco editor shows column list after upsert query loading completes', async ({page}) => {
128+
const objectSummary = new ObjectSummary(page);
129+
const queryEditor = new QueryEditor(page);
130+
131+
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.UpsertQuery);
132+
133+
const upsertContent = await queryEditor.editorTextArea.inputValue();
134+
expect(upsertContent).toContain('UPSERT INTO');
135+
expect(upsertContent).toContain('VALUES');
136+
expect(upsertContent).toMatch(/\(\s*`\w+`\s*(,\s*`\w+`\s*)*\)/); // Backticked columns in parentheses
137+
});
138+
139+
test('Different tables show different column lists in Monaco editor', async ({page}) => {
140+
const objectSummary = new ObjectSummary(page);
141+
const queryEditor = new QueryEditor(page);
142+
const unsavedChangesModal = new UnsavedChangesModal(page);
143+
144+
// Get columns for first table
145+
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.SelectQuery);
146+
const vslotsColumns = await queryEditor.editorTextArea.inputValue();
147+
148+
// Get columns for second table
149+
await objectSummary.clickActionMenuItem(
150+
dsStoragePoolsTableName,
151+
RowTableAction.SelectQuery,
152+
);
153+
154+
await page.waitForTimeout(500);
155+
// Click Don't save in the modal
156+
await unsavedChangesModal.clickDontSave();
157+
158+
const storagePoolsColumns = await queryEditor.editorTextArea.inputValue();
159+
160+
// Verify the column lists are different
161+
expect(vslotsColumns).not.toEqual(storagePoolsColumns);
162+
});
84163
});

tests/utils/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export const tenantPage = 'tenant';
1010
export const tenantName = '/local';
1111
export const dsVslotsSchema = '/local/.sys/ds_vslots';
1212
export const dsVslotsTableName = 'ds_vslots';
13+
export const dsStorageStatsTableName = 'ds_storage_stats';
14+
export const dsStoragePoolsTableName = 'ds_storage_pools';
1315

1416
// URLs
1517
export const backend = process.env.PLAYWRIGHT_APP_BACKEND || 'http://localhost:8765';

0 commit comments

Comments
 (0)