Skip to content

Commit

Permalink
Add initial query enhancement 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 Oct 22, 2024
1 parent be1f578 commit b1c51cb
Show file tree
Hide file tree
Showing 3 changed files with 348 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import {
MiscUtils,
TestFixtureHandler,
} from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
import { CURRENT_TENANT } from '../../../../../../utils/commands';

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

const indexSet = [
'logstash-2015.09.22',
'logstash-2015.09.21',
'logstash-2015.09.20',
];

describe('dataset navigator', { scrollBehavior: false }, () => {
before(() => {
CURRENT_TENANT.newTenant = 'global';
cy.fleshTenantSettings();
cy.deleteAllIndices();
cy.deleteSavedObjectByType('index-pattern');
});

describe('empty state', () => {
it('no index pattern', function () {
// Go to the Discover page
miscUtils.visitPage(
`app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))`
);

cy.waitForLoaderNewHeader();
cy.getElementByTestId('discoverNoIndexPatterns');
});
});

describe('select indices', () => {
before(() => {
// import logstash functional
testFixtureHandler.importJSONDocIfNeeded(
indexSet,
'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.mappings.json.txt',
'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.json.txt'
);

// Go to the Discover page
miscUtils.visitPage(
`app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))`
);
});

it('with SQL as default language', function () {
cy.get(`[class~="datasetSelector__button"]`).click();
cy.get(`[class~="datasetSelector__advancedButton"]`).click();
cy.get(`[title="Indexes"]`).click();
cy.get(`[title="Default Cluster"]`).click();
cy.get(`[title="logstash-2015.09.20"]`).click();
cy.getElementByTestId('datasetSelectorNext').click();

cy.get(`[class="euiModalHeader__title"]`).should(
'contain',
'Step 2: Configure data'
);
// should have two options: SQL and PPL
cy.get('option').should('have.length', 2);
cy.getElementByTestId('advancedSelectorConfirmButton').click();

cy.waitForLoaderNewHeader();

// Selected language should be SQL
cy.getElementByTestId('queryEditorLanguageSelector').should(
'contain',
'SQL'
);

// The following steps are needed because when selecting SQL, discover loaded with data but the
// multi-line query editor are not loaded properly(it renders a single line query bar) unless we select SQL again
// This bug only exist in cypress test; can not reproduce manually
cy.get(`[data-test-subj="queryEditorLanguageSelector"]`).click();
cy.get(`[class~="languageSelector__menuItem"]`)
.should('have.length', 2)
.eq(1)
.click({
force: true,
});
cy.waitForLoaderNewHeader();
cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible');

// Switch language to PPL
cy.get(`[data-test-subj="queryEditorLanguageSelector"]`).click();
cy.get(`[class~="languageSelector__menuItem"]`).eq(0).click({
force: true,
});
cy.waitForLoaderNewHeader();
cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible');
});

it('with PPL as default language', function () {
cy.get(`[class~="datasetSelector__button"]`).click();
cy.get(`[class~="datasetSelector__advancedButton"]`).click();
cy.get(`[title="Indexes"]`).click();
cy.get(`[title="Default Cluster"]`).click();
cy.get(`[title="logstash-2015.09.21"]`).click();
cy.getElementByTestId('datasetSelectorNext').click();

cy.get(`[class="euiModalHeader__title"]`).should(
'contain',
'Step 2: Configure data'
);
// should have two options: SQL and PPL; PPL should be selected
cy.getElementByTestId('advancedSelectorTimeFieldSelect').select(
'@timestamp'
);
cy.getElementByTestId('advancedSelectorConfirmButton').click();

cy.waitForLoaderNewHeader();

// Selected language should be PPL
cy.getElementByTestId('queryEditorLanguageSelector').should(
'contain',
'PPL'
);

cy.waitForLoaderNewHeader();
cy.getElementByTestId('queryResultCompleteMsg').should('be.visible');
cy.getElementByTestId('queryEditorFooterTimestamp').should(
'contain',
'@timestamp'
);

// Switch language to SQL
cy.getElementByTestId('queryEditorLanguageSelector').click();
cy.get(`[class~="languageSelector__menuItem"]`).eq(1).click({
force: true,
});
cy.waitForLoaderNewHeader();
cy.getElementByTestId('queryResultCompleteMsg').should('be.visible');
cy.getElementByTestId('queryEditorFooterTimestamp').should(
'contain',
'@timestamp'
);
});
});

describe('index pattern', () => {
it('create index pattern and select it', function () {
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'
);

// Go to the Discover page
miscUtils.visitPage(
`app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))`
);

cy.get(`[class~="datasetSelector__button"]`).click();
cy.getElementByTestId(`datasetOption-logstash-*`).click();

cy.waitForLoaderNewHeader();
cy.waitForSearch();
cy.verifyHitCount('14,004');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import {
MiscUtils,
TestFixtureHandler,
} from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
import { CURRENT_TENANT } from '../../../../../../utils/commands';

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

const indexSet = [
'logstash-2015.09.22',
'logstash-2015.09.21',
'logstash-2015.09.20',
];

describe('query enhancement queries', { scrollBehavior: false }, () => {
before(() => {
CURRENT_TENANT.newTenant = 'global';
cy.fleshTenantSettings();
cy.deleteAllIndices();
cy.deleteSavedObjectByType('index-pattern');
// import logstash functional
testFixtureHandler.importJSONDocIfNeeded(
indexSet,
'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.mappings.json.txt',
'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.json.txt'
);

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'
);

// miscUtils.visitPage(`app/import_sample_data`);
// cy.getElementByTestId(
// 'addSampleDataSetecommerce'
// ).click();
// cy.waitForLoaderNewHeader();

cy.setAdvancedSetting({
defaultIndex: 'logstash-*',
});

// Go to the Discover page
miscUtils.visitPage(
`app/data-explorer/discover#/?_g=(filters:!(),time:(from:'2015-09-19T13:31:44.000Z',to:'2015-09-24T01:31:44.000Z'))`
);

cy.get(`[class~="datasetSelector__button"]`).click();
cy.get(`[data-test-subj="datasetOption-logstash-*"]`).click();

cy.waitForLoaderNewHeader();
cy.waitForSearch();
});

describe('send queries', () => {
it('with DQL', function () {
const query = `geo.src:FR`;
cy.setSingleLineQueryEditor(query);
cy.waitForLoaderNewHeader();
cy.waitForSearch();
cy.verifyHitCount(119);

//query should persist across refresh
cy.reload();
cy.verifyHitCount(119);
});

it('with Lucene', function () {
cy.get(`[data-test-subj="queryEditorLanguageSelector"]`).click();
cy.get(`[class~="languageSelector__menuItem"]`).eq(1).click({
force: true,
});

const query = `geo.src:FR`;
cy.setSingleLineQueryEditor(query);
cy.waitForLoaderNewHeader();
cy.waitForSearch();
cy.verifyHitCount(119);

//query should persist across refresh
cy.reload();
cy.verifyHitCount(119);
});

it('with PPL', function () {
cy.get(`[data-test-subj="queryEditorLanguageSelector"]`).click();
cy.get(`[class~="languageSelector__menuItem"]`).eq(2).click({
force: true,
});

// default PPL query should be set
cy.waitForLoaderNewHeader();
cy.waitForSearch();
cy.verifyHitCount('14,004');

//query should persist across refresh
cy.reload();
cy.verifyHitCount('14,004');
});

it('with SQL', function () {
cy.get(`[data-test-subj="queryEditorLanguageSelector"]`).click();
cy.get(`[class~="languageSelector__menuItem"]`).eq(3).click({
force: true,
});

// default SQL query should be set
cy.waitForLoaderNewHeader();
cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible');

//query should persist across refresh
cy.reload();
cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible');
});
});
});
47 changes: 47 additions & 0 deletions cypress/utils/dashboards/data_explorer/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,50 @@ function checkForElementVisibility() {
}
});
}

Cypress.Commands.add('waitForLoaderNewHeader', () => {
const opts = { log: false };

Cypress.log({
name: 'waitForPageLoad',
displayName: 'wait',
message: 'page load',
});
cy.wait(Cypress.env('WAIT_FOR_LOADER_BUFFER_MS'));
cy.getElementByTestId('recentItemsSectionButton', opts);
});

Cypress.Commands.add('setSingleLineQueryEditor', (value, submit = true) => {
const opts = { log: false };

Cypress.log({
name: 'setSingleLineQueryEditor',
displayName: 'set query',
message: value,
});

cy.getElementByTestId('osdQueryEditor__singleLine', opts).type(value, opts);

if (submit) {
cy.updateTopNav(opts);
}
});

Cypress.Commands.add('setMultiLineQueryEditor', (value, submit = true) => {
const opts = { log: false };

Cypress.log({
name: 'setMultiLineQueryEditor',
displayName: 'set query',
message: value,
});

cy.getElementByTestId('osdQueryEditor__multiLine', opts)
.clear(opts)
.type(value, opts)
.blur(opts);

if (submit) {
cy.updateTopNav(opts);
}
});

0 comments on commit b1c51cb

Please sign in to comment.