diff --git a/src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx b/src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx index a83b61d99..17cc8c54f 100644 --- a/src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx +++ b/src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx @@ -198,7 +198,7 @@ function QueryEditor(props: QueryEditorProps) { const schema = useMultiSchema ? 'multi' : 'modern'; - const query = text && typeof text === 'string' ? text : input; + const query = text ?? input; setLastUsedQueryAction(QUERY_ACTIONS.execute); if (!isEqual(lastQueryExecutionSettings, querySettings)) { @@ -397,10 +397,10 @@ function QueryEditor(props: QueryEditorProps) { const renderControls = () => { return ( <QueryEditorControls - onRunButtonClick={handleSendExecuteClick} + handleSendExecuteClick={handleSendExecuteClick} onSettingsButtonClick={handleSettingsClick} runIsLoading={executeQueryResult.isLoading} - onExplainButtonClick={handleGetExplainQueryClick} + handleGetExplainQueryClick={handleGetExplainQueryClick} explainIsLoading={explainQueryResult.isLoading} disabled={!executeQuery.input} highlightedAction={lastUsedQueryAction} diff --git a/src/containers/Tenant/Query/QueryEditorControls/QueryEditorControls.tsx b/src/containers/Tenant/Query/QueryEditorControls/QueryEditorControls.tsx index 1105c1f4f..a8146465d 100644 --- a/src/containers/Tenant/Query/QueryEditorControls/QueryEditorControls.tsx +++ b/src/containers/Tenant/Query/QueryEditorControls/QueryEditorControls.tsx @@ -54,20 +54,20 @@ const SettingsButton = ({onClick, runIsLoading}: SettingsButtonProps) => { }; interface QueryEditorControlsProps { - onRunButtonClick: () => void; + handleSendExecuteClick: () => void; onSettingsButtonClick: () => void; runIsLoading: boolean; - onExplainButtonClick: () => void; + handleGetExplainQueryClick: () => void; explainIsLoading: boolean; disabled: boolean; highlightedAction: QueryAction; } export const QueryEditorControls = ({ - onRunButtonClick, + handleSendExecuteClick, onSettingsButtonClick, runIsLoading, - onExplainButtonClick, + handleGetExplainQueryClick, explainIsLoading, disabled, highlightedAction, @@ -76,6 +76,14 @@ export const QueryEditorControls = ({ const explainView: ButtonView | undefined = highlightedAction === 'explain' ? 'action' : undefined; + const onRunButtonClick = () => { + handleSendExecuteClick(); + }; + + const onExplainButtonClick = () => { + handleGetExplainQueryClick(); + }; + return ( <div className={b()}> <div className={b('left')}> diff --git a/tests/suites/tenant/queryHistory/queryHistory.test.ts b/tests/suites/tenant/queryHistory/queryHistory.test.ts new file mode 100644 index 000000000..db15bad13 --- /dev/null +++ b/tests/suites/tenant/queryHistory/queryHistory.test.ts @@ -0,0 +1,62 @@ +import {expect, test} from '@playwright/test'; + +import {tenantName} from '../../../utils/constants'; +import {TenantPage} from '../TenantPage'; +import {QueryEditor, QueryMode} from '../queryEditor/QueryEditor'; + +test.describe('Query History', () => { + let tenantPage: TenantPage; + let queryEditor: QueryEditor; + + test.beforeEach(async ({page}) => { + const pageQueryParams = { + schema: tenantName, + name: tenantName, + general: 'query', + }; + + tenantPage = new TenantPage(page); + await tenantPage.goto(pageQueryParams); + queryEditor = new QueryEditor(page); + }); + + test('New query appears in history after execution', async ({page}) => { + const testQuery = 'SELECT 1 AS test_column;'; + + // Execute the query + await queryEditor.run(testQuery, QueryMode.YQLScript); + + // Navigate to the history tab + await page.click('text=History'); + + // Check if the query appears in the history + const historyTable = page.locator('.ydb-queries-history table'); + await expect(historyTable.locator(`text="${testQuery}"`)).toBeVisible(); + }); + + test('Multiple queries appear in correct order in history', async ({page}) => { + const queries = [ + 'SELECT 1 AS first_query;', + 'SELECT 2 AS second_query;', + 'SELECT 3 AS third_query;', + ]; + + // Execute multiple queries + for (const query of queries) { + await queryEditor.run(query, QueryMode.YQLScript); + } + + // Navigate to the history tab + await page.click('text=History'); + + // Check if queries appear in reverse order (most recent first) + const historyTable = page.locator('.ydb-queries-history table'); + const rows = historyTable.locator('tbody tr'); + + await expect(rows).toHaveCount(queries.length); + + for (let i = 0; i < queries.length; i++) { + await expect(rows.nth(i)).toContainText(queries[queries.length - 1 - i]); + } + }); +});