Skip to content

fix: try no unsaved for templates #2117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/containers/Tenant/Query/QueryEditor/YqlEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export function YqlEditor({
editor.focus();
editor.setValue('');
contribution.insert(input);
dispatch(setIsDirty(false));
}
});

Expand Down
66 changes: 62 additions & 4 deletions tests/suites/tenant/queryEditor/queryTemplates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,20 @@ test.describe('Query Templates', () => {
}
});

test('Unsaved changes modal appears when switching between templates', async ({page}) => {
test('Unsaved changes modal appears when switching between templates if query was edited', async ({
page,
}) => {
const objectSummary = new ObjectSummary(page);
const unsavedChangesModal = new UnsavedChangesModal(page);
const queryEditor = new QueryEditor(page);

// First action - Add index
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.AddIndex);
await page.waitForTimeout(500);

// First set some content
await queryEditor.setQuery('SELECT 1;');

// Try to switch to Select query
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.SelectQuery);
await page.waitForTimeout(500);
Expand All @@ -107,8 +113,7 @@ test.describe('Query Templates', () => {
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.AddIndex);
await page.waitForTimeout(500);

// Store initial editor content
const initialContent = await queryEditor.editorTextArea.inputValue();
await queryEditor.setQuery('SELECT 1;');

// Try to switch to Select query
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.SelectQuery);
Expand All @@ -118,7 +123,7 @@ test.describe('Query Templates', () => {
await unsavedChangesModal.clickCancel();

// Verify editor content remains unchanged
await expect(queryEditor.editorTextArea).toHaveValue(initialContent);
await expect(queryEditor.editorTextArea).toHaveValue('SELECT 1;');
});

test('Dont save button in unsaved changes modal allows to change text', async ({page}) => {
Expand All @@ -130,6 +135,7 @@ test.describe('Query Templates', () => {
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.AddIndex);
await page.waitForTimeout(500);

await queryEditor.setQuery('SELECT 1;');
// Store initial editor content
const initialContent = await queryEditor.editorTextArea.inputValue();

Expand Down Expand Up @@ -157,6 +163,8 @@ test.describe('Query Templates', () => {
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.AddIndex);
await page.waitForTimeout(500);

await queryEditor.setQuery('SELECT 1;');

// Try to switch to Select query
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.SelectQuery);
await page.waitForTimeout(500);
Expand Down Expand Up @@ -214,4 +222,54 @@ test.describe('Query Templates', () => {
// Verify unsaved changes modal appears
await expect(unsavedChangesModal.isVisible()).resolves.toBe(true);
});
test('Switching between templates does not trigger unsaved changes modal', async ({page}) => {
const objectSummary = new ObjectSummary(page);
const tenantPage = new TenantPage(page);

// First select a template (Add Index)
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.AddIndex);
await page.waitForTimeout(500);

// Without editing the template, switch to another template (Select Query)
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.SelectQuery);
await page.waitForTimeout(500);

// Verify unsaved changes modal does not appear
const isModalHidden = await tenantPage.isUnsavedChangesModalHidden();
expect(isModalHidden).toBe(true);
});

test('Selecting a template and then opening history query does not trigger unsaved changes modal', async ({
page,
}) => {
const objectSummary = new ObjectSummary(page);
const queryEditor = new QueryEditor(page);
const tenantPage = new TenantPage(page);

// First, run a query to ensure we have history to select from
const testQuery = 'SELECT 1 AS test_column;';
await queryEditor.setQuery(testQuery);
await queryEditor.clickRunButton();
await page.waitForTimeout(1000); // Wait for the query to complete

// Next, select a template
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.AddIndex);
await page.waitForTimeout(500);

// Navigate to history tab
await queryEditor.queryTabs.selectTab(QueryTabs.History);
await queryEditor.historyQueries.isVisible();

// Select the query from history
await queryEditor.historyQueries.selectQuery(testQuery);
await page.waitForTimeout(500);

// Verify no unsaved changes modal appeared
const isModalHidden = await tenantPage.isUnsavedChangesModalHidden();
expect(isModalHidden).toBe(true);

// Verify the query was loaded into the editor
const editorValue = await queryEditor.editorTextArea.inputValue();
expect(editorValue.trim()).toBe(testQuery.trim());
});
});
4 changes: 0 additions & 4 deletions tests/suites/tenant/summary/objectSummary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from '../../../utils/constants';
import {TenantPage} from '../TenantPage';
import {QueryEditor} from '../queryEditor/models/QueryEditor';
import {UnsavedChangesModal} from '../queryEditor/models/UnsavedChangesModal';

import {ObjectSummary, ObjectSummaryTab} from './ObjectSummary';
import {RowTableAction} from './types';
Expand Down Expand Up @@ -140,7 +139,6 @@ test.describe('Object Summary', async () => {
test('Different tables show different column lists in Monaco editor', async ({page}) => {
const objectSummary = new ObjectSummary(page);
const queryEditor = new QueryEditor(page);
const unsavedChangesModal = new UnsavedChangesModal(page);

// Get columns for first table
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.SelectQuery);
Expand All @@ -153,8 +151,6 @@ test.describe('Object Summary', async () => {
);

await page.waitForTimeout(500);
// Click Don't save in the modal
await unsavedChangesModal.clickDontSave();

const storagePoolsColumns = await queryEditor.editorTextArea.inputValue();

Expand Down
Loading