Skip to content

Commit 922e758

Browse files
committed
chore: Run selected part of the query
1 parent 469ab9a commit 922e758

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed

tests/suites/tenant/queryEditor/models/QueryEditor.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,27 @@ export class QueryEditor {
144144
await this.editorTextArea.focus();
145145
}
146146

147+
async selectText(startLine: number, startColumn: number, endLine: number, endColumn: number) {
148+
await this.editorTextArea.evaluate(
149+
(_, coords) => {
150+
const editor = window.ydbEditor;
151+
if (editor) {
152+
editor.setSelection({
153+
startLineNumber: coords.startLine,
154+
startColumn: coords.startColumn,
155+
endLineNumber: coords.endLine,
156+
endColumn: coords.endColumn,
157+
});
158+
}
159+
},
160+
{startLine, startColumn, endLine, endColumn},
161+
);
162+
}
163+
164+
async pressKeys(key: string) {
165+
await this.editorTextArea.press(key);
166+
}
167+
147168
async closeSettingsDialog() {
148169
await this.settingsDialog.clickButton(ButtonNames.Cancel);
149170
}

tests/suites/tenant/queryEditor/models/ResultTable.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ export class ResultTable {
2424
private table: Locator;
2525
private preview: Locator;
2626
private resultHead: Locator;
27+
private resultWrapper: Locator;
2728

2829
constructor(selector: Locator) {
2930
this.table = selector.locator('.ydb-query-result-sets-viewer__result');
3031
this.preview = selector.locator('.kv-preview__result');
3132
this.resultHead = selector.locator('.ydb-query-result-sets-viewer__head');
33+
this.resultWrapper = selector.locator('.ydb-query-result-sets-viewer__result-wrapper');
3234
}
3335

3436
async isVisible() {
@@ -70,4 +72,34 @@ export class ResultTable {
7072
await this.resultHead.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT});
7173
return this.resultHead.innerText();
7274
}
75+
76+
async getResultTabs() {
77+
const tabs = this.resultWrapper.locator(
78+
'.ydb-query-result-sets-viewer__tabs .g-tabs__item',
79+
);
80+
await tabs.first().waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT});
81+
return tabs;
82+
}
83+
84+
async getResultTabsCount() {
85+
const tabs = await this.getResultTabs();
86+
return tabs.count();
87+
}
88+
89+
async getResultTabTitle(index: number) {
90+
const tabs = await this.getResultTabs();
91+
const tab = tabs.nth(index);
92+
await tab.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT});
93+
return tab.getAttribute('title');
94+
}
95+
96+
async hasMultipleResultTabs() {
97+
const tabs = this.resultWrapper.locator('.ydb-query-result-sets-viewer__tabs');
98+
try {
99+
await tabs.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT});
100+
return true;
101+
} catch {
102+
return false;
103+
}
104+
}
73105
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
QueryTabs,
1313
ResultTabNames,
1414
} from './models/QueryEditor';
15+
import {executeSelectedQueryWithKeybinding} from './utils';
1516

1617
test.describe('Test Query Editor', async () => {
1718
const testQuery = 'SELECT 1, 2, 3, 4, 5;';
@@ -241,4 +242,30 @@ test.describe('Test Query Editor', async () => {
241242

242243
await expect(queryEditor.waitForStatus('Completed')).resolves.toBe(true);
243244
});
245+
246+
test('Running selected query executes only selected part', async ({page}) => {
247+
const queryEditor = new QueryEditor(page);
248+
const multiQuery = 'SELECT 1;\nSELECT 2;';
249+
250+
// First verify running the entire query produces two results
251+
await queryEditor.setQuery(multiQuery);
252+
await queryEditor.clickRunButton();
253+
await expect(queryEditor.waitForStatus('Completed')).resolves.toBe(true);
254+
255+
// Verify there are two result tabs
256+
await expect(queryEditor.resultTable.getResultTabsCount()).resolves.toBe(2);
257+
await expect(queryEditor.resultTable.getResultTabTitle(0)).resolves.toBe('Result #1');
258+
await expect(queryEditor.resultTable.getResultTabTitle(1)).resolves.toBe('Result #2');
259+
260+
// Then verify running only selected part produces one result
261+
await queryEditor.focusEditor();
262+
await queryEditor.selectText(1, 1, 1, 9);
263+
264+
// Use keyboard shortcut to run selected query
265+
await executeSelectedQueryWithKeybinding(page);
266+
267+
await expect(queryEditor.waitForStatus('Completed')).resolves.toBe(true);
268+
await expect(queryEditor.resultTable.hasMultipleResultTabs()).resolves.toBe(false);
269+
await expect(queryEditor.resultTable.getResultHeadText()).resolves.toBe('Result(1)');
270+
});
244271
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type {Page} from '@playwright/test';
2+
3+
export const executeSelectedQueryWithKeybinding = async (page: Page) => {
4+
const isMac = process.platform === 'darwin';
5+
const browserName = page.context().browser()?.browserType().name() ?? 'chromium';
6+
const modifierKey = browserName === 'webkit' ? 'Meta' : 'Control';
7+
8+
if (browserName !== 'webkit' || isMac) {
9+
await page.keyboard.down(modifierKey);
10+
await page.keyboard.down('Shift');
11+
await page.keyboard.press('Enter');
12+
await page.keyboard.up('Shift');
13+
await page.keyboard.up(modifierKey);
14+
} else {
15+
await page.keyboard.press('Meta+Shift+Enter');
16+
}
17+
18+
// Add a small delay to ensure the event is processed
19+
await page.waitForTimeout(1000);
20+
};

0 commit comments

Comments
 (0)