Skip to content

Commit

Permalink
Make createWorkspaceIndexPatterns to handle no default cluster and cl…
Browse files Browse the repository at this point in the history
…ean up

Signed-off-by: Anan <[email protected]>
  • Loading branch information
ananzh committed Dec 30, 2024
1 parent fb9a814 commit 05a6e0d
Show file tree
Hide file tree
Showing 13 changed files with 305 additions and 182 deletions.
1 change: 1 addition & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = defineConfig({
DATASOURCE_MANAGEMENT_ENABLED: false,
ML_COMMONS_DASHBOARDS_ENABLED: true,
WAIT_FOR_LOADER_BUFFER_MS: 0,
DISABLE_LOCAL_CLUSTER: false,
},
e2e: {
baseUrl: 'http://localhost:5601',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* SPDX-License-Identifier: Apache-2.0
*/

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

const miscUtils = new MiscUtils(cy);
const randomString = Math.random().toString(36).substring(7);
const workspace = `${WORKSPACE_NAME}-${randomString}`;

describe('No Index Pattern Check Test', () => {
before(() => {
Expand All @@ -23,21 +23,22 @@ describe('No Index Pattern Check Test', () => {
'cypress/fixtures/query_enhancements/data-logs-2/data_logs_small_time_2.data.ndjson',
]
);

// Add data source
cy.addDataSource({
name: `${DATASOURCE_NAME}`,
url: `${SECONDARY_ENGINE.url}`,
authType: 'no_auth',
});
// Create workspace
cy.deleteWorkspaceByName(`${WORKSPACE_NAME}`);
miscUtils.visitPage('/app/home');
cy.createInitialWorkspaceWithDataSource(`${DATASOURCE_NAME}`, `${WORKSPACE_NAME}`);
cy.deleteWorkspaceByName(`${workspace}`);
cy.visit('/app/home');
cy.createInitialWorkspaceWithDataSource(`${DATASOURCE_NAME}`, `${workspace}`);
cy.wait(2000);
});

after(() => {
cy.deleteWorkspaceByName(`${WORKSPACE_NAME}`);
cy.deleteWorkspaceByName(`${workspace}`);
cy.deleteDataSourceByName(`${DATASOURCE_NAME}`);
// TODO: Modify deleteIndex to handle an array of index and remove hard code
cy.deleteIndex('data_logs_small_time_1');
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { WORKSPACE_NAME, DATASOURCE_NAME, START_TIME, END_TIME } from './constants';
import {
WORKSPACE_NAME,
DATASOURCE_NAME,
START_TIME,
END_TIME,
} from '../../../../../utils/apps/constants';
import { BASE_PATH, SECONDARY_ENGINE } from '../../../../../utils/constants';

const randomString = Math.random().toString(36).substring(7);
const workspace = `${WORKSPACE_NAME}-${randomString}`;

describe('dataset selector', { scrollBehavior: false }, () => {
before(() => {
cy.setupTestData(
Expand All @@ -27,13 +35,13 @@ describe('dataset selector', { scrollBehavior: false }, () => {
});
beforeEach(() => {
// Create workspace
cy.deleteWorkspaceByName(`${WORKSPACE_NAME}`);
cy.deleteWorkspaceByName(`${workspace}`);
cy.visit('/app/home');
cy.createInitialWorkspaceWithDataSource(`${DATASOURCE_NAME}`, `${WORKSPACE_NAME}`);
cy.createInitialWorkspaceWithDataSource(`${DATASOURCE_NAME}`, `${workspace}`);
});

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

describe('select indices', () => {
Expand All @@ -47,7 +55,7 @@ describe('dataset selector', { scrollBehavior: false }, () => {

cy.get(`[class="euiModalHeader__title"]`).should('contain', 'Step 2: Configure data');

//select SQL
// Select SQL
cy.getElementByTestId('advancedSelectorLanguageSelect').select('OpenSearch SQL');
cy.getElementByTestId(`advancedSelectorTimeFieldSelect`).select('timestamp');
cy.getElementByTestId('advancedSelectorConfirmButton').click();
Expand Down Expand Up @@ -79,7 +87,7 @@ describe('dataset selector', { scrollBehavior: false }, () => {

cy.get(`[class="euiModalHeader__title"]`).should('contain', 'Step 2: Configure data');

//select PPL
// Select PPL
cy.getElementByTestId('advancedSelectorLanguageSelect').select('PPL');

cy.getElementByTestId(`advancedSelectorTimeFieldSelect`).select('timestamp');
Expand Down Expand Up @@ -112,15 +120,15 @@ describe('dataset selector', { scrollBehavior: false }, () => {
// Create and select index pattern for data_logs_small_time_1*
cy.createWorkspaceIndexPatterns({
url: `${BASE_PATH}`,
workspaceName: `${WORKSPACE_NAME}`,
workspaceName: `${workspace}`,
indexPattern: 'data_logs_small_time_1',
timefieldName: 'timestamp',
indexPatternHasTimefield: true,
dataSource: DATASOURCE_NAME,
isEnhancement: true,
});

cy.navigateToWorkSpaceHomePage(`${BASE_PATH}`, `${WORKSPACE_NAME}`);
cy.navigateToWorkSpaceHomePage(`${BASE_PATH}`, `${workspace}`);

cy.waitForLoader(true);
cy.getElementByTestId(`datasetSelectorButton`).click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { WORKSPACE_NAME, DATASOURCE_NAME, START_TIME, END_TIME } from './constants';
import {
WORKSPACE_NAME,
DATASOURCE_NAME,
START_TIME,
END_TIME,
} from '../../../../../utils/apps/constants';
import { BASE_PATH, SECONDARY_ENGINE } from '../../../../../utils/constants';

const randomString = Math.random().toString(36).substring(7);
const workspace = `${WORKSPACE_NAME}-${randomString}`;

describe('query enhancement queries', { scrollBehavior: false }, () => {
before(() => {
// Load test data
Expand All @@ -23,14 +31,14 @@ describe('query enhancement queries', { scrollBehavior: false }, () => {
});

// Create workspace and set up index pattern
cy.deleteWorkspaceByName(`${WORKSPACE_NAME}`);
cy.deleteWorkspaceByName(`${workspace}`);
cy.visit('/app/home');
cy.createInitialWorkspaceWithDataSource(`${DATASOURCE_NAME}`, `${WORKSPACE_NAME}`);
cy.createInitialWorkspaceWithDataSource(`${DATASOURCE_NAME}`, `${workspace}`);

// Create and select index pattern for data_logs_small_time_1*
cy.createWorkspaceIndexPatterns({
url: `${BASE_PATH}`,
workspaceName: `${WORKSPACE_NAME}`,
workspaceName: `${workspace}`,
indexPattern: 'data_logs_small_time_1',
timefieldName: 'timestamp',
indexPatternHasTimefield: true,
Expand All @@ -39,61 +47,72 @@ describe('query enhancement queries', { scrollBehavior: false }, () => {
});

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

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

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

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

it('with Lucene', function () {
cy.setQueryLanguage('Lucene');
cy.setTopNavDate(START_TIME, END_TIME);

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

it('with SQL', function () {
cy.setQueryLanguage('OpenSearch SQL');

// default SQL query should be set
// Default SQL query should be set
cy.waitForLoader(true);
cy.getElementByTestId(`osdQueryEditor__multiLine`).contains(
`SELECT * FROM data_logs_small_time_1* LIMIT 10`
);
cy.getElementByTestId(`queryResultCompleteMsg`).should('be.visible');

//query should persist across refresh
// Query should persist across refresh
cy.reload();
cy.getElementByTestId(`queryResultCompleteMsg`).should('be.visible');

cy.getElementByTestId(`osdQueryEditor__multiLine`).type(`{backspace}`);
cy.getElementByTestId('osdQueryEditor__multiLine')
.find('.monaco-editor')
.should('be.visible')
// Ensure editor is in the correct visual state ('vs' is Monaco's default theme)
// This helps verify the editor is fully initialized and ready
.should('have.class', 'vs')
.click()
.find('textarea.inputarea')
.focus()
.type('{backspace}', { force: true });

cy.getElementByTestId(`querySubmitButton`).click();
cy.waitForSearch();
cy.getElementByTestId(`queryResultCompleteMsg`).should('be.visible');
Expand All @@ -102,15 +121,15 @@ describe('query enhancement queries', { scrollBehavior: false }, () => {
it('with PPL', function () {
cy.setQueryLanguage('PPL');

// default PPL query should be set
// Default PPL query should be set
cy.waitForLoader(true);
cy.getElementByTestId(`osdQueryEditor__multiLine`).contains(
`source = data_logs_small_time_1*`
);
cy.waitForSearch();
cy.getElementByTestId(`queryResultCompleteMsg`).should('be.visible');

//query should persist across refresh
// Query should persist across refresh
cy.reload();
cy.getElementByTestId(`queryResultCompleteMsg`).should('be.visible');
cy.verifyHitCount('10,000');
Expand Down
1 change: 1 addition & 0 deletions cypress/utils/apps/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import './data_explorer/commands';
import './query_enhancements/commands';
import './workspace/commands';

Cypress.Commands.add('waitForLoader', (isEnhancement = false) => {
const opts = { log: false };
Expand Down
29 changes: 29 additions & 0 deletions cypress/utils/apps/query_enhancements/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,32 @@ Cypress.Commands.add('deleteDataSourceByName', (dataSourceName) => {
cy.getElementByTestId('editDatasourceDeleteIcon').click();
cy.getElementByTestId('confirmModalConfirmButton').click();
});

Cypress.Commands.add('deleteAllDataSources', () => {
cy.visit('app/dataSources');
cy.waitForLoader(true);
cy.wait(2000);

cy.get('body').then(($body) => {
const hasEmptyState = $body.find('[data-test-subj="datasourceTableEmptyState"]').length > 0;
const hasDataSources = $body.find('[data-test-subj="checkboxSelectAll"]').length > 0;
cy.log('hasEmptyState');
cy.log(hasEmptyState);
cy.log('hasDataSources');
cy.log(hasDataSources);

if (hasEmptyState) {
cy.log('No data sources to delete');
} else if (hasDataSources) {
cy.log('Need to clean out data sources');
cy.getElementByTestId('checkboxSelectAll')
.should('exist')
.should('not.be.disabled')
.check({ force: true });

cy.getElementByTestId('deleteDataSourceConnections').should('be.visible').click();

cy.getElementByTestId('confirmModalConfirmButton').should('be.visible').click();
}
});
});
6 changes: 4 additions & 2 deletions cypress/utils/apps/query_enhancements/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

export const clusterName = 'test_cluster';
export const clusterConnection = 'http://localhost:9200';
export const DATASOURCE_NAME = 'data-logs-1';
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';
1 change: 1 addition & 0 deletions cypress/utils/apps/query_enhancements/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ declare namespace Cypress {
credentials?: { username: string; password: string };
}): Chainable<any>;
deleteDataSourceByName(dataSourceName: string): Chainable<any>;
deleteAllDataSources(): Chainable<any>;
}
}
Loading

0 comments on commit 05a6e0d

Please sign in to comment.