Skip to content

Commit

Permalink
fix(QueryHistory): query history not saving
Browse files Browse the repository at this point in the history
  • Loading branch information
astandrik committed Aug 2, 2024
1 parent cc51b20 commit 32de0f3
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,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)) {
Expand Down Expand Up @@ -312,10 +312,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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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')}>
Expand Down
4 changes: 4 additions & 0 deletions tests/suites/tenant/queryEditor/QueryEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ export class QueryEditor {
}
}

async focusEditor() {
await this.editorTextArea.focus();
}

async clickGearButton() {
await this.gearButton.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT});
await this.gearButton.click();
Expand Down
99 changes: 99 additions & 0 deletions tests/suites/tenant/queryHistory/queryHistory.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import {expect, test} from '@playwright/test';

import {tenantName} from '../../../utils/constants';
import {TenantPage} from '../TenantPage';
import {QueryEditor, QueryMode} from '../queryEditor/QueryEditor';

export const VISIBILITY_TIMEOUT = 5000;

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({
timeout: VISIBILITY_TIMEOUT,
});
});

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]);
}
});

test('Query executed with keybinding is saved in history', async ({page, browserName}) => {
const testQuery = 'SELECT 1 AS keybinding_test;';

// Focus on the query editor
await queryEditor.focusEditor();

// Type the query
await page.keyboard.type(testQuery);

// Use the keybinding to execute the query
if (browserName === 'chromium') {
// For Chromium, we need to press the keys separately
await page.keyboard.down('Control');
await page.keyboard.press('Enter');
await page.keyboard.up('Control');
} else {
// For other browsers, we can use the combined key press
await page.keyboard.press(
process.platform === 'darwin' ? 'Meta+Enter' : 'Control+Enter',
);
}

// Wait for the query to be executed
await page.waitForSelector('.ydb-query-execute-result__result');

// 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();
});
});

0 comments on commit 32de0f3

Please sign in to comment.