Skip to content

Commit

Permalink
Re-enable dataset_selector.spec.js and queries.spec.js under workspace
Browse files Browse the repository at this point in the history
Signed-off-by: Anan <[email protected]>
  • Loading branch information
ananzh committed Dec 20, 2024
1 parent f85cd6d commit feaed99
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@

export const DATASOURCE_NAME = 'query-cluster';
export const WORKSPACE_NAME = 'query-workspace';
export const START_TIME = 'Dec 31, 2020 @ 00:00:00.000';
export const END_TIME = 'Dec 31, 2022 @ 23:59:59.999';
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,50 @@
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import {
MiscUtils,
TestFixtureHandler,
} from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
import { PATHS, SECONDARY_ENGINE } from '../../../../../utils/constants';

const miscUtils = new MiscUtils(cy);
const testFixtureHandler = new TestFixtureHandler(cy, PATHS.ENGINE);
import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
import { WORKSPACE_NAME, DATASOURCE_NAME, START_TIME, END_TIME } from './constants';
import { BASE_PATH, SECONDARY_ENGINE } from '../../../../../utils/constants';

describe.skip('dataset selector', { scrollBehavior: false }, () => {
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'))`
);
const miscUtils = new MiscUtils(cy);

cy.waitForLoader(true);
cy.getElementByTestId('discoverNoIndexPatterns');
describe('dataset selector', { scrollBehavior: false }, () => {
before(() => {
cy.setupTestData(
SECONDARY_ENGINE.url,
['cypress/fixtures/query_enhancements/data-logs-1/data_logs_small_time_1.mapping.json'],
['cypress/fixtures/query_enhancements/data-logs-1/data_logs_small_time_1.data.ndjson']
);

// Add data source
cy.addDataSource({
name: `${DATASOURCE_NAME}`,
url: `${SECONDARY_ENGINE.url}`,
authType: 'no_auth',
});
});
after(() => {
cy.deleteDataSourceByName(`${DATASOURCE_NAME}`);
cy.deleteIndex('data_logs_small_time_1');
});
beforeEach(() => {
// Create workspace
cy.deleteWorkspaceByName(`${WORKSPACE_NAME}`);
miscUtils.visitPage('/app/home');
cy.createInitialWorkspaceWithDataSource(`${DATASOURCE_NAME}`, `${WORKSPACE_NAME}`);
});

describe('select indices', () => {
before(() => {
testFixtureHandler.importJSONMapping('cypress/fixtures/timestamp/mappings.json.txt');

testFixtureHandler.importJSONDoc('cypress/fixtures/timestamp/data.json.txt');

// Since default cluster is removed, need to create a data source connection if needed
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(SECONDARY_ENGINE.name);
cy.get('[name="endpoint"]').type(SECONDARY_ENGINE.url);
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#/`);

cy.waitForLoader(true);
});
afterEach(() => {
cy.deleteWorkspaceByName(`${WORKSPACE_NAME}`);
});

describe('select indices', () => {
it('with SQL as default language', function () {
cy.getElementByTestId(`datasetSelectorButton`).click();
cy.getElementByTestId(`datasetSelectorAdvancedButton`).click();
cy.get(`[title="Indexes"]`).click();
cy.get(`[title=${SECONDARY_ENGINE.name}]`).click();
cy.get(`[title="timestamp-nanos"]`).click();
cy.get(`[title=${DATASOURCE_NAME}]`).click();
cy.get(`[title="data_logs_small_time_1"]`).click(); // Updated to match loaded data
cy.getElementByTestId('datasetSelectorNext').click();

cy.get(`[class="euiModalHeader__title"]`).should('contain', 'Step 2: Configure data');
Expand All @@ -81,9 +66,7 @@ describe.skip('dataset selector', { scrollBehavior: false }, () => {

// Switch language to PPL
cy.setQueryLanguage('PPL');
const fromTime = 'Sep 19, 2018 @ 00:00:00.000';
const toTime = 'Sep 21, 2019 @ 00:00:00.000';
cy.setTopNavDate(fromTime, toTime);
cy.setTopNavDate(START_TIME, END_TIME);

cy.waitForLoader(true);
cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible');
Expand All @@ -93,8 +76,8 @@ describe.skip('dataset selector', { scrollBehavior: false }, () => {
cy.getElementByTestId(`datasetSelectorButton`).click();
cy.getElementByTestId(`datasetSelectorAdvancedButton`).click();
cy.get(`[title="Indexes"]`).click();
cy.get(`[title=${SECONDARY_ENGINE.name}]`).click();
cy.get(`[title="timestamp-nanos"]`).click();
cy.get(`[title=${DATASOURCE_NAME}]`).click();
cy.get(`[title="data_logs_small_time_1"]`).click(); // Updated to match loaded data
cy.getElementByTestId('datasetSelectorNext').click();

cy.get(`[class="euiModalHeader__title"]`).should('contain', 'Step 2: Configure data');
Expand All @@ -110,9 +93,7 @@ describe.skip('dataset selector', { scrollBehavior: false }, () => {
// PPL should already be selected
cy.getElementByTestId('queryEditorLanguageSelector').should('contain', 'PPL');

const fromTime = 'Sep 19, 2018 @ 00:00:00.000';
const toTime = 'Sep 21, 2019 @ 00:00:00.000';
cy.setTopNavDate(fromTime, toTime);
cy.setTopNavDate(START_TIME, END_TIME);

cy.waitForLoader(true);

Expand All @@ -131,30 +112,28 @@ describe.skip('dataset selector', { scrollBehavior: false }, () => {

describe('index pattern', () => {
it('create index pattern and select it', function () {
testFixtureHandler.importJSONMapping('cypress/fixtures/logstash/mappings.json.txt');
testFixtureHandler.importJSONDoc('cypress/fixtures/logstash/data.json.txt');

testFixtureHandler.importJSONMapping('cypress/fixtures/discover/mappings.json.txt');
testFixtureHandler.importJSONDoc('cypress/fixtures/discover/data.json.txt');
// Create and select index pattern for data_logs_small_time_1*
cy.createWorkspaceIndexPatterns({
url: `${BASE_PATH}`,
workspaceName: `${WORKSPACE_NAME}`,
indexPattern: 'data_logs_small_time_1',
timefieldName: 'timestamp',
indexPatternHasTimefield: true,
dataSource: DATASOURCE_NAME,
isEnhancement: true,
});

// 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.navigateToWorkSpaceHomePage(`${BASE_PATH}`, `${WORKSPACE_NAME}`);

cy.waitForLoader(true);
cy.getElementByTestId(`datasetSelectorButton`).click();
cy.getElementByTestId(`datasetSelectorAdvancedButton`).click();
cy.get(`[title="Index Patterns"]`).click();
cy.get(`[title="logstash-*"]`).click();
cy.getElementByTestId('datasetSelectorNext').click();
cy.get(`[title="${DATASOURCE_NAME}::data_logs_small_time_1*"]`).should('exist');

cy.waitForLoader(true);
cy.waitForSearch();
cy.getElementByTestId(`queryResultCompleteMsg`).should('be.visible');
});
});

after(() => {
cy.deleteIndex('timestamp-nanos');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,68 @@
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import {
MiscUtils,
TestFixtureHandler,
} from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
import { PATHS } from '../../../../../utils/constants';

import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
import { WORKSPACE_NAME, DATASOURCE_NAME, START_TIME, END_TIME } from './constants';
import { BASE_PATH, SECONDARY_ENGINE } from '../../../../../utils/constants';

const miscUtils = new MiscUtils(cy);
const testFixtureHandler = new TestFixtureHandler(cy, PATHS.ENGINE);

describe.skip('query enhancement queries', { scrollBehavior: false }, () => {
describe('query enhancement queries', { scrollBehavior: false }, () => {
before(() => {
testFixtureHandler.importJSONMapping('cypress/fixtures/timestamp/mappings.json.txt');

testFixtureHandler.importJSONDoc('cypress/fixtures/timestamp/data_with_index_pattern.json.txt');

// Go to the Discover page
miscUtils.visitPage(`app/data-explorer/discover#/`);
// Load test data
cy.setupTestData(
SECONDARY_ENGINE.url,
['cypress/fixtures/query_enhancements/data-logs-1/data_logs_small_time_1.mapping.json'],
['cypress/fixtures/query_enhancements/data-logs-1/data_logs_small_time_1.data.ndjson']
);

cy.setAdvancedSetting({
defaultIndex: 'timestamp-*',
// Add data source
cy.addDataSource({
name: `${DATASOURCE_NAME}`,
url: `${SECONDARY_ENGINE.url}`,
authType: 'no_auth',
});

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

cy.get(`[class~="datasetSelector__button"]`).click();
cy.get(`[data-test-subj="datasetOption-timestamp-*"]`).click();
// Create workspace and set up index pattern
cy.deleteWorkspaceByName(`${WORKSPACE_NAME}`);
miscUtils.visitPage('/app/home');
cy.createInitialWorkspaceWithDataSource(`${DATASOURCE_NAME}`, `${WORKSPACE_NAME}`);

// Create and select index pattern for data_logs_small_time_1*
cy.createWorkspaceIndexPatterns({
url: `${BASE_PATH}`,
workspaceName: `${WORKSPACE_NAME}`,
indexPattern: 'data_logs_small_time_1',
timefieldName: 'timestamp',
indexPatternHasTimefield: true,
dataSource: DATASOURCE_NAME,
isEnhancement: true,
});

// Go to workspace home
cy.navigateToWorkSpaceHomePage(`${BASE_PATH}`, `${WORKSPACE_NAME}`);
cy.setTopNavDate(START_TIME, END_TIME);
cy.waitForLoader(true);
cy.waitForSearch();
});

after(() => {
cy.deleteWorkspaceByName(`${WORKSPACE_NAME}`);
cy.deleteDataSourceByName(`${DATASOURCE_NAME}`);
cy.deleteIndex('data_logs_small_time_1');
});

describe('send queries', () => {
it('with DQL', function () {
cy.setQueryLanguage('DQL');

const query = `_id:1`;
cy.setSingleLineQueryEditor(query);
cy.waitForLoader(true);
cy.waitForSearch();
cy.verifyHitCount(1);

//query should persist across refresh
// query should persist across refresh
cy.reload();
cy.verifyHitCount(1);
});
Expand All @@ -69,7 +88,7 @@ describe.skip('query enhancement queries', { scrollBehavior: false }, () => {
// default SQL query should be set
cy.waitForLoader(true);
cy.getElementByTestId(`osdQueryEditor__multiLine`).contains(
`SELECT * FROM timestamp-* LIMIT 10`
`SELECT * FROM data_logs_small_time_1* LIMIT 10`
);
cy.getElementByTestId(`queryResultCompleteMsg`).should('be.visible');

Expand All @@ -88,21 +107,15 @@ describe.skip('query enhancement queries', { scrollBehavior: false }, () => {

// default PPL query should be set
cy.waitForLoader(true);
cy.getElementByTestId(`osdQueryEditor__multiLine`).contains(`source = timestamp-*`);
cy.getElementByTestId(`osdQueryEditor__multiLine`).contains(
`source = data_logs_small_time_1*`
);
cy.waitForSearch();
cy.getElementByTestId(`queryResultCompleteMsg`).should('be.visible');
cy.get('[class="euiText euiText--small"]').then((text) => cy.log(text));
cy.verifyHitCount(4);

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

after(() => {
cy.deleteIndex('timestamp-nanos');
cy.deleteIndex('timestamp-milis');
cy.deleteSavedObject('index-pattern', 'index-pattern:timestamp-*');
cy.getElementByTestId(`queryResultCompleteMsg`).should('be.visible');
});
});
});
9 changes: 9 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@ import '../utils/commands';
import '../utils/apps/commands';
import '../utils/dashboards/workspace-plugin/commands';
import '../utils/dashboards/commands';

// TODO: Remove this after https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5476 is resolved
const scopedHistoryNavigationError = /^[^(ScopedHistory instance has fell out of navigation scope)]/;
Cypress.on('uncaught:exception', (err) => {
/* returning false here prevents Cypress from failing the test */
if (scopedHistoryNavigationError.test(err.message)) {
return false;
}
});
9 changes: 5 additions & 4 deletions cypress/utils/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,14 @@ Cypress.Commands.add('createInitialWorkspaceWithDataSource', (dataSourceTitle, w
cy.getElementByTestId('workspaceForm-workspaceDetails-nameInputText')
.should('be.visible')
.type(workspaceName);
cy.getElementByTestId('workspace-creator-dataSources-assign-button').should('be.visible').click();
cy.getElementByTestId('workspace-creator-dataSources-assign-button')
.scrollIntoView()
.should('be.visible')
.click();
cy.get(`.euiSelectableListItem[title="${dataSourceTitle}"]`)
.should('be.visible')
.trigger('click');
cy.getElementByTestId('workspace-detail-dataSources-associateModal-save-button')
.should('be.visible')
.click();
cy.getElementByTestId('workspace-detail-dataSources-associateModal-save-button').click();
cy.getElementByTestId('workspaceForm-bottomBar-createButton').should('be.visible').click();
cy.contains(/successfully/);
});
Expand Down
2 changes: 1 addition & 1 deletion cypress/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

export * from './apps/constants';

export const BASE_PATH = Cypress.env('baseUrl');
export const BASE_PATH = Cypress.config('baseUrl');
export const BASE_ENGINE = Cypress.env('ENGINE');
export const SECONDARY_ENGINE = Cypress.env('SECONDARY_ENGINE');

Expand Down
Loading

0 comments on commit feaed99

Please sign in to comment.