Skip to content

Commit

Permalink
[Discover 2.0 Testing] Create View List of Saved Queries Test (Test-I…
Browse files Browse the repository at this point in the history
…d 124: View list of Saved query) (opensearch-project#9166)

* add spec for old ui

Signed-off-by: Argus Li <[email protected]>

* Add comment about cleaning up saved queries

Signed-off-by: Argus Li <[email protected]>

* Add data-test-subj for save query new ui

Signed-off-by: Argus Li <[email protected]>

* Add data-test-subj for save query button for new ui

Signed-off-by: Argus Li <[email protected]>

* Add data-test-subj for open query button in query management popover

Signed-off-by: Argus Li <[email protected]>

* Add new ui spec to test list saved queries

Signed-off-by: Argus Li <[email protected]>

* Fix DataSource url

Signed-off-by: Argus Li <[email protected]>

* Changeset file for PR opensearch-project#9166 created/updated

* Address Justin's comments.

Signed-off-by: Argus Li <[email protected]>

* Remove final force.

Signed-off-by: Argus Li <[email protected]>

* Fix final force.

Signed-off-by: Argus Li <[email protected]>

* Move utils to Suchit's suggested location, fix comments

Signed-off-by: Argus Li <[email protected]>

* Rename specs, change cypress workflow to use new save query ui, merge old ui and new ui commands

Signed-off-by: Argus Li <[email protected]>

* fix import

Signed-off-by: Argus Li <[email protected]>

---------

Signed-off-by: Argus Li <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
ArgusLi and opensearch-changeset-bot[bot] authored Jan 16, 2025
1 parent 5a290a4 commit 33f7ba6
Show file tree
Hide file tree
Showing 12 changed files with 433 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cypress_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
options: --user 1001
env:
START_CMD: ${{ matrix.config == 'query_enhanced' &&
'node scripts/opensearch_dashboards --dev --no-base-path --no-watch --savedObjects.maxImportPayloadBytes=10485760 --server.maxPayloadBytes=1759977 --logging.json=false --data.search.aggs.shardDelay.enabled=true --csp.warnLegacyBrowsers=false --uiSettings.overrides["query:enhancements:enabled"]=true --uiSettings.overrides[''home:useNewHomePage'']=true --data_source.enabled=true --workspace.enabled=true --opensearch.ignoreVersionMismatch=true' ||
'node scripts/opensearch_dashboards --dev --no-base-path --no-watch --savedObjects.maxImportPayloadBytes=10485760 --server.maxPayloadBytes=1759977 --logging.json=false --data.search.aggs.shardDelay.enabled=true --csp.warnLegacyBrowsers=false --uiSettings.overrides["query:enhancements:enabled"]=true --uiSettings.overrides[''home:useNewHomePage'']=true --data_source.enabled=true --workspace.enabled=true --opensearch.ignoreVersionMismatch=true --data.savedQueriesNewUI.enabled=true' ||
matrix.config == 'dashboard' &&
'node scripts/opensearch_dashboards --dev --no-base-path --no-watch --savedObjects.maxImportPayloadBytes=10485760 --server.maxPayloadBytes=1759977 --logging.json=false --data.search.aggs.shardDelay.enabled=true' ||
'node ../scripts/opensearch_dashboards --dev --no-base-path --no-watch --savedObjects.maxImportPayloadBytes=10485760 --server.maxPayloadBytes=1759977 --logging.json=false --data.search.aggs.shardDelay.enabled=true --csp.warnLegacyBrowsers=false --uiSettings.overrides["query:enhancements:enabled"]=false' }}
Expand Down
2 changes: 2 additions & 0 deletions changelogs/fragments/9166.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
- Add cypress integration test for the old and new UI view saved queries. ([#9166](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9166))
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
END_TIME,
DATASET_CONFIGS,
} from '../../../../../utils/apps/constants';
import * as dataExplorer from '../../../../../integration/core-opensearch-dashboards/opensearch-dashboards/apps/query_enhancements/utils/field_display_filtering.js';
import * as dataExplorer from '../../../../../utils/apps/query_enhancements/field_display_filtering.js';
import { SECONDARY_ENGINE, BASE_PATH } from '../../../../../utils/constants';
import { NEW_SEARCH_BUTTON } from '../../../../../utils/dashboards/data_explorer/elements.js';

Expand Down Expand Up @@ -223,7 +223,7 @@ describe('filter for value spec', () => {
});

after(() => {
cy.deleteWorkspaceByName(`${WORKSPACE_NAME}`);
cy.deleteWorkspaceByName(`${workspace}`);
cy.deleteDataSourceByName(`${DATASOURCE_NAME}`);
// TODO: Modify deleteIndex to handle an array of index and remove hard code
cy.deleteIndex(INDEX_PATTERN_NAME);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import {
INDEX_PATTERN_WITH_TIME,
INDEX_WITH_TIME_1,
INDEX_WITH_TIME_2,
SECONDARY_ENGINE,
} from '../../../../../utils/constants';

import {
workspaceName,
datasourceName,
setSearchConfigurations,
setDatePickerDatesAndSearchIfRelevant,
verifyDiscoverPageState,
} from '../../../../../utils/apps/query_enhancements/saved_search';

import { generateAllTestConfigurations } from '../../../../../utils/apps/query_enhancements/saved_queries';

// This spec assumes data.savedQueriesNewUI.enabled is true.

export const runSavedQueriesFlyoutUITests = () => {
describe('saved queries flyout UI', () => {
before(() => {
// Load test data
cy.setupTestData(
SECONDARY_ENGINE.url,
[
`cypress/fixtures/query_enhancements/data-logs-1/${INDEX_WITH_TIME_1}.mapping.json`,
`cypress/fixtures/query_enhancements/data-logs-2/${INDEX_WITH_TIME_2}.mapping.json`,
],
[
`cypress/fixtures/query_enhancements/data-logs-1/${INDEX_WITH_TIME_1}.data.ndjson`,
`cypress/fixtures/query_enhancements/data-logs-2/${INDEX_WITH_TIME_2}.data.ndjson`,
]
);
// Add data source
cy.addDataSource({
name: datasourceName,
url: SECONDARY_ENGINE.url,
authType: 'no_auth',
});

// Create workspace
cy.deleteWorkspaceByName(workspaceName);
cy.visit('/app/home');
cy.createInitialWorkspaceWithDataSource(datasourceName, workspaceName);
cy.createWorkspaceIndexPatterns({
workspaceName: workspaceName,
indexPattern: INDEX_PATTERN_WITH_TIME.replace('*', ''),
timefieldName: 'timestamp',
dataSource: datasourceName,
isEnhancement: true,
});
});

after(() => {
// No need to explicitly delete all saved queries as deleting the workspace will delete associated saved queries
cy.deleteWorkspaceByName(workspaceName);
// // TODO: Modify deleteIndex to handle an array of index and remove hard code
cy.deleteDataSourceByName(datasourceName);
cy.deleteIndex(INDEX_WITH_TIME_1);
cy.deleteIndex(INDEX_WITH_TIME_2);
});

const testConfigurations = generateAllTestConfigurations();
testConfigurations.forEach((config) => {
it(`should successfully create a saved query for ${config.testName}`, () => {
cy.navigateToWorkSpaceSpecificPage({
workspaceName,
page: 'discover',
isEnhancement: true,
});

cy.setDataset(config.dataset, datasourceName, config.datasetType);

cy.setQueryLanguage(config.language);
setDatePickerDatesAndSearchIfRelevant(config.language);

setSearchConfigurations(config);
verifyDiscoverPageState(config);
cy.saveQuery(config.saveName);
});
});

it('should see all saved queries', () => {
cy.getElementByTestId('saved-query-management-popover-button').click();

cy.getElementByTestId('saved-query-management-open-button').click();

testConfigurations.forEach((config) => {
cy.getElementByTestId('euiFlyoutCloseButton')
.parent()
.contains(config.saveName)
.should('exist');
});
});
});
};

runSavedQueriesFlyoutUITests();
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import {
INDEX_PATTERN_WITH_TIME,
INDEX_WITH_TIME_1,
INDEX_WITH_TIME_2,
SECONDARY_ENGINE,
} from '../../../../../utils/constants';

import {
workspaceName,
datasourceName,
setSearchConfigurations,
setDatePickerDatesAndSearchIfRelevant,
verifyDiscoverPageState,
} from '../../../../../utils/apps/query_enhancements/saved_search';

import { generateAllTestConfigurations } from '../../../../../utils/apps/query_enhancements/saved_queries';

// This spec assumes data.savedQueriesNewUI.enabled is false.
// These tests will not be run until the older legacy tests are migrated https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9166#discussion_r1913687440

export const runSavedQueriesPopoverUITests = () => {
describe.skip('saved queries popover UI', () => {
before(() => {
// Load test data
cy.setupTestData(
SECONDARY_ENGINE.url,
[
`cypress/fixtures/query_enhancements/data-logs-1/${INDEX_WITH_TIME_1}.mapping.json`,
`cypress/fixtures/query_enhancements/data-logs-2/${INDEX_WITH_TIME_2}.mapping.json`,
],
[
`cypress/fixtures/query_enhancements/data-logs-1/${INDEX_WITH_TIME_1}.data.ndjson`,
`cypress/fixtures/query_enhancements/data-logs-2/${INDEX_WITH_TIME_2}.data.ndjson`,
]
);
// Add data source
cy.addDataSource({
name: datasourceName,
url: SECONDARY_ENGINE.url,
authType: 'no_auth',
});

// Create workspace
cy.deleteWorkspaceByName(workspaceName);
cy.visit('/app/home');
cy.createInitialWorkspaceWithDataSource(datasourceName, workspaceName);
cy.createWorkspaceIndexPatterns({
workspaceName: workspaceName,
indexPattern: INDEX_PATTERN_WITH_TIME.replace('*', ''),
timefieldName: 'timestamp',
dataSource: datasourceName,
isEnhancement: true,
});
});

after(() => {
// No need to explicitly delete all saved queries as deleting the workspace will delete associated saved queries
cy.deleteWorkspaceByName(workspaceName);
// // TODO: Modify deleteIndex to handle an array of index and remove hard code
cy.deleteDataSourceByName(datasourceName);
cy.deleteIndex(INDEX_WITH_TIME_1);
cy.deleteIndex(INDEX_WITH_TIME_2);
});

const testConfigurations = generateAllTestConfigurations();
testConfigurations.forEach((config) => {
it(`should successfully create a saved query for ${config.testName}`, () => {
cy.navigateToWorkSpaceSpecificPage({
workspaceName,
page: 'discover',
isEnhancement: true,
});

cy.setDataset(config.dataset, datasourceName, config.datasetType);

cy.setQueryLanguage(config.language);
setDatePickerDatesAndSearchIfRelevant(config.language);

setSearchConfigurations(config);
verifyDiscoverPageState(config);
cy.saveQuery(config.saveName, ' ', false);
});
});

it('should see all saved queries', () => {
cy.getElementByTestId('saved-query-management-popover-button').click();

testConfigurations.forEach((config) => {
cy.getElementByTestId('saved-query-management-popover')
.contains(config.saveName)
.should('exist');
});
});
});
};

runSavedQueriesPopoverUITests();
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
verifySavedSearchInAssetsPage,
postRequestSaveSearch,
updateSavedSearchAndSaveAndVerify,
} from './utils/saved_search';
} from '../../../../../utils/apps/query_enhancements/saved_search';

export const runSavedSearchTests = () => {
describe('saved search', () => {
Expand Down
6 changes: 5 additions & 1 deletion cypress/utils/apps/data_explorer/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,18 @@ Cypress.Commands.add(
}
);

Cypress.Commands.add('saveQuery', (name, description) => {
// eslint-disable-next-line no-unused-vars
Cypress.Commands.add('saveQuery', (name, description = ' ', savedQueriesNewUIEnabled = true) => {
cy.whenTestIdNotFound('saved-query-management-popover', () => {
cy.getElementByTestId('saved-query-management-popover-button').click();
});
cy.getElementByTestId('saved-query-management-save-button').click();

cy.getElementByTestId('saveQueryFormTitle').type(name);
cy.getElementByTestId('saveQueryFormDescription').type(description);

cy.getElementByTestId('savedQueryFormSaveButton').click();
cy.getElementByTestId('euiToastHeader').contains('was saved').should('be.visible');
});

Cypress.Commands.add('loadSaveQuery', (name) => {
Expand Down
Loading

0 comments on commit 33f7ba6

Please sign in to comment.