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

Re-enable dataset_selector.spec.js and queries.spec.js under workspace #9082

Merged
merged 4 commits into from
Dec 20, 2024
Merged
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
2 changes: 2 additions & 0 deletions changelogs/fragments/9082.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
- Re-enable dataset_selector.spec.js under workspace in ciGroup10 ([#9082](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9082))
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 = 'Jan 1, 2020 @ 00:00:00.000';
export const END_TIME = 'Jan 1, 2024 @ 00:00:00.000';
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,47 @@
* 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);

describe.skip('dataset selector', { scrollBehavior: false }, () => {
describe('empty state', () => {
Copy link
Member

Choose a reason for hiding this comment

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

why do we delete the test for testing the empty state? i think we do need to test when there is no index pattern

Copy link
Member Author

Choose a reason for hiding this comment

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

we moved it to a_check.spec.js

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.waitForLoader(true);
cy.getElementByTestId('discoverNoIndexPatterns');
import { WORKSPACE_NAME, DATASOURCE_NAME, START_TIME, END_TIME } from './constants';
import { BASE_PATH, SECONDARY_ENGINE } from '../../../../../utils/constants';

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}`);
cy.visit('/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 +63,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 +73,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 +90,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 +109,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,65 @@
* 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';

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

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}`);
cy.visit('/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 +85,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 +104,16 @@ 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);
Copy link
Member

Choose a reason for hiding this comment

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

Why do we delete verifying the hit count? If we delete verifying hit count, how are we ensuring the query is persisted across refresh?

Feel like cy.getElementByTestId(queryResultCompleteMsg).should('be.visible'); only does not provide valid proof

Copy link
Member Author

Choose a reason for hiding this comment

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

sure. I added cy.verifyHitCount('10,000');


//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');
cy.verifyHitCount('10,000');
});
});
});
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
Loading