Skip to content

Commit

Permalink
fix save query tests
Browse files Browse the repository at this point in the history
Signed-off-by: Qingyang(Abby) Hu <[email protected]>
  • Loading branch information
abbyhu2000 committed Sep 20, 2023
1 parent a99c982 commit 0a0c6cd
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ describe('date_nanos_mixed', () => {
cy.waitForSearch();
});

after(() => {
testFixtureHandler.clearJSONMapping(
'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/date_nanos_mix/mappings.json.txt'
);
});

it('shows a list of records of indices with date & date_nanos fields in the right order', function () {
cy.get(`[data-test-subj="dataGridRowCell"]`)
.eq(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const testFixtureHandler = new TestFixtureHandler(

describe('discover app', () => {
before(() => {
cy.log('load opensearch-dashboards index with default index pattern');
testFixtureHandler.importJSONMapping(
'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/discover/discover.mappings.json.txt'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,41 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
import {
TestFixtureHandler,
MiscUtils,
} from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
import {
DX_DEFAULT_END_TIME,
DX_DEFAULT_START_TIME,
} from '../../../../../utils/constants';

const miscUtils = new MiscUtils(cy);
const testFixtureHandler = new TestFixtureHandler(
cy,
Cypress.env('openSearchUrl')
);

describe('saved queries saved objects', () => {
const fromTime = 'Sep 20, 2015 @ 08:00:00.000';
const toTime = 'Sep 21, 2015 @ 08:00:00.000';
before(() => {
testFixtureHandler.importJSONMapping(
'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/discover/discover.mappings.json.txt'
);

testFixtureHandler.importJSONDoc(
'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/discover/discover.json.txt'
);

testFixtureHandler.importJSONMapping(
'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.mappings.json.txt'
);

testFixtureHandler.importJSONDoc(
'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.json.txt'
);

cy.setAdvancedSetting({
defaultIndex: 'logstash-*',
});
Expand Down Expand Up @@ -98,26 +121,22 @@ describe('saved queries saved objects', () => {

cy.getElementByTestId(`queryInput`).should('have.text', '');

cy.loadSaveQuery('OkResponse');

cy.getElementByTestId(`queryInput`).should(
'have.text',
cy.get(`[data-test-subj~="load-saved-query-OkResponse-button"]`)
.should('be.visible')
.click();

'response:404'
);
cy.getElementByTestId(`queryInput`).should('have.text', 'response:404');
});

it('allows saving the currently loaded query as a new query', () => {
cy.whenTestIdNotFound('saved-query-management-popover', () => {
cy.getElementByTestId('saved-query-management-popover-button').click();
});
cy.getElementByTestId('saved-query-management-popover-button').click();

//save as new query
cy.getElementByTestId(
'saved-query-management-save-as-new-button'
).click();
cy.getElementByTestId('saveQueryFormTitle').type('OkResponseCopy');
cy.getElementByTestId('savedQueryFormSaveButton').click();
cy.loadSaveQuery('OkResponseCopy');
});

it('allows deleting the currently loaded saved query in the saved query management component and clears the query', () => {
Expand All @@ -140,6 +159,7 @@ describe('saved queries saved objects', () => {
cy.getElementByTestId('saveQueryForm')
.get('.euiForm__error')
.should('have.text', 'Name conflicts with an existing saved query');
cy.getElementByTestId('savedQueryFormCancelButton').click();
});

it('resets any changes to a loaded query on reloading the same saved query', () => {
Expand All @@ -150,13 +170,17 @@ describe('saved queries saved objects', () => {
});

it('allows clearing the currently loaded saved query', () => {
cy.loadSaveQuery('OkResponse');
cy.clearSaveQuery();
cy.getElementByTestId('saved-query-management-popover-button').click({
force: true,
});
cy.getElementByTestId('saved-query-management-clear-button').click();
cy.getElementByTestId(`queryInput`).should('have.text', '');
});

it('changing language removes saved query', () => {
cy.loadSaveQuery('OkResponse');
cy.get(`[data-test-subj~="load-saved-query-OkResponse-button"]`)
.should('be.visible')
.click();
cy.getElementByTestId('switchQueryLanguageButton').click();
cy.getElementByTestId('languageToggle').click();
cy.getElementByTestId(`queryInput`).should('have.text', '');
Expand Down
11 changes: 6 additions & 5 deletions cypress/utils/dashboards/data_explorer/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ Cypress.Commands.add('saveQuery', (name, description) => {
});

Cypress.Commands.add('loadSaveQuery', (name) => {
cy.whenTestIdNotFound('saved-query-management-popover', () => {
cy.getElementByTestId('saved-query-management-popover-button').click();
cy.getElementByTestId('saved-query-management-popover-button').click({
force: true,
});

cy.get(`[data-test-subj~="load-saved-query-${name}-button"]`)
.should('be.visible')
.click();
Expand All @@ -134,8 +135,8 @@ Cypress.Commands.add('clearSaveQuery', () => {
Cypress.Commands.add('deleteSaveQuery', (name) => {
cy.getElementByTestId('saved-query-management-popover-button').click();

cy.get(`[data-test-subj~="delete-saved-query-${name}-button"]`)
.should('be.visible')
.click();
cy.get(`[data-test-subj~="delete-saved-query-${name}-button"]`).click({
force: true,
});
cy.getElementByTestId('confirmModalConfirmButton').click();
});

0 comments on commit 0a0c6cd

Please sign in to comment.