Skip to content

Commit

Permalink
Apply test preconditions
Browse files Browse the repository at this point in the history
Signed-off-by: Miki <[email protected]>
  • Loading branch information
AMoo-Miki committed Jan 10, 2025
1 parent 69ae8ec commit 0939a23
Show file tree
Hide file tree
Showing 6 changed files with 415 additions and 391 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,49 @@ import { SECONDARY_ENGINE } from '../../../../../utils/constants';
const randomString = Math.random().toString(36).substring(7);
const workspace = `${WORKSPACE_NAME}-${randomString}`;

ifEnabled('WORKSPACE').describe('No Index Pattern Check Test', () => {
before(() => {
// 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-2/data_logs_small_time_2.mapping.json',
],
[
'cypress/fixtures/query_enhancements/data-logs-1/data_logs_small_time_1.data.ndjson',
'cypress/fixtures/query_enhancements/data-logs-2/data_logs_small_time_2.data.ndjson',
]
);
ifEnabled('SECURITY').not('No Index Pattern', () => {
ifEnabled('WORKSPACE').describe('No Index Pattern Check Test', () => {
before(() => {
// 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-2/data_logs_small_time_2.mapping.json',
],
[
'cypress/fixtures/query_enhancements/data-logs-1/data_logs_small_time_1.data.ndjson',
'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',
// Add data source
cy.addDataSource({
name: `${DATASOURCE_NAME}`,
url: `${SECONDARY_ENGINE.url}`,
authType: 'no_auth',
});
// Create workspace
cy.deleteWorkspaceByName(`${workspace}`);
cy.visit('/app/home');
cy.createInitialWorkspaceWithDataSource(`${DATASOURCE_NAME}`, `${workspace}`);
cy.wait(2000);
});
// Create workspace
cy.deleteWorkspaceByName(`${workspace}`);
cy.visit('/app/home');
cy.createInitialWorkspaceWithDataSource(`${DATASOURCE_NAME}`, `${workspace}`);
cy.wait(2000);
});

after(() => {
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');
cy.deleteIndex('data_logs_small_time_2');
});
after(() => {
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');
cy.deleteIndex('data_logs_small_time_2');
});

describe('empty state', () => {
it('no index pattern', function () {
// Go to the Discover page
cy.waitForLoader(true);
cy.getElementByTestId('discoverNoIndexPatterns');
describe('empty state', () => {
it('no index pattern', function () {
// Go to the Discover page
cy.waitForLoader(true);
cy.getElementByTestId('discoverNoIndexPatterns');
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,105 +14,109 @@ import { 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(
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}`);
cy.visit('/app/home');
cy.createInitialWorkspaceWithDataSource(`${DATASOURCE_NAME}`, `${workspace}`);
cy.navigateToWorkSpaceSpecificPage({
workspaceName: workspace,
page: 'discover',
isEnhancement: true,
});
});

afterEach(() => {
cy.deleteWorkspaceByName(`${workspace}`);
});
ifEnabled('SECURITY').not('dataset selector', () => {
ifEnabled('WORKSPACE').describe('dataset selector', () => {
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}`);
cy.visit('/app/home');
cy.createInitialWorkspaceWithDataSource(`${DATASOURCE_NAME}`, `${workspace}`);
cy.navigateToWorkSpaceSpecificPage({
workspaceName: workspace,
page: 'discover',
isEnhancement: true,
});
});

describe('select indices', () => {
it('with SQL as default language', function () {
cy.setIndexAsDataset('data_logs_small_time_1', DATASOURCE_NAME, 'OpenSearch SQL');
afterEach(() => {
cy.deleteWorkspaceByName(`${workspace}`);
});

// SQL should already be selected
cy.getElementByTestId('queryEditorLanguageSelector').should('contain', 'OpenSearch SQL');
cy.waitForLoader(true);
describe('select indices', () => {
it('with SQL as default language', function () {
cy.setIndexAsDataset('data_logs_small_time_1', DATASOURCE_NAME, 'OpenSearch SQL');

// SQL query should be executed and sending back result
cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible');
// SQL should already be selected
cy.getElementByTestId('queryEditorLanguageSelector').should('contain', 'OpenSearch SQL');
cy.waitForLoader(true);

// Switch language to PPL
cy.setQueryLanguage('PPL');
cy.setTopNavDate(START_TIME, END_TIME);
// SQL query should be executed and sending back result
cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible');

cy.waitForLoader(true);
cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible');
});
// Switch language to PPL
cy.setQueryLanguage('PPL');
cy.setTopNavDate(START_TIME, END_TIME);

it('with PPL as default language', function () {
cy.setIndexAsDataset('data_logs_small_time_1', DATASOURCE_NAME, 'PPL');
cy.waitForLoader(true);
cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible');
});

// PPL should already be selected
cy.getElementByTestId('queryEditorLanguageSelector').should('contain', 'PPL');
it('with PPL as default language', function () {
cy.setIndexAsDataset('data_logs_small_time_1', DATASOURCE_NAME, 'PPL');

cy.setTopNavDate(START_TIME, END_TIME);
// PPL should already be selected
cy.getElementByTestId('queryEditorLanguageSelector').should('contain', 'PPL');

cy.waitForLoader(true);
cy.setTopNavDate(START_TIME, END_TIME);

// Query should finish running with timestamp and finish time in the footer
cy.getElementByTestId('queryResultCompleteMsg').should('be.visible');
cy.getElementByTestId('queryEditorFooterTimestamp').should('contain', 'timestamp');
cy.waitForLoader(true);

// Switch language to SQL
cy.setQueryLanguage('OpenSearch SQL');
// Query should finish running with timestamp and finish time in the footer
cy.getElementByTestId('queryResultCompleteMsg').should('be.visible');
cy.getElementByTestId('queryEditorFooterTimestamp').should('contain', 'timestamp');

cy.waitForLoader(true);
cy.getElementByTestId('queryResultCompleteMsg').should('be.visible');
cy.getElementByTestId('queryEditorFooterTimestamp').should('contain', 'timestamp');
});
});
// Switch language to SQL
cy.setQueryLanguage('OpenSearch SQL');

describe('index pattern', () => {
it('create index pattern and select it', function () {
// Create and select index pattern for data_logs_small_time_1*
cy.createWorkspaceIndexPatterns({
workspaceName: workspace,
indexPattern: 'data_logs_small_time_1',
timefieldName: 'timestamp',
indexPatternHasTimefield: true,
dataSource: DATASOURCE_NAME,
isEnhancement: true,
cy.waitForLoader(true);
cy.getElementByTestId('queryResultCompleteMsg').should('be.visible');
cy.getElementByTestId('queryEditorFooterTimestamp').should('contain', 'timestamp');
});
});

cy.navigateToWorkSpaceHomePage(workspace);

cy.waitForLoader(true);
cy.setIndexPatternAsDataset('data_logs_small_time_1*', DATASOURCE_NAME);
// setting OpenSearch SQL as the code following it does not work if this test is isolated
cy.setQueryLanguage('OpenSearch SQL');

cy.waitForLoader(true);
cy.waitForSearch();
cy.getElementByTestId(`queryResultCompleteMsg`).should('be.visible');
describe('index pattern', () => {
it('create index pattern and select it', function () {
// Create and select index pattern for data_logs_small_time_1*
cy.createWorkspaceIndexPatterns({
workspaceName: workspace,
indexPattern: 'data_logs_small_time_1',
timefieldName: 'timestamp',
indexPatternHasTimefield: true,
dataSource: DATASOURCE_NAME,
isEnhancement: true,
});

cy.navigateToWorkSpaceHomePage(workspace);

cy.waitForLoader(true);
cy.setIndexPatternAsDataset('data_logs_small_time_1*', DATASOURCE_NAME);
// setting OpenSearch SQL as the code following it does not work if this test is isolated
cy.setQueryLanguage('OpenSearch SQL');

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

0 comments on commit 0939a23

Please sign in to comment.