Skip to content

Commit c57d265

Browse files
[TEST] Reenable saved search test and convert it to use before and after (opensearch-project#9628)
* reenable saved search test and convert it to use before and after Signed-off-by: Justin Kim <jungkm@amazon.com> * Changeset file for PR opensearch-project#9628 created/updated * address pr comments Signed-off-by: Justin Kim <jungkm@amazon.com> --------- Signed-off-by: Justin Kim <jungkm@amazon.com> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
1 parent 8f57da4 commit c57d265

File tree

6 files changed

+129
-12
lines changed

6 files changed

+129
-12
lines changed

changelogs/fragments/9628.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test:
2+
- Reenable saved search cypress tests ([#9628](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9628))

cypress/integration/core_opensearch_dashboards/opensearch_dashboards/apps/query_enhancements/01/saved_search.spec.js

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ const workspaceName = getRandomizedWorkspaceName();
2828

2929
const runSavedSearchTests = () => {
3030
describe('saved search', () => {
31-
// TODO: Currently we cannot convert this into a "before" and "after" due to us grabbing several aliases that are required by postRequestSaveSearch()
32-
beforeEach(() => {
31+
before(() => {
3332
cy.osd.setupWorkspaceAndDataSourceWithIndices(workspaceName, [
3433
INDEX_WITH_TIME_1,
3534
INDEX_WITH_TIME_2,
@@ -41,10 +40,9 @@ const runSavedSearchTests = () => {
4140
dataSource: DATASOURCE_NAME,
4241
isEnhancement: true,
4342
});
44-
cy.osd.grabDataSourceId(workspaceName, DATASOURCE_NAME);
4543
});
4644

47-
afterEach(() => {
45+
after(() => {
4846
cy.osd.cleanupWorkspaceAndDataSourceAndIndices(workspaceName, [
4947
INDEX_WITH_TIME_1,
5048
INDEX_WITH_TIME_2,
@@ -60,6 +58,7 @@ const runSavedSearchTests = () => {
6058
});
6159

6260
cy.setDataset(config.dataset, DATASOURCE_NAME, config.datasetType);
61+
cy.osd.grabIdsFromDiscoverPageUrl();
6362

6463
cy.setQueryLanguage(config.language);
6564
setDatePickerDatesAndSearchIfRelevant(config.language);
@@ -86,18 +85,48 @@ const runSavedSearchTests = () => {
8685
cy.loadSaveSearch(config.saveName);
8786
setDatePickerDatesAndSearchIfRelevant(config.language);
8887
verifyDiscoverPageState(config);
88+
89+
cy.get('@WORKSPACE_ID').then((workspaceId) => {
90+
cy.osd.deleteSavedObjectsByType(workspaceId, 'search');
91+
});
8992
});
9093

91-
it.skip(`should successfully update a saved search for ${config.testName}`, () => {
94+
it(`should successfully update a saved search for ${config.testName}`, () => {
95+
cy.osd.navigateToWorkSpaceSpecificPage({
96+
workspaceName,
97+
page: 'discover',
98+
isEnhancement: true,
99+
});
100+
101+
cy.setDataset(config.dataset, DATASOURCE_NAME, config.datasetType);
102+
cy.osd.grabIdsFromDiscoverPageUrl();
103+
92104
// using a POST request to create a saved search to load
93105
postRequestSaveSearch(config);
94106
updateSavedSearchAndSaveAndVerify(config, workspaceName, DATASOURCE_NAME, false);
107+
108+
cy.get('@WORKSPACE_ID').then((workspaceId) => {
109+
cy.osd.deleteSavedObjectsByType(workspaceId, 'search');
110+
});
95111
});
96112

97-
it.skip(`should successfully save a saved search as a new saved search for ${config.testName}`, () => {
113+
it(`should successfully save a saved search as a new saved search for ${config.testName}`, () => {
114+
cy.osd.navigateToWorkSpaceSpecificPage({
115+
workspaceName,
116+
page: 'discover',
117+
isEnhancement: true,
118+
});
119+
120+
cy.setDataset(config.dataset, DATASOURCE_NAME, config.datasetType);
121+
cy.osd.grabIdsFromDiscoverPageUrl();
122+
98123
// using a POST request to create a saved search to load
99124
postRequestSaveSearch(config);
100125
updateSavedSearchAndSaveAndVerify(config, workspaceName, DATASOURCE_NAME, true);
126+
127+
cy.get('@WORKSPACE_ID').then((workspaceId) => {
128+
cy.osd.deleteSavedObjectsByType(workspaceId, 'search');
129+
});
101130
});
102131
});
103132
});

cypress/utils/apps/query_enhancements/commands.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ Cypress.Commands.add('setQueryEditor', (value, options = {}) => {
101101
.should('be.visible')
102102
.wait(200)
103103
.type(escape ? `${value}{esc}` : value, {
104+
delay: 40,
104105
force: true,
105106
...typeOptions, // Pass through all other options to type command
106107
});

cypress/utils/apps/query_enhancements/saved.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,6 @@ export const updateSavedSearchAndSaveAndVerify = (
509509
datasourceName,
510510
saveAsNew
511511
) => {
512-
cy.osd.navigateToWorkSpaceSpecificPage({
513-
workspaceName: workspaceName,
514-
page: 'discover',
515-
isEnhancement: true,
516-
});
517512
cy.loadSaveSearch(config.saveName);
518513

519514
// Change the dataset type to use
@@ -540,7 +535,8 @@ export const updateSavedSearchAndSaveAndVerify = (
540535
// Load updated saved search and verify
541536
cy.getElementByTestId('discoverNewButton').click();
542537
// wait for the new tab to load
543-
cy.getElementByTestId('docTableHeader').should('be.visible');
538+
cy.getElementByTestId('loadingSpinnerText').should('not.exist');
539+
544540
cy.loadSaveSearch(saveNameToUse);
545541
setDatePickerDatesAndSearchIfRelevant(newConfig.language);
546542
verifyDiscoverPageState(newConfig);

cypress/utils/commands.osd.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,57 @@ cy.osd.add('grabDataSourceId', (workspaceName, dataSourceName) => {
291291
}
292292
});
293293

294+
cy.osd.add('grabIdsFromDiscoverPageUrl', () => {
295+
cy.url().then(($url) => {
296+
const workspaceIdMatch = $url.match(/\/w\/([^\/]+)\//);
297+
const datasourceIdMatch = $url.match(/dataSource:\(id:'?([0-9a-f-]+)'?,/);
298+
const indexPatternIdMatch = $url.match(/\),id:'?([0-9A-Za-z:_-]+)'?,/);
299+
300+
if (workspaceIdMatch && workspaceIdMatch[1]) {
301+
cy.wrap(workspaceIdMatch[1]).as('WORKSPACE_ID');
302+
}
303+
if (datasourceIdMatch && datasourceIdMatch[1]) {
304+
cy.wrap(datasourceIdMatch[1]).as('DATASOURCE_ID');
305+
}
306+
if (indexPatternIdMatch && indexPatternIdMatch[1]) {
307+
cy.wrap(indexPatternIdMatch[1]).as('INDEX_PATTERN_ID');
308+
}
309+
});
310+
});
311+
312+
cy.osd.add('deleteSavedObject', (type, id, options = {}) => {
313+
const url = `/api/saved_objects/${type}/${id}?force=true`;
314+
315+
cy.request({
316+
method: 'DELETE',
317+
url,
318+
headers: {
319+
'osd-xsrf': true,
320+
},
321+
failOnStatusCode: false,
322+
...options,
323+
});
324+
});
325+
326+
cy.osd.add('deleteSavedObjectsByType', (workspaceId, type, search) => {
327+
const searchParams = new URLSearchParams({
328+
fields: 'id',
329+
type,
330+
workspaces: workspaceId,
331+
});
332+
if (search) {
333+
searchParams.set('search', search);
334+
}
335+
336+
const url = `/api/opensearch-dashboards/management/saved_objects/_find?${searchParams.toString()}`;
337+
338+
return cy.request(url).then((response) => {
339+
response.body.saved_objects.map(({ id }) => {
340+
cy.osd.deleteSavedObject(type, id);
341+
});
342+
});
343+
});
344+
294345
cy.osd.add('deleteAllOldWorkspaces', () => {
295346
cy.visit('/app/workspace_list#/');
296347
cy.get('h1').contains('Workspaces').should('be.visible');

cypress/utils/index.d.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44
*/
55

66
declare namespace Cypress {
7+
type SavedObjectsType =
8+
| 'config'
9+
| 'url'
10+
| 'data-connection'
11+
| 'index-pattern'
12+
| 'query'
13+
| 'homepage'
14+
| 'dashboard'
15+
| 'visualization'
16+
| 'visualization-visbuilder'
17+
| 'augment-vis'
18+
| 'search';
19+
720
interface Chainable<Subject> {
821
/**
922
* Get an element by its test id
@@ -154,6 +167,31 @@ declare namespace Cypress {
154167
*/
155168
grabDataSourceId(workspaceName: string, dataSourceName: string): Chainable<any>;
156169

170+
/**
171+
* Grabs Workspace ID, dataSourceId, and indexPattern id from the URL of discover page
172+
* Sets it in the alias @DATASOURCE_ID, @WORKSPACE_ID, @DATASOURCE_ID
173+
*/
174+
grabIdsFromDiscoverPageUrl(): Chainable<any>;
175+
176+
/**
177+
* Makes an API call to delete specified saved object
178+
*/
179+
deleteSavedObject(
180+
type: SavedObjectsType,
181+
id: string,
182+
options?: Record<string, any>
183+
): Chainable<any>;
184+
185+
/**
186+
* Deletes all saved objects by type and an optional search param for a given workspace.
187+
* If search param is not provided, it will delete all saved objects by that type.
188+
*/
189+
deleteSavedObjectsByType(
190+
workspaceId: string,
191+
type: SavedObjectsType,
192+
search?: string
193+
): Chainable<any>;
194+
157195
/**
158196
* Deletes all workspaces that are older than a specified amount. This is to prevent ws buildup
159197
*/

0 commit comments

Comments
 (0)