Skip to content

Commit

Permalink
refactor query enhancement tests (#9208)
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Kim <[email protected]>
  • Loading branch information
angle943 authored Jan 17, 2025
1 parent ed9ef72 commit a2f3b15
Show file tree
Hide file tree
Showing 15 changed files with 412 additions and 612 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { WORKSPACE_NAME, DATASOURCE_NAME } from '../../../../../utils/apps/constants';
import { DATASOURCE_NAME } from '../../../../../utils/apps/constants';
import { SECONDARY_ENGINE } from '../../../../../utils/constants';
import { getRandomizedWorkspaceName } from '../../../../../utils/apps/query_enhancements/shared';

const randomString = Math.random().toString(36).substring(7);
const workspace = `${WORKSPACE_NAME}-${randomString}`;
const workspace = getRandomizedWorkspaceName();

describe('No Index Pattern Check Test', () => {
before(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
* SPDX-License-Identifier: Apache-2.0
*/

import {
WORKSPACE_NAME,
DATASOURCE_NAME,
START_TIME,
END_TIME,
} from '../../../../../utils/apps/constants';
import { DATASOURCE_NAME, START_TIME, END_TIME } from '../../../../../utils/apps/constants';
import { SECONDARY_ENGINE } from '../../../../../utils/constants';
import { getRandomizedWorkspaceName } from '../../../../../utils/apps/query_enhancements/shared';

const randomString = Math.random().toString(36).substring(7);
const workspace = `${WORKSPACE_NAME}-${randomString}`;
const workspace = getRandomizedWorkspaceName();

describe('dataset selector', { scrollBehavior: false }, () => {
before(() => {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
* SPDX-License-Identifier: Apache-2.0
*/

import {
WORKSPACE_NAME,
DATASOURCE_NAME,
START_TIME,
END_TIME,
} from '../../../../../utils/apps/constants';
import { DATASOURCE_NAME, START_TIME, END_TIME } from '../../../../../utils/apps/constants';
import { SECONDARY_ENGINE } from '../../../../../utils/constants';
import { getRandomizedWorkspaceName } from '../../../../../utils/apps/query_enhancements/shared';

const randomString = Math.random().toString(36).substring(7);
const workspace = `${WORKSPACE_NAME}-${randomString}`;
const workspace = getRandomizedWorkspaceName();

describe('query enhancement queries', { scrollBehavior: false }, () => {
before(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
DSM_API,
S3_CLUSTER,
} from '../../../../../utils/apps/query_enhancements/constants';
import { WORKSPACE_NAME } from '../../../../../utils/apps/constants';
import { getRandomizedWorkspaceName } from '../../../../../utils/apps/query_enhancements/shared';

const workspace = getRandomizedWorkspaceName();

let dataSourceId = '';
const definedS3Variables = !S3_CLUSTER.url;
Expand Down Expand Up @@ -83,12 +85,12 @@ const definedS3Variables = !S3_CLUSTER.url;
describe('Run S3 Query', () => {
beforeEach(() => {
// Create workspace
cy.deleteWorkspaceByName(WORKSPACE_NAME);
cy.deleteWorkspaceByName(workspace);
cy.visit('/app/home');
cy.createInitialWorkspaceWithDataSource(S3_CLUSTER.name, WORKSPACE_NAME);
cy.createInitialWorkspaceWithDataSource(S3_CLUSTER.name, workspace);
});
afterEach(() => {
cy.deleteWorkspaceByName(WORKSPACE_NAME);
cy.deleteWorkspaceByName(workspace);
});

it('with SQL', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,25 @@ import {
INDEX_WITH_TIME_2,
SECONDARY_ENGINE,
} from '../../../../../utils/constants';

import {
workspaceName,
datasourceName,
setSearchConfigurations,
getRandomizedWorkspaceName,
getRandomizedDatasourceName,
setDatePickerDatesAndSearchIfRelevant,
generateAllTestConfigurations,
} from '../../../../../utils/apps/query_enhancements/shared';
import {
generateSavedTestConfiguration,
setSearchConfigurations,
verifyDiscoverPageState,
} from '../../../../../utils/apps/query_enhancements/saved_search';
} from '../../../../../utils/apps/query_enhancements/saved';

import { generateAllTestConfigurations } from '../../../../../utils/apps/query_enhancements/saved_queries';
const workspaceName = getRandomizedWorkspaceName();
const datasourceName = getRandomizedDatasourceName();

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

export const runSavedQueriesFlyoutUITests = () => {
describe('saved queries flyout UI', () => {
before(() => {
beforeEach(() => {
// Load test data
cy.setupTestData(
SECONDARY_ENGINE.url,
Expand Down Expand Up @@ -57,7 +60,7 @@ export const runSavedQueriesFlyoutUITests = () => {
});
});

after(() => {
afterEach(() => {
// 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
Expand All @@ -66,8 +69,7 @@ export const runSavedQueriesFlyoutUITests = () => {
cy.deleteIndex(INDEX_WITH_TIME_2);
});

const testConfigurations = generateAllTestConfigurations();
testConfigurations.forEach((config) => {
generateAllTestConfigurations(generateSavedTestConfiguration).forEach((config) => {
it(`should successfully create a saved query for ${config.testName}`, () => {
cy.navigateToWorkSpaceSpecificPage({
workspaceName,
Expand All @@ -83,15 +85,10 @@ export const runSavedQueriesFlyoutUITests = () => {
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) => {
// verify that it has been saved
cy.getElementByTestId('saved-query-management-popover-button').click();
cy.getElementByTestId('saved-query-management-open-button').click();
cy.getElementByTestId('euiFlyoutCloseButton')
.parent()
.contains(config.saveName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,26 @@ import {
INDEX_WITH_TIME_2,
SECONDARY_ENGINE,
} from '../../../../../utils/constants';

import {
workspaceName,
datasourceName,
setSearchConfigurations,
getRandomizedWorkspaceName,
getRandomizedDatasourceName,
setDatePickerDatesAndSearchIfRelevant,
generateAllTestConfigurations,
} from '../../../../../utils/apps/query_enhancements/shared';
import {
generateSavedTestConfiguration,
setSearchConfigurations,
verifyDiscoverPageState,
} from '../../../../../utils/apps/query_enhancements/saved_search';
} from '../../../../../utils/apps/query_enhancements/saved';

import { generateAllTestConfigurations } from '../../../../../utils/apps/query_enhancements/saved_queries';
const workspaceName = getRandomizedWorkspaceName();
const datasourceName = getRandomizedDatasourceName();

// 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(() => {
beforeEach(() => {
// Load test data
cy.setupTestData(
SECONDARY_ENGINE.url,
Expand Down Expand Up @@ -58,7 +61,7 @@ export const runSavedQueriesPopoverUITests = () => {
});
});

after(() => {
afterEach(() => {
// 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
Expand All @@ -67,8 +70,7 @@ export const runSavedQueriesPopoverUITests = () => {
cy.deleteIndex(INDEX_WITH_TIME_2);
});

const testConfigurations = generateAllTestConfigurations();
testConfigurations.forEach((config) => {
generateAllTestConfigurations(generateSavedTestConfiguration).forEach((config) => {
it(`should successfully create a saved query for ${config.testName}`, () => {
cy.navigateToWorkSpaceSpecificPage({
workspaceName,
Expand All @@ -83,14 +85,10 @@ export const runSavedQueriesPopoverUITests = () => {

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

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

testConfigurations.forEach((config) => {
// verify that it has been saved
cy.getElementByTestId('saved-query-management-popover-button').click();
cy.getElementByTestId('saved-query-management-popover')
.contains(config.saveName)
.should('exist');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,22 @@ import {
SECONDARY_ENGINE,
} from '../../../../../utils/constants';
import {
workspaceName,
datasourceName,
generateAllTestConfigurations,
getRandomizedWorkspaceName,
getRandomizedDatasourceName,
setDatePickerDatesAndSearchIfRelevant,
} from '../../../../../utils/apps/query_enhancements/shared';
import {
setSearchConfigurations,
verifyDiscoverPageState,
verifySavedSearchInAssetsPage,
postRequestSaveSearch,
updateSavedSearchAndSaveAndVerify,
} from '../../../../../utils/apps/query_enhancements/saved_search';
generateSavedTestConfiguration,
} from '../../../../../utils/apps/query_enhancements/saved';

const workspaceName = getRandomizedWorkspaceName();
const datasourceName = getRandomizedDatasourceName();

export const runSavedSearchTests = () => {
describe('saved search', () => {
Expand Down Expand Up @@ -65,7 +71,7 @@ export const runSavedSearchTests = () => {
cy.deleteIndex(INDEX_WITH_TIME_2);
});

generateAllTestConfigurations().forEach((config) => {
generateAllTestConfigurations(generateSavedTestConfiguration).forEach((config) => {
it(`should successfully create a saved search for ${config.testName}`, () => {
cy.navigateToWorkSpaceSpecificPage({
workspaceName,
Expand All @@ -86,7 +92,7 @@ export const runSavedSearchTests = () => {
// the saved search does not appear. So adding this wait
cy.wait(2000);

verifySavedSearchInAssetsPage(config);
verifySavedSearchInAssetsPage(config, workspaceName);
});

// We are starting from various languages
Expand Down Expand Up @@ -126,13 +132,13 @@ export const runSavedSearchTests = () => {
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);
updateSavedSearchAndSaveAndVerify(config, workspaceName, datasourceName, 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);
updateSavedSearchAndSaveAndVerify(config, workspaceName, datasourceName, true);
});
});
});
Expand Down
6 changes: 3 additions & 3 deletions cypress/utils/apps/data_explorer/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ Cypress.Commands.add(
}
);

// eslint-disable-next-line no-unused-vars
Cypress.Commands.add('saveQuery', (name, description = ' ', savedQueriesNewUIEnabled = true) => {
Cypress.Commands.add('saveQuery', (name, description = ' ') => {
cy.whenTestIdNotFound('saved-query-management-popover', () => {
cy.getElementByTestId('saved-query-management-popover-button').click();
});
Expand All @@ -123,7 +122,8 @@ Cypress.Commands.add('saveQuery', (name, description = ' ', savedQueriesNewUIEna
cy.getElementByTestId('saveQueryFormTitle').type(name);
cy.getElementByTestId('saveQueryFormDescription').type(description);

cy.getElementByTestId('savedQueryFormSaveButton').click();
// putting force: true as this button is sometimes masked by a popup element
cy.getElementByTestId('savedQueryFormSaveButton').click({ force: true });
cy.getElementByTestId('euiToastHeader').contains('was saved').should('be.visible');
});

Expand Down
2 changes: 1 addition & 1 deletion cypress/utils/apps/data_explorer/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ declare namespace Cypress {
value: string,
isEnhancement?: boolean
): Chainable<any>;
saveQuery(name: string, description: string): Chainable<any>;
saveQuery(name: string, description?: string): Chainable<any>;
loadSaveQuery(name: string): Chainable<any>;
clearSaveQuery(): Chainable<any>;
deleteSaveQuery(name: string): Chainable<any>;
Expand Down
26 changes: 0 additions & 26 deletions cypress/utils/apps/query_enhancements/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,6 @@ export const DATASOURCE_NAME = 'data-logs-1';
export const WORKSPACE_NAME = 'query-ws';
export const START_TIME = 'Jan 1, 2020 @ 00:00:00.000';
export const END_TIME = 'Jan 1, 2024 @ 00:00:00.000';
export const INDEX_NAME = 'data_logs_small_time_1';
export const DEFAULT_TIME_INDEX_PATTERN_NAME = 'data_logs_small_time_1*';
export const DEFAULT_NO_TIME_INDEX_PATTERN_NAME = 'data_logs_small_no_time_1*';
export const INDEX_PATTERN_NAME = `${DATASOURCE_NAME}::${DEFAULT_TIME_INDEX_PATTERN_NAME}`;

export const DATASET_CONFIGS = {
index_pattern: {
type: 'index_pattern',
name: INDEX_PATTERN_NAME,
languages: [
// isFilterButtonsEnabled signifies if the filter buttons are supposed to be enabled.
{ name: 'DQL', isFilterButtonsEnabled: true },
{ name: 'Lucene', isFilterButtonsEnabled: true },
{ name: 'OpenSearch SQL', isFilterButtonsEnabled: false },
{ name: 'PPL', isFilterButtonsEnabled: false },
],
},
index: {
type: 'index',
name: INDEX_NAME,
languages: [
{ name: 'OpenSearch SQL', isFilterButtonsEnabled: false },
{ name: 'PPL', isFilterButtonsEnabled: false },
],
},
};

export const clusterName = 'test_cluster';
export const clusterConnection = 'http://localhost:9200';
Expand Down
Loading

0 comments on commit a2f3b15

Please sign in to comment.