Skip to content

Commit 434fcf1

Browse files
committed
chore: Can run query from history
1 parent ac8fa63 commit 434fcf1

File tree

3 files changed

+97
-22
lines changed

3 files changed

+97
-22
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import type {Locator, Page} from '@playwright/test';
2+
3+
import {VISIBILITY_TIMEOUT} from '../../TenantPage';
4+
5+
export class QueriesHistoryTable {
6+
private page: Page;
7+
private container: Locator;
8+
private searchInput: Locator;
9+
private table: Locator;
10+
11+
constructor(page: Page) {
12+
this.page = page;
13+
this.container = page.locator('.ydb-queries-history');
14+
this.searchInput = this.container.locator('.ydb-queries-history__search input');
15+
this.table = this.container.locator('.data-table');
16+
}
17+
18+
async search(text: string) {
19+
await this.searchInput.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT});
20+
await this.searchInput.fill(text);
21+
}
22+
23+
async getQueryRow(query: string) {
24+
return this.table.locator('.ydb-queries-history__table-row', {
25+
has: this.page.locator('.yql-highlighter', {hasText: query}),
26+
});
27+
}
28+
29+
async selectQuery(query: string) {
30+
const row = await this.getQueryRow(query);
31+
await row.click();
32+
}
33+
34+
async getQueryText(index: number) {
35+
const row = this.table.locator('.ydb-queries-history__table-row').nth(index);
36+
return row.locator('.yql-highlighter').innerText();
37+
}
38+
39+
async isVisible() {
40+
await this.container.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT});
41+
return true;
42+
}
43+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {Locator, Page} from '@playwright/test';
33
import type {QUERY_MODES} from '../../../../../src/utils/query';
44
import {VISIBILITY_TIMEOUT} from '../../TenantPage';
55

6+
import {QueriesHistoryTable} from './QueriesHistoryTable';
67
import {QueryTabsNavigation} from './QueryTabsNavigation';
78
import {PaneWrapper, ResultTable} from './ResultTable';
89
import {SavedQueriesTable} from './SavedQueriesTable';
@@ -41,6 +42,7 @@ export class QueryEditor {
4142
queryTabs: QueryTabsNavigation;
4243
resultTable: ResultTable;
4344
savedQueries: SavedQueriesTable;
45+
historyQueries: QueriesHistoryTable;
4446
editorTextArea: Locator;
4547

4648
private page: Page;
@@ -78,6 +80,7 @@ export class QueryEditor {
7880
this.paneWrapper = new PaneWrapper(page);
7981
this.queryTabs = new QueryTabsNavigation(page);
8082
this.savedQueries = new SavedQueriesTable(page);
83+
this.historyQueries = new QueriesHistoryTable(page);
8184
}
8285

8386
async run(query: string, mode: keyof typeof QUERY_MODES) {
@@ -197,6 +200,7 @@ export class QueryEditor {
197200

198201
async setQuery(query: string) {
199202
await this.editorTextArea.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT});
203+
await this.editorTextArea.clear();
200204
await this.editorTextArea.fill(query);
201205
}
202206

tests/suites/tenant/queryHistory/queryHistory.test.ts

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {expect, test} from '@playwright/test';
33
import {QUERY_MODES} from '../../../../src/utils/query';
44
import {tenantName} from '../../../utils/constants';
55
import {TenantPage, VISIBILITY_TIMEOUT} from '../TenantPage';
6-
import {QueryEditor} from '../queryEditor/models/QueryEditor';
6+
import {QueryEditor, QueryTabs} from '../queryEditor/models/QueryEditor';
7+
import {UnsavedChangesModal} from '../queryEditor/models/UnsavedChangesModal';
78

89
import executeQueryWithKeybinding from './utils';
910

@@ -23,23 +24,22 @@ test.describe('Query History', () => {
2324
queryEditor = new QueryEditor(page);
2425
});
2526

26-
test('New query appears in history after execution', async ({page}) => {
27+
test('New query appears in history after execution', async () => {
2728
const testQuery = 'SELECT 1 AS test_column;';
2829

2930
// Execute the query
3031
await queryEditor.run(testQuery, QUERY_MODES.script);
3132

32-
// Navigate to the history tab
33-
await page.click('text=History');
33+
// Navigate to the history tab using existing navigation method
34+
await queryEditor.queryTabs.selectTab(QueryTabs.History);
3435

3536
// Check if the query appears in the history
36-
const historyTable = page.locator('.ydb-queries-history table');
37-
await expect(historyTable.locator('.yql-highlighter', {hasText: testQuery})).toBeVisible({
38-
timeout: VISIBILITY_TIMEOUT,
39-
});
37+
await queryEditor.historyQueries.isVisible();
38+
const queryRow = await queryEditor.historyQueries.getQueryRow(testQuery);
39+
await expect(queryRow).toBeVisible({timeout: VISIBILITY_TIMEOUT});
4040
});
4141

42-
test('Multiple queries appear in correct order in history', async ({page}) => {
42+
test('Multiple queries appear in correct order in history', async () => {
4343
const queries = [
4444
'SELECT 1 AS first_query;',
4545
'SELECT 2 AS second_query;',
@@ -51,17 +51,19 @@ test.describe('Query History', () => {
5151
await queryEditor.run(query, QUERY_MODES.script);
5252
}
5353

54-
// Navigate to the history tab
55-
await page.click('text=History');
54+
// Navigate to the history tab using existing navigation method
55+
await queryEditor.queryTabs.selectTab(QueryTabs.History);
5656

5757
// Check if queries appear in reverse order (most recent first)
58-
const historyTable = page.locator('.ydb-queries-history table');
59-
const rows = historyTable.locator('tbody tr');
60-
61-
await expect(rows).toHaveCount(queries.length);
58+
await queryEditor.historyQueries.isVisible();
6259

6360
for (let i = 0; i < queries.length; i++) {
64-
await expect(rows.nth(i)).toContainText(queries[queries.length - 1 - i]);
61+
const queryRow = await queryEditor.historyQueries.getQueryRow(
62+
queries[queries.length - 1 - i],
63+
);
64+
await expect(queryRow).toBeVisible();
65+
const queryText = await queryEditor.historyQueries.getQueryText(i);
66+
expect(queryText).toContain(queries[queries.length - 1 - i]);
6567
}
6668
});
6769

@@ -77,14 +79,40 @@ test.describe('Query History', () => {
7779
// Use the keybinding to execute the query
7880
await executeQueryWithKeybinding(page, browserName);
7981

80-
// Wait for the query to be executed
81-
await page.waitForSelector('.ydb-query-result-sets-viewer__result', {timeout: 10000});
82+
// Wait for query results
83+
await queryEditor.resultTable.isVisible();
8284

83-
// Navigate to the history tab
84-
await page.click('text=History');
85+
// Navigate to the history tab using existing navigation method
86+
await queryEditor.queryTabs.selectTab(QueryTabs.History);
8587

8688
// Check if the query appears in the history
87-
const historyTable = page.locator('.ydb-queries-history table');
88-
await expect(historyTable.locator('.yql-highlighter', {hasText: testQuery})).toBeVisible();
89+
await queryEditor.historyQueries.isVisible();
90+
const queryRow = await queryEditor.historyQueries.getQueryRow(testQuery);
91+
await expect(queryRow).toBeVisible();
92+
});
93+
94+
test('Can run query from history', async ({page}) => {
95+
const testQuery = 'SELECT 42 AS history_run_test;';
96+
const unsavedChangesModal = new UnsavedChangesModal(page);
97+
98+
// Execute the query first time
99+
await queryEditor.run(testQuery, QUERY_MODES.script);
100+
101+
// Navigate to the history tab using existing navigation method
102+
await queryEditor.queryTabs.selectTab(QueryTabs.History);
103+
104+
// Select query from history to load it into editor
105+
await queryEditor.historyQueries.selectQuery(testQuery);
106+
107+
// Handle unsaved changes modal by clicking "Don't save"
108+
await unsavedChangesModal.clickDontSave();
109+
110+
// Run the query using the editor
111+
await queryEditor.clickRunButton();
112+
113+
// Verify query was executed by checking results
114+
await queryEditor.resultTable.isVisible();
115+
const value = await queryEditor.resultTable.getCellValue(1, 2);
116+
expect(value).toBe('42');
89117
});
90118
});

0 commit comments

Comments
 (0)