Skip to content

Commit e7d4a50

Browse files
authored
fix: try no unsaved for templates (#2117)
1 parent 2e6051b commit e7d4a50

File tree

3 files changed

+63
-8
lines changed

3 files changed

+63
-8
lines changed

src/containers/Tenant/Query/QueryEditor/YqlEditor.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export function YqlEditor({
9999
editor.focus();
100100
editor.setValue('');
101101
contribution.insert(input);
102+
dispatch(setIsDirty(false));
102103
}
103104
});
104105

tests/suites/tenant/queryEditor/queryTemplates.test.ts

+62-4
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,20 @@ test.describe('Query Templates', () => {
8282
}
8383
});
8484

85-
test('Unsaved changes modal appears when switching between templates', async ({page}) => {
85+
test('Unsaved changes modal appears when switching between templates if query was edited', async ({
86+
page,
87+
}) => {
8688
const objectSummary = new ObjectSummary(page);
8789
const unsavedChangesModal = new UnsavedChangesModal(page);
90+
const queryEditor = new QueryEditor(page);
8891

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

96+
// First set some content
97+
await queryEditor.setQuery('SELECT 1;');
98+
9399
// Try to switch to Select query
94100
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.SelectQuery);
95101
await page.waitForTimeout(500);
@@ -107,8 +113,7 @@ test.describe('Query Templates', () => {
107113
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.AddIndex);
108114
await page.waitForTimeout(500);
109115

110-
// Store initial editor content
111-
const initialContent = await queryEditor.editorTextArea.inputValue();
116+
await queryEditor.setQuery('SELECT 1;');
112117

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

120125
// Verify editor content remains unchanged
121-
await expect(queryEditor.editorTextArea).toHaveValue(initialContent);
126+
await expect(queryEditor.editorTextArea).toHaveValue('SELECT 1;');
122127
});
123128

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

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

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

166+
await queryEditor.setQuery('SELECT 1;');
167+
160168
// Try to switch to Select query
161169
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.SelectQuery);
162170
await page.waitForTimeout(500);
@@ -214,4 +222,54 @@ test.describe('Query Templates', () => {
214222
// Verify unsaved changes modal appears
215223
await expect(unsavedChangesModal.isVisible()).resolves.toBe(true);
216224
});
225+
test('Switching between templates does not trigger unsaved changes modal', async ({page}) => {
226+
const objectSummary = new ObjectSummary(page);
227+
const tenantPage = new TenantPage(page);
228+
229+
// First select a template (Add Index)
230+
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.AddIndex);
231+
await page.waitForTimeout(500);
232+
233+
// Without editing the template, switch to another template (Select Query)
234+
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.SelectQuery);
235+
await page.waitForTimeout(500);
236+
237+
// Verify unsaved changes modal does not appear
238+
const isModalHidden = await tenantPage.isUnsavedChangesModalHidden();
239+
expect(isModalHidden).toBe(true);
240+
});
241+
242+
test('Selecting a template and then opening history query does not trigger unsaved changes modal', async ({
243+
page,
244+
}) => {
245+
const objectSummary = new ObjectSummary(page);
246+
const queryEditor = new QueryEditor(page);
247+
const tenantPage = new TenantPage(page);
248+
249+
// First, run a query to ensure we have history to select from
250+
const testQuery = 'SELECT 1 AS test_column;';
251+
await queryEditor.setQuery(testQuery);
252+
await queryEditor.clickRunButton();
253+
await page.waitForTimeout(1000); // Wait for the query to complete
254+
255+
// Next, select a template
256+
await objectSummary.clickActionMenuItem(dsVslotsTableName, RowTableAction.AddIndex);
257+
await page.waitForTimeout(500);
258+
259+
// Navigate to history tab
260+
await queryEditor.queryTabs.selectTab(QueryTabs.History);
261+
await queryEditor.historyQueries.isVisible();
262+
263+
// Select the query from history
264+
await queryEditor.historyQueries.selectQuery(testQuery);
265+
await page.waitForTimeout(500);
266+
267+
// Verify no unsaved changes modal appeared
268+
const isModalHidden = await tenantPage.isUnsavedChangesModalHidden();
269+
expect(isModalHidden).toBe(true);
270+
271+
// Verify the query was loaded into the editor
272+
const editorValue = await queryEditor.editorTextArea.inputValue();
273+
expect(editorValue.trim()).toBe(testQuery.trim());
274+
});
217275
});

tests/suites/tenant/summary/objectSummary.test.ts

-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
} from '../../../utils/constants';
1212
import {TenantPage} from '../TenantPage';
1313
import {QueryEditor} from '../queryEditor/models/QueryEditor';
14-
import {UnsavedChangesModal} from '../queryEditor/models/UnsavedChangesModal';
1514

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

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

155153
await page.waitForTimeout(500);
156-
// Click Don't save in the modal
157-
await unsavedChangesModal.clickDontSave();
158154

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

0 commit comments

Comments
 (0)