Skip to content

Commit

Permalink
[Cypress][Fix] Update saved search utilities (opensearch-project#9151)
Browse files Browse the repository at this point in the history
* update saved search
* minor refactor4 on setDatePickerDatesAndSearchIfRelevant

Signed-off-by: Justin Kim <[email protected]>

---------

Signed-off-by: Justin Kim <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
angle943 and opensearch-changeset-bot[bot] authored Jan 13, 2025
1 parent e1b12ab commit d7f82b1
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/9151.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
- Add tests for updating a saved search ([#9151](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9151))
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
verifyDiscoverPageState,
verifySavedSearchInAssetsPage,
postRequestSaveSearch,
updateSavedSearchAndSaveAndVerify,
} from './utils/saved_search';

export const runSavedSearchTests = () => {
Expand Down Expand Up @@ -98,6 +99,7 @@ export const runSavedSearchTests = () => {
if (startingLanguage !== config.language) return;

it(`should successfully load a saved search for ${config.testName} starting from ${startingLanguage}`, () => {
// using a POST request to create a saved search to load
postRequestSaveSearch(config);

cy.navigateToWorkSpaceSpecificPage({
Expand All @@ -120,6 +122,18 @@ export const runSavedSearchTests = () => {
verifyDiscoverPageState(config);
});
});

it(`should successfully update a saved search for ${config.testName}`, () => {
// using a POST request to create a saved search to load
postRequestSaveSearch(config);
updateSavedSearchAndSaveAndVerify(config, false);
});

it(`should successfully save a saved search as a new saved search for ${config.testName}`, () => {
// using a POST request to create a saved search to load
postRequestSaveSearch(config);
updateSavedSearchAndSaveAndVerify(config, true);
});
});
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,9 @@ export const generateAllTestConfigurations = () => {
* @param {QueryEnhancementLanguage} language - query language
*/
export const setDatePickerDatesAndSearchIfRelevant = (language) => {
if (language === QueryLanguages.SQL.name) {
return;
if (language !== QueryLanguages.SQL.name) {
cy.setTopNavDate(START_TIME, END_TIME);
}

cy.setTopNavDate(START_TIME, END_TIME);
};

/**
Expand Down Expand Up @@ -492,3 +490,45 @@ export const postRequestSaveSearch = (config) => {
});
});
};

/**
* Loads a saved search and updates it and verify that it is correct
* @param {SavedSearchTestConfig} config - the relevant config for the test case
* @param {boolean} saveAsNew - flag to determine whether to overwrite the saved search (false) or save as a new saved search (true)
*/
export const updateSavedSearchAndSaveAndVerify = (config, saveAsNew) => {
const saveName = config.saveName;

cy.navigateToWorkSpaceSpecificPage({
workspaceName: workspaceName,
page: 'discover',
isEnhancement: true,
});
cy.loadSaveSearch(saveName);

// Change the dataset type to use
const [newDataset, newDatasetType] =
config.datasetType === DatasetTypes.INDEX_PATTERN.name
? [INDEX_WITH_TIME_1, DatasetTypes.INDEXES.name]
: [INDEX_PATTERN_WITH_TIME, DatasetTypes.INDEX_PATTERN.name];
// If current language is PPL, update to OpenSearch SQL, else update to PPL
const newLanguage =
config.language === QueryLanguages.PPL.name ? QueryLanguages.SQL : QueryLanguages.PPL;
const newConfig = generateTestConfiguration(newDataset, newDatasetType, newLanguage);

cy.setDataset(newConfig.dataset, datasourceName, newConfig.datasetType);
cy.setQueryLanguage(newConfig.language);
setDatePickerDatesAndSearchIfRelevant(newConfig.language);
setSearchConfigurations({
...newConfig,
// only select field if previous config did not select it, because otherwise it is already selected
selectFields: !config.selectFields ? newConfig.selectFields : false,
});
cy.saveSearch(saveName, saveAsNew);

// Load updated saved search and verify
cy.getElementByTestId('discoverNewButton').click();
cy.loadSaveSearch(saveName, saveAsNew);
setDatePickerDatesAndSearchIfRelevant(newConfig.language);
verifyDiscoverPageState(newConfig);
};

0 comments on commit d7f82b1

Please sign in to comment.