Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Qingyang(Abby) Hu <[email protected]>
  • Loading branch information
abbyhu2000 committed Nov 6, 2024
1 parent d9dbe42 commit 64a54d4
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
TestFixtureHandler,
} from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
import { CURRENT_TENANT } from '../../../../../utils/commands';
import { clusterName, clusterConnection } from '../../../../../utils/constants';

const miscUtils = new MiscUtils(cy);
const testFixtureHandler = new TestFixtureHandler(
Expand All @@ -26,6 +27,7 @@ describe('dataset navigator', { scrollBehavior: false }, () => {
cy.fleshTenantSettings();
cy.deleteAllIndices();
cy.deleteSavedObjectByType('index-pattern');
cy.deleteSavedObjectByType('data-source');
});

describe('empty state', () => {
Expand All @@ -50,6 +52,28 @@ describe('dataset navigator', { scrollBehavior: false }, () => {
'cypress/fixtures/dashboard/opensearch_dashboards/query_enhancement/data.json.txt'
);

// Since default cluster is removed, need to create a data source connection
miscUtils.visitPage(
'app/management/opensearch-dashboards/dataSources/create'
);
cy.intercept('POST', '/api/saved_objects/data-source').as(
'createDataSourceRequest'
);
cy.getElementByTestId(`datasource_card_opensearch`).click();
cy.get('[name="dataSourceTitle"]').type(clusterName);
cy.get('[name="endpoint"]').type(clusterConnection);
cy.getElementByTestId('createDataSourceFormAuthTypeSelect').click();
cy.get(`button[id="no_auth"]`).click();

cy.getElementByTestId('createDataSourceButton').click();
cy.wait('@createDataSourceRequest').then((interception) => {
expect(interception.response.statusCode).to.equal(200);
});
cy.location('pathname', { timeout: 6000 }).should(
'include',
'app/management/opensearch-dashboards/dataSources'
);

// Go to the Discover page
miscUtils.visitPage(`app/data-explorer/discover#/`);

Expand All @@ -60,7 +84,7 @@ describe('dataset navigator', { scrollBehavior: false }, () => {
cy.getElementByTestId(`datasetSelectorButton`).click();
cy.getElementByTestId(`datasetSelectorAdvancedButton`).click();
cy.get(`[title="Indexes"]`).click();
cy.get(`[title="Default Cluster"]`).click();
cy.get(`[title=${clusterName}]`).click();
cy.get(`[title="timestamp-nanos"]`).click();
cy.getElementByTestId('datasetSelectorNext').click();

Expand All @@ -74,33 +98,25 @@ describe('dataset navigator', { scrollBehavior: false }, () => {
.should('have.length', 2);

//select SQL
cy.getElementByTestId('advancedSelectorLanguageSelect').select('SQL');
cy.getElementByTestId('advancedSelectorLanguageSelect').select(
'OpenSearch SQL'
);
cy.getElementByTestId('advancedSelectorConfirmButton').click();

cy.waitForLoaderNewHeader();

// Selected language in the language picker should be SQL
// bug: SQL won't be selected in cypress; manually click SQL in language selector
// cy.getElementByTestId('queryEditorLanguageSelector').should(
// 'contain',
// 'SQL'
// );

cy.get(`[data-test-subj="queryEditorLanguageSelector"]`).click();
cy.get(`[class~="languageSelector__menuItem"]`)
.should('have.length', 2)
.eq(1)
.click({
force: true,
});
// SQL should already be selected
cy.getElementByTestId('queryEditorLanguageSelector').should(
'contain',
'OpenSearch SQL'
);
cy.waitForLoaderNewHeader();

// SQL query should be executed and sending back result
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.setQueryLanguage('PPL');
cy.waitForLoaderNewHeader();
cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible');
});
Expand All @@ -109,7 +125,7 @@ describe('dataset navigator', { scrollBehavior: false }, () => {
cy.getElementByTestId(`datasetSelectorButton`).click();
cy.getElementByTestId(`datasetSelectorAdvancedButton`).click();
cy.get(`[title="Indexes"]`).click();
cy.get(`[title="Default Cluster"]`).click();
cy.get(`[title=${clusterName}]`).click();
cy.get(`[title="timestamp-nanos"]`).click();
cy.getElementByTestId('datasetSelectorNext').click();

Expand All @@ -128,7 +144,7 @@ describe('dataset navigator', { scrollBehavior: false }, () => {

cy.waitForLoaderNewHeader();

// Selected language should be PPL
// PPL should already be selected
cy.getElementByTestId('queryEditorLanguageSelector').should(
'contain',
'PPL'
Expand All @@ -148,13 +164,8 @@ describe('dataset navigator', { scrollBehavior: false }, () => {
);

// Switch language to SQL
cy.getElementByTestId('queryEditorLanguageSelector').click();
cy.get(`[class~="languageSelector__menuItem"]`)
.should('have.length', 2)
.eq(1)
.click({
force: true,
});
cy.setQueryLanguage('OpenSearch SQL');

cy.waitForLoaderNewHeader();
cy.getElementByTestId('queryResultCompleteMsg').should('be.visible');
cy.getElementByTestId('queryEditorFooterTimestamp').should(
Expand Down
1 change: 1 addition & 0 deletions cypress/utils/dashboards/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import './vis_type_table/commands';
import './vis_type_vega/commands';
import './vis-augmenter/commands';
import './data_explorer/commands';
import './query_enhancement/commands';

Cypress.Commands.add('waitForLoader', () => {
const opts = { log: false };
Expand Down
1 change: 1 addition & 0 deletions cypress/utils/dashboards/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ export * from './vis_type_timeline/constants';
export * from './vis-augmenter/constants';
export * from './data_explorer/constants';
export * from './vis_type_vega/constants';
export * from './query_enhancement/constants';
47 changes: 0 additions & 47 deletions cypress/utils/dashboards/data_explorer/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,50 +168,3 @@ 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);
}
});
47 changes: 47 additions & 0 deletions cypress/utils/dashboards/query_enhancement/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

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('setQueryLanguage', (value, submit = true) => {
const opts = { log: false };

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

cy.getElementByTestId(`queryEditorLanguageSelector`).click();
cy.get(`[class~="languageSelector__menuItem"]`).contains(value).click({
force: true,
});
});
7 changes: 7 additions & 0 deletions cypress/utils/dashboards/query_enhancement/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

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

0 comments on commit 64a54d4

Please sign in to comment.