|
| 1 | +import {expect, test} from '@playwright/test'; |
| 2 | + |
| 3 | +import {tenantName} from '../../../utils/constants'; |
| 4 | +import {TenantPage} from '../TenantPage'; |
| 5 | +import {QueryEditor, QueryMode} from '../queryEditor/QueryEditor'; |
| 6 | + |
| 7 | +import executeQueryWithKeybinding from './utils'; |
| 8 | + |
| 9 | +export const VISIBILITY_TIMEOUT = 5000; |
| 10 | + |
| 11 | +test.describe('Query History', () => { |
| 12 | + let tenantPage: TenantPage; |
| 13 | + let queryEditor: QueryEditor; |
| 14 | + |
| 15 | + test.beforeEach(async ({page}) => { |
| 16 | + const pageQueryParams = { |
| 17 | + schema: tenantName, |
| 18 | + name: tenantName, |
| 19 | + general: 'query', |
| 20 | + }; |
| 21 | + |
| 22 | + tenantPage = new TenantPage(page); |
| 23 | + await tenantPage.goto(pageQueryParams); |
| 24 | + queryEditor = new QueryEditor(page); |
| 25 | + }); |
| 26 | + |
| 27 | + test('New query appears in history after execution', async ({page}) => { |
| 28 | + const testQuery = 'SELECT 1 AS test_column;'; |
| 29 | + |
| 30 | + // Execute the query |
| 31 | + await queryEditor.run(testQuery, QueryMode.YQLScript); |
| 32 | + |
| 33 | + // Navigate to the history tab |
| 34 | + await page.click('text=History'); |
| 35 | + |
| 36 | + // Check if the query appears in the history |
| 37 | + const historyTable = page.locator('.ydb-queries-history table'); |
| 38 | + await expect(historyTable.locator(`text="${testQuery}"`)).toBeVisible({ |
| 39 | + timeout: VISIBILITY_TIMEOUT, |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + test('Multiple queries appear in correct order in history', async ({page}) => { |
| 44 | + const queries = [ |
| 45 | + 'SELECT 1 AS first_query;', |
| 46 | + 'SELECT 2 AS second_query;', |
| 47 | + 'SELECT 3 AS third_query;', |
| 48 | + ]; |
| 49 | + |
| 50 | + // Execute multiple queries |
| 51 | + for (const query of queries) { |
| 52 | + await queryEditor.run(query, QueryMode.YQLScript); |
| 53 | + } |
| 54 | + |
| 55 | + // Navigate to the history tab |
| 56 | + await page.click('text=History'); |
| 57 | + |
| 58 | + // Check if queries appear in reverse order (most recent first) |
| 59 | + const historyTable = page.locator('.ydb-queries-history table'); |
| 60 | + const rows = historyTable.locator('tbody tr'); |
| 61 | + |
| 62 | + await expect(rows).toHaveCount(queries.length); |
| 63 | + |
| 64 | + for (let i = 0; i < queries.length; i++) { |
| 65 | + await expect(rows.nth(i)).toContainText(queries[queries.length - 1 - i]); |
| 66 | + } |
| 67 | + }); |
| 68 | + |
| 69 | + test('Query executed with keybinding is saved in history', async ({page, browserName}) => { |
| 70 | + const testQuery = 'SELECT 1 AS keybinding_test;'; |
| 71 | + |
| 72 | + // Focus on the query editor |
| 73 | + await queryEditor.focusEditor(); |
| 74 | + |
| 75 | + // Type the query |
| 76 | + await page.keyboard.type(testQuery); |
| 77 | + |
| 78 | + // Use the keybinding to execute the query |
| 79 | + await executeQueryWithKeybinding(page, browserName); |
| 80 | + |
| 81 | + // Wait for the query to be executed |
| 82 | + await page.waitForSelector('.ydb-query-execute-result__result', {timeout: 10000}); |
| 83 | + |
| 84 | + // Navigate to the history tab |
| 85 | + await page.click('text=History'); |
| 86 | + |
| 87 | + // Check if the query appears in the history |
| 88 | + const historyTable = page.locator('.ydb-queries-history table'); |
| 89 | + await expect(historyTable.locator(`text="${testQuery}"`)).toBeVisible(); |
| 90 | + }); |
| 91 | +}); |
0 commit comments