Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cypress tests for discover 2.0 #1598

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets be more specific about what this test is doing

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();
Comment on lines +59 to +63
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use a test ID here. This will be flakey otherwise

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'
);
Comment on lines +77 to +80
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be flakey unless we can set this before hand right?


// 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();
Comment on lines +82 to +85
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will a wait help?

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we ensure this? Wont this be flakey?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea it prob be flaky. Will change to click PPL as a option

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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are index patterns, the default index pattern should be selected by default. We should not have to select it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea when i tried it manually, the default index pattern will be picked up by default; but somehow in the test, it wont. @ashwin-pc

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,121 @@
/*
* 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'
);

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

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);
}
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"osd:ciGroup7": "echo apps/data_explorer/aaa_before.spec.js,apps/data_explorer/doc_navigation.spec.js,apps/data_explorer/doc_table.spec.js,apps/data_explorer/errors.spec.js,apps/data_explorer/field_data.spec.js,apps/data_explorer/zzz_after.spec.js",
"osd:ciGroup8": "echo apps/data_explorer/aaa_before.spec.js,apps/data_explorer/field_visualize.spec.js,apps/data_explorer/filter_editor.spec.js,apps/data_explorer/index_pattern_with_encoded_id.spec.js,apps/data_explorer/index_pattern_without_field.spec.js,apps/data_explorer/zzz_after.spec.js",
"osd:ciGroup9": "echo apps/data_explorer/aaa_before.spec.js,apps/data_explorer/inspector.spec.js,apps/data_explorer/large_string.spec.js,apps/data_explorer/saved_queries.spec.js,apps/data_explorer/shared_links.spec.js,apps/data_explorer/sidebar.spec.js,apps/data_explorer/source_filter.spec.js,apps/data_explorer/zzz_after.spec.js",
"osd:ciGroup10": "echo apps/query_enhancement/*.js",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wont this require all the YAML settings and Advanced settings for this view to be set correctly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by this?

"start-dummy-llm-server": "node ./cypress/support/assistant-dummy-llm.js"
},
"repository": {
Expand Down
Loading