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

[TESTID-64] Add cypress test for auto query updates when switch dataset #9322

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import {
INDEX_WITH_TIME_1,
INDEX_WITHOUT_TIME_1,
QueryLanguages,
SECONDARY_ENGINE,
} from '../../../../../utils/constants';
import {
getRandomizedWorkspaceName,
getRandomizedDatasourceName,
setDatePickerDatesAndSearchIfRelevant,
} from '../../../../../utils/apps/query_enhancements/shared';
import {
typeAndVerifySuggestion,
typeAndSelectSuggestion,
selectSpecificSuggestion,
verifyFieldValues,
validateQueryResults,
generateAutocompleteTestConfigurations,
getDatasetName,
} from '../../../../../utils/apps/query_enhancements/autocomplete';

const workspaceName = getRandomizedWorkspaceName();
const datasourceName = getRandomizedDatasourceName();

const generateAutocompleteTestConfiguration = (dataset, datasetType, language) => {
const baseConfig = {
dataset,
datasetType,
language: language.name,
testName: `${language.name}-${datasetType}`,
};

return {
...baseConfig,
};
};

const createPPLQueryUsingAutocomplete = (config) => {
cy.getElementByTestId('osdQueryEditor__multiLine')
.find('.monaco-editor')
.should('be.visible')
.should('have.class', 'vs')
.wait(1000)
.within(() => {
// Initial command test - for PPL this would be 'source'
typeAndSelectSuggestion('s', 'source');

// Space and equals operator
typeAndVerifySuggestion('', '=');
selectSpecificSuggestion('=');

// Dataset suggestion
const dataset = getDatasetName('data_logs_small_time_1', config.datasetType);
typeAndVerifySuggestion('', dataset);
selectSpecificSuggestion(dataset);

// Pipe and where command
typeAndVerifySuggestion('', '|');
selectSpecificSuggestion('|');
typeAndSelectSuggestion('w', 'where');

cy.get('.inputarea').type('personal', { force: true });
cy.get('.suggest-widget').should('not.be.visible');
cy.get('.inputarea').type('{backspace}'.repeat('personal'.length));

// Field suggestions
const expectedCategoryValues = ['Application', 'Database', 'Network', 'Security'];
typeAndSelectSuggestion('c', 'category');
typeAndVerifySuggestion('', '=');
selectSpecificSuggestion('=');
verifyFieldValues(expectedCategoryValues);
typeAndSelectSuggestion('App', 'Application');

// Verify 'and' appears in suggestions
typeAndSelectSuggestion('a', 'and');

// After 'and' is selected, space is automatically added
// Verify fields are shown in suggestions and select bytes_transferred
typeAndVerifySuggestion('', 'bytes_transferred');
selectSpecificSuggestion('bytes_transferred');

// Verify '>' appears in suggestions and select it
typeAndVerifySuggestion('', '>');
selectSpecificSuggestion('>');

// Complete the query with compound condition
// Type the value 9500
cy.get('.inputarea').type('9500', { force: true });
});
};

const createDQLQueryUsingAutocomplete = () => {
cy.getElementByTestId('osdQueryEditor__singleLine')
.find('.monaco-editor')
.should('be.visible')
.should('have.class', 'vs')
.wait(1000)
.within(() => {
typeAndSelectSuggestion('c', 'category');
const expectedCategoryValues = ['Application', 'Database', 'Network', 'Security'];
verifyFieldValues(expectedCategoryValues);
typeAndSelectSuggestion('App', 'Application');
typeAndSelectSuggestion('a', 'and');
typeAndVerifySuggestion('', 'bytes_transferred');
selectSpecificSuggestion('bytes_transferred');
typeAndVerifySuggestion('', '>');
selectSpecificSuggestion('>');
cy.get('.inputarea').type('9500', { force: true });
});
};

const createSQLQueryUsingAutocomplete = () => {
cy.getElementByTestId('osdQueryEditor__multiLine')
.find('.monaco-editor')
.should('be.visible')
.should('have.class', 'vs')
.wait(1000)
.within(() => {
// Initial SELECT keyword
typeAndSelectSuggestion('s', 'SELECT');

// Field suggestions after SELECT
typeAndVerifySuggestion('', '*');
selectSpecificSuggestion('*');

// FROM keyword
typeAndSelectSuggestion('f', 'FROM');

// Dataset suggestion
typeAndVerifySuggestion('', 'data_logs_small_time_1');
selectSpecificSuggestion('data_logs_small_time_1');

// WHERE clause
typeAndSelectSuggestion('w', 'WHERE');

// Field suggestions for WHERE clause
typeAndSelectSuggestion('c', 'category');

// Equals operator
typeAndVerifySuggestion('', '=');
selectSpecificSuggestion('=');

// Value suggestion
typeAndSelectSuggestion("'App", "'Application'");

// AND operator
typeAndSelectSuggestion('a', 'AND');

// Second condition
typeAndVerifySuggestion('', 'bytes_transferred');
selectSpecificSuggestion('bytes_transferred');

typeAndVerifySuggestion('', '>');
selectSpecificSuggestion('>');

// Type the value directly
cy.get('.inputarea').type('9500', { force: true });
});
};

export const runAutocompleteTests = () => {
describe('discover autocomplete tests', () => {
beforeEach(() => {
cy.setupTestData(
SECONDARY_ENGINE.url,
[
`cypress/fixtures/query_enhancements/data_logs_1/${INDEX_WITH_TIME_1}.mapping.json`,
`cypress/fixtures/query_enhancements/data_logs_1/${INDEX_WITHOUT_TIME_1}.mapping.json`,
],
[
`cypress/fixtures/query_enhancements/data_logs_1/${INDEX_WITH_TIME_1}.data.ndjson`,
`cypress/fixtures/query_enhancements/data_logs_1/${INDEX_WITHOUT_TIME_1}.data.ndjson`,
]
);
cy.addDataSource({
name: datasourceName,
url: SECONDARY_ENGINE.url,
authType: 'no_auth',
});
cy.deleteWorkspaceByName(`${workspaceName}`);
cy.visit('/app/home');
cy.osd.createInitialWorkspaceWithDataSource(datasourceName, workspaceName);
});

afterEach(() => {
cy.deleteWorkspaceByName(`${workspaceName}`);
cy.deleteDataSourceByName(datasourceName);
cy.deleteIndex('data_logs_small_time_1');
});

generateAutocompleteTestConfigurations(generateAutocompleteTestConfiguration).forEach(
(config) => {
describe(`${config.testName}`, () => {
beforeEach(() => {
if (config.datasetType === 'INDEX_PATTERN') {
cy.createWorkspaceIndexPatterns({
workspaceName: workspaceName,
indexPattern: 'data_logs_small_time_1',
timefieldName: 'timestamp',
dataSource: datasourceName,
isEnhancement: true,
});
}
cy.navigateToWorkSpaceSpecificPage({
workspaceName: workspaceName,
page: 'discover',
isEnhancement: true,
});
});

it('should show and select suggestions progressively', function () {
// Setup
cy.setDataset(config.dataset, datasourceName, config.datasetType);
cy.setQueryLanguage(config.language);
setDatePickerDatesAndSearchIfRelevant(config.language);
cy.clearQueryEditor();

if (config.language === QueryLanguages.PPL.name) {
createPPLQueryUsingAutocomplete(config);
} else if (config.language === QueryLanguages.DQL.name) {
createDQLQueryUsingAutocomplete(config);
} else if (config.language === QueryLanguages.SQL.name) {
createSQLQueryUsingAutocomplete(config);
}

// Run the query
cy.getElementByTestId('querySubmitButton').click();
cy.waitForLoader(true);
cy.wait(1000);
// Validate results meet our conditions
cy.get('tbody tr')
.first()
.find('[data-test-subj="docTableExpandToggleColumn"] button')
.click();
validateQueryResults('bytes_transferred', 9500, '>');
validateQueryResults('category', 'Application');
});
});
}
);
});
};

runAutocompleteTests();
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import {
INDEX_WITH_TIME_1,
INDEX_WITH_TIME_2,
SECONDARY_ENGINE,
QueryLanguages,
} from '../../../../../utils/constants';
import {
getRandomizedWorkspaceName,
getRandomizedDatasourceName,
getDefaultQuery,
} from '../../../../../utils/apps/query_enhancements/shared';
import {
generateAutocompleteTestConfigurations,
LanguageConfigs,
getDatasetName,
} from '../../../../../utils/apps/query_enhancements/autocomplete';

const workspaceName = getRandomizedWorkspaceName();
const datasourceName = getRandomizedDatasourceName();
Copy link
Contributor

Choose a reason for hiding this comment

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

just fyi i am removing the function getRandomizedDatasourceName() in my other open PR: #9319

but if your PR gets merged first, I will take care of it

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah thanks for the remind


const generateAutocompleteTestConfiguration = (dataset, datasetType, language) => {
const baseConfig = {
dataset,
datasetType,
language: language.name,
testName: `${language.name}-${datasetType}`,
};

return {
...baseConfig,
};
};

export const runAutocompleteTests = () => {
describe('discover autocomplete tests', () => {
beforeEach(() => {
cy.setupTestData(
SECONDARY_ENGINE.url,
Copy link
Contributor

Choose a reason for hiding this comment

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

just fyi I am changing this to PATHS.SECONDARY_ENGINE_URL or something like that in my other PR: #9319

but if your PR gets merged first, i will take care of it (Sorry for redundant comments, just moreso leaving a note to myself)

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

[
`cypress/fixtures/query_enhancements/data_logs_1/${INDEX_WITH_TIME_1}.mapping.json`,
`cypress/fixtures/query_enhancements/data_logs_1/${INDEX_WITH_TIME_2}.mapping.json`,
],
[
`cypress/fixtures/query_enhancements/data_logs_1/${INDEX_WITH_TIME_1}.data.ndjson`,
`cypress/fixtures/query_enhancements/data_logs_1/${INDEX_WITH_TIME_2}.data.ndjson`,
]
);
cy.addDataSource({
name: datasourceName,
url: SECONDARY_ENGINE.url,
authType: 'no_auth',
});
cy.deleteWorkspaceByName(workspaceName);
cy.visit('/app/home');
cy.osd.createInitialWorkspaceWithDataSource(datasourceName, workspaceName);
});

afterEach(() => {
cy.deleteWorkspaceByName(workspaceName);
cy.deleteDataSourceByName(datasourceName);
cy.deleteIndex(INDEX_WITH_TIME_1);
cy.deleteIndex(INDEX_WITH_TIME_2);
});

generateAutocompleteTestConfigurations(generateAutocompleteTestConfiguration, {
languageConfig: LanguageConfigs.SQL_PPL,
}).forEach((config) => {
describe(`${config.testName}`, () => {
beforeEach(() => {
if (config.datasetType === 'INDEX_PATTERN') {
cy.createWorkspaceIndexPatterns({
workspaceName: workspaceName,
indexPattern: INDEX_WITH_TIME_1,
timefieldName: 'timestamp',
dataSource: datasourceName,
isEnhancement: true,
});
cy.createWorkspaceIndexPatterns({
workspaceName: workspaceName,
indexPattern: INDEX_WITH_TIME_2,
timefieldName: 'timestamp',
dataSource: datasourceName,
isEnhancement: true,
});
}
cy.navigateToWorkSpaceSpecificPage({
workspaceName: workspaceName,
page: 'discover',
isEnhancement: true,
});
});

it('should update default query when switching index patterns and languages', function () {
// Setup
cy.setDataset(config.dataset, datasourceName, config.datasetType);
cy.setQueryLanguage(config.language);

// Get dataset names based on type
const firstDataset = getDatasetName('data_logs_small_time_1', config.datasetType);
const secondDataset = getDatasetName('data_logs_small_time_2', config.datasetType);

// Verify initial default query
cy.getElementByTestId('osdQueryEditor__multiLine').contains(
getDefaultQuery(firstDataset, config.language)
);

// Switch to second index pattern
cy.setDataset(secondDataset, datasourceName, config.datasetType);

// Verify query updated for new index pattern
cy.getElementByTestId('osdQueryEditor__multiLine').contains(
getDefaultQuery(secondDataset, config.language)
);

// Switch language and verify index pattern maintained
const switchLanguage =
config.language === QueryLanguages.SQL.name
? QueryLanguages.PPL.name
: QueryLanguages.SQL.name;
cy.setQueryLanguage(switchLanguage);
cy.getElementByTestId('osdQueryEditor__multiLine').contains(
getDefaultQuery(secondDataset, switchLanguage)
);
});
});
});
});
};

runAutocompleteTests();
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export const runSideBarTests = () => {
testData.simpleFields.expectedValues,
testData.pplQuery(config.dataset),
testData.sqlQuery(config.dataset),
cconfig.datasetType === DatasetTypes.INDEX_PATTERN.name,
config.datasetType === DatasetTypes.INDEX_PATTERN.name,
config
);
});
Expand Down
Loading
Loading