Skip to content

Commit

Permalink
[Recent Queries]: add all recent queries tests (opensearch-project#9307)
Browse files Browse the repository at this point in the history
* add max recent queries tests

Signed-off-by: Federico Silva <[email protected]>

* refactor callback function

Signed-off-by: Federico Silva <[email protected]>

* add testid-42 tests

Signed-off-by: Federico Silva <[email protected]>

* add comments

Signed-off-by: Federico Silva <[email protected]>

* add spec to package.json

Signed-off-by: Federico Silva <[email protected]>

* fix testconfig fn name

Signed-off-by: Federico Silva <[email protected]>

* fix clipboard flakiness

Signed-off-by: Federico Silva <[email protected]>

* refactor test preparation

Signed-off-by: Federico Silva <[email protected]>

* fix package.json, yarn.locl and cypress.config.ts

Signed-off-by: Federico Silva <[email protected]>

* Changeset file for PR opensearch-project#9307 created/updated

Signed-off-by: Federico Silva <[email protected]>

* remove element.js references

Signed-off-by: Federico Silva <[email protected]>

* [Documentation] Add alternative Docker Development Environment Setup documentation. (opensearch-project#9362)

* Add alternative Docker Development Environment Setup.

Signed-off-by: Argus Li <[email protected]>

* Changeset file for PR opensearch-project#9362 created/updated

* Use relative link

Signed-off-by: Argus Li <[email protected]>

* Address Suchit's comments.

Signed-off-by: Argus Li <[email protected]>

---------

Signed-off-by: Argus Li <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Signed-off-by: Federico Silva <[email protected]>

* [TESTID-77] Index Patterns Caching functionality for Discover (opensearch-project#9331)

* Create caching test.

Signed-off-by: Argus Li <[email protected]>

* Changeset file for PR opensearch-project#9331 created/updated

* Create caching test.

Signed-off-by: Argus Li <[email protected]>

* Changeset file for PR opensearch-project#9331 created/updated

* Refactor based on opensearch-project#9319

Signed-off-by: Argus Li <[email protected]>

* Update package.json

Signed-off-by: Suchit Sahoo <[email protected]>

* Remove element.js

Signed-off-by: Argus Li <[email protected]>

---------

Signed-off-by: Argus Li <[email protected]>
Signed-off-by: Suchit Sahoo <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Co-authored-by: Suchit Sahoo <[email protected]>
Co-authored-by: Anan Zhuang <[email protected]>
Signed-off-by: Federico Silva <[email protected]>

* comment out tests with dependencies

Signed-off-by: Federico Silva <[email protected]>

* [Discover] fix: Clean up sync URL subscription in Discover plugin topNav (opensearch-project#9316)

* [Discover] fix: Clean up sync URL subscription in Discover plugin topNav

Signed-off-by: Joey Liu <[email protected]>

* Changeset file for PR opensearch-project#9316 created/updated

* Update unit test

Signed-off-by: Joey Liu <[email protected]>

* Revert save modal change

Signed-off-by: Joey Liu <[email protected]>

---------

Signed-off-by: Joey Liu <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Signed-off-by: Federico Silva <[email protected]>

* [TESTID-64,80,UI] Add cypress test for autocomplete feature (opensearch-project#9322)

* [TESTID-64,80,UI] Add cypress test for autocomplete feature

Add tests related to autocomplete. This will close all the issues listed here:

https://github.com/opensearch-project/OpenSearch-Dashboards/issues/assigned/ananzh?q=is%3Aissue%20assignee%3Aananzh%20label%3A%22discover%20autocomplete%22%20

Signed-off-by: Anan <[email protected]>

* Changeset file for PR opensearch-project#9322 created/updated

---------

Signed-off-by: Anan <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Signed-off-by: Federico Silva <[email protected]>

* [Discover] chore: Update query editor loading UI (opensearch-project#9344)

* [Discover] chore: Update query editor loading UI

* Move progress bar position

Signed-off-by: Joey Liu <[email protected]>

* Update loading text font

Signed-off-by: Joey Liu <[email protected]>

* update unit test snapshot

Signed-off-by: Joey Liu <[email protected]>

* Update single line query editor

Signed-off-by: Joey Liu <[email protected]>

* Changeset file for PR opensearch-project#9344 created/updated

* pull doc update

Signed-off-by: Joey Liu <[email protected]>

---------

Signed-off-by: Joey Liu <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Signed-off-by: Federico Silva <[email protected]>

* feat(vis_type_vega): support reading time field (opensearch-project#9152)

* feat(vis_type_vega): support reading time field

Signed-off-by: Yulong Ruan <[email protected]>

* Changeset file for PR opensearch-project#9152 created/updated

* fix time format to use moment.utc

Signed-off-by: Yulong Ruan <[email protected]>

---------

Signed-off-by: Yulong Ruan <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Signed-off-by: Federico Silva <[email protected]>

* [TESTID-17] Add tests for query testing and advanced settings (opensearch-project#9384)

Issue Resolved:
opensearch-project#8934

Signed-off-by: Anan <[email protected]>
Signed-off-by: Federico Silva <[email protected]>

---------

Signed-off-by: Federico Silva <[email protected]>
Signed-off-by: Argus Li <[email protected]>
Signed-off-by: Suchit Sahoo <[email protected]>
Signed-off-by: Joey Liu <[email protected]>
Signed-off-by: Anan <[email protected]>
Signed-off-by: Yulong Ruan <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Co-authored-by: Argus Li <[email protected]>
Co-authored-by: Suchit Sahoo <[email protected]>
Co-authored-by: Anan Zhuang <[email protected]>
Co-authored-by: Joey Liu <[email protected]>
Co-authored-by: Yulong Ruan <[email protected]>
  • Loading branch information
7 people authored and sumukhswamy committed Feb 18, 2025
1 parent 62d9327 commit 495d9b0
Show file tree
Hide file tree
Showing 7 changed files with 358 additions and 6 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/9307.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
- Add all recent queries tests ([#9307](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9307))
7 changes: 7 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { defineConfig } from 'cypress';
import webpackPreprocessor from '@cypress/webpack-preprocessor';
// TODO: import { paste } from 'copy-paste';

module.exports = defineConfig({
defaultCommandTimeout: 60000,
Expand Down Expand Up @@ -76,6 +77,12 @@ function setupNodeEvents(
webpackOptions,
})
);
// TODO: Define the custom task to read clipboard
/* on('task', {
readClipboard() {
return paste(); // Return the clipboard content
},
});*/

return config;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import {
DATASOURCE_NAME,
INDEX_PATTERN_WITH_TIME,
INDEX_WITH_TIME_1,
} from '../../../../../utils/apps/constants';
import { BASE_PATH, PATHS } from '../../../../../utils/constants';
import {
getRandomizedWorkspaceName,
setDatePickerDatesAndSearchIfRelevant,
generateAllTestConfigurations,
} from '../../../../../utils/apps/query_enhancements/shared';
import {
generateRecentQueriesTestConfiguration,
BaseQuery,
TestQueries,
//TODO: QueryRegex,
} from '../../../../../utils/apps/query_enhancements/recent_queries';
import { prepareTestSuite } from '../../../../../utils/helpers';

const workspace = getRandomizedWorkspaceName();
const runRecentQueryTests = () => {
describe('recent queries spec', { testIsolation: true }, () => {
const index = INDEX_PATTERN_WITH_TIME.replace('*', '');
beforeEach(() => {
// Load test data
cy.osd.setupTestData(
PATHS.SECONDARY_ENGINE,
['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.osd.addDataSource({
name: DATASOURCE_NAME,
url: `${PATHS.SECONDARY_ENGINE}`,
authType: 'no_auth',
});
// Create workspace
cy.deleteWorkspaceByName(workspace);
cy.visit('/app/home');
cy.osd.createInitialWorkspaceWithDataSource(DATASOURCE_NAME, workspace);
cy.createWorkspaceIndexPatterns({
workspaceName: workspace,
indexPattern: index,
timefieldName: 'timestamp',
indexPatternHasTimefield: true,
dataSource: DATASOURCE_NAME,
isEnhancement: true,
});

cy.navigateToWorkSpaceSpecificPage({
url: BASE_PATH,
workspaceName: workspace,
page: 'discover',
isEnhancement: true,
});
});

afterEach(() => {
cy.deleteWorkspaceByName(workspace);
cy.osd.deleteDataSourceByName(DATASOURCE_NAME);
// TODO: Modify deleteIndex to handle an array of index and remove hard code
cy.osd.deleteIndex(INDEX_WITH_TIME_1);
});

generateAllTestConfigurations(generateRecentQueriesTestConfiguration)
.filter(Boolean) // removes undefined values
.forEach((config) => {
it(`check max queries for ${config.testName}`, () => {
cy.setDataset(config.dataset, DATASOURCE_NAME, config.datasetType);
cy.setQueryLanguage(config.language);
setDatePickerDatesAndSearchIfRelevant(config.language);
const currentLang = BaseQuery[config.datasetType][config.language];
const currentBaseQuery = currentLang.query;
const currentWhereStatement = currentLang.where;
TestQueries.forEach((query) => {
cy.setQueryEditor(
currentBaseQuery + config.dataset + currentWhereStatement + query,
{},
true
);
});
cy.getElementByTestId('queryEditorFooterToggleRecentQueriesButton').click({
force: true,
});
// only 10 of the 11 queries should be displayed
cy.getElementByTestIdLike('row-').should('have.length', 10);
const reverseList = [...TestQueries].reverse();
const steps = [
{
// only check the table
action: () => {},
},
{
// check table after changing language and returning to the language under test
action: () => {
cy.setQueryLanguage(config.oppositeLang);
cy.setQueryLanguage(config.language);
cy.wrap(null).then(() => {
// force Cypress to run this method in order
reverseList.unshift(config.defaultQuery);
});
},
},
{
// check table after changing dataset and returning to the dataset under test
action: () => {
cy.setIndexAsDataset(
config.alternativeDataset,
DATASOURCE_NAME,
config.language,
"I don't want to use the time filter"
);
cy.setDataset(config.dataset, DATASOURCE_NAME, config.datasetType);
cy.wrap(null).then(() => {
// force Cypress to run this method in order
reverseList.unshift(config.defaultQuery);
});
},
},
{
// check table after visiting a different URL and coming back to the workspace
action: () => {
cy.visit('/app/workspace_initial');
cy.navigateToWorkSpaceSpecificPage({
url: BASE_PATH,
workspaceName: workspace,
page: 'discover',
isEnhancement: true,
});
cy.getElementByTestId('queryEditorFooterToggleRecentQueriesButton').click({
force: true,
});
},
},
];
steps.forEach(({ action }, stepIndex) => {
action();
cy.getElementByTestIdLike('row-').each(($row, rowIndex) => {
let expectedQuery = '';
if (rowIndex === 1 && stepIndex >= 2) {
expectedQuery =
currentBaseQuery + config.alternativeDataset + reverseList[rowIndex];
} else if (rowIndex === 0 && stepIndex >= 1) {
expectedQuery = currentBaseQuery + config.dataset + reverseList[rowIndex];
} else {
expectedQuery =
currentBaseQuery + config.dataset + currentWhereStatement + reverseList[rowIndex];
}
expect($row.text()).to.contain(expectedQuery);
});
});
});

it(`check duplicate query for ${config.testName}`, () => {
cy.setDataset(config.dataset, DATASOURCE_NAME, config.datasetType);
cy.setQueryLanguage(config.language);
setDatePickerDatesAndSearchIfRelevant(config.language);
const currentLang = BaseQuery[config.datasetType][config.language];
const currentBaseQuery = currentLang.query;
const currentWhereStatement = currentLang.where;
const testQueries = [
currentBaseQuery + config.dataset + currentWhereStatement + ' status_code = 504', // valid
currentBaseQuery + config.dataset + currentWhereStatement, // invalid
];
testQueries.forEach((query, index) => {
cy.setQueryEditor(query, {}, true);
cy.setQueryEditor(query, {}, true);
if (!index)
// it remains expanded for the second iteration, no need to expand it again
cy.getElementByTestId('queryEditorFooterToggleRecentQueriesButton').click({
force: true,
});
cy.getElementByTestIdLike('row-').should('have.length', index + 2);
});
});

/* TODO: adding these tests requires adding a dependency OR customizing the execSync function
//const { execSync } = require('child_process');
//console.log(execSync('xclip -selection clipboard -o').toString().trim()); // for Linux
//Caveat: the commands for reading the system's clipboard is OS-dependent.
it(`check running and copying recent queries for ${config.testName}`, () => {
cy.setDataset(config.dataset, DATASOURCE_NAME, config.datasetType);
cy.setQueryLanguage(config.language);
setDatePickerDatesAndSearchIfRelevant(config.language);
// Precondition: run some queries first
const currentLang = BaseQuery[config.datasetType][config.language];
const currentBaseQuery = currentLang.query + config.dataset + currentLang.where;
const queries = [...TestQueries].splice(0, 3);
queries.forEach((query) => {
cy.setQueryEditor(currentBaseQuery + query, {}, true);
});
cy.getElementByTestId('queryEditorFooterToggleRecentQueriesButton').click({
force: true,
});
const expectedQuery = currentBaseQuery + queries[0];
cy.getElementByTestIdLike('row-') // check query in original position
.eq(2)
.focus()
.then(($row) => {
expect($row.text()).to.include(expectedQuery);
});
cy.getElementByTestId('action-run').eq(2).focus().click({ force: true }); // run query again
cy.wait(2000);
cy.getElementByTestIdLike('row-') // check query in altered position
.eq(0)
.focus()
.then(($row) => {
expect($row.text()).to.include(expectedQuery);
});
cy.getElementByTestIdLike('row-') // copy another query to clipboard
.eq(1)
.focus()
.then(($row) => {
cy.get('[aria-label="Copy recent query"]').eq(1).click({ force: true });
cy.wait(1000); // Give the clipboard some time to update
const expectedQuery = $row.text().replace(QueryRegex[config.language], '$1');
cy.get('[aria-label="Copy recent query"]').eq(1).focus();
cy.task('readClipboard').then((clipboardText) => {
expect(clipboardText).to.eq(expectedQuery);
});
});
});*/
});
});
};

prepareTestSuite('Recent Query', runRecentQueryTests);
97 changes: 97 additions & 0 deletions cypress/utils/apps/query_enhancements/recent_queries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { QueryLanguages } from './constants';

export const RecentQueriesDataTypes = {
INDEX_PATTERN: {
name: 'INDEX_PATTERN',
supportedLanguages: [QueryLanguages.SQL, QueryLanguages.PPL],
},
INDEXES: {
name: 'INDEXES',
supportedLanguages: [QueryLanguages.SQL, QueryLanguages.PPL],
},
};

export const BaseQuery = {
INDEX_PATTERN: {
'OpenSearch SQL': {
query: `SELECT * FROM `,
where: ' WHERE ',
},
PPL: {
query: `source = `,
where: ' | where ',
},
},
INDEXES: {
'OpenSearch SQL': {
query: `SELECT * FROM `,
where: ' WHERE ',
},
PPL: {
query: `source = `,
where: ' | where ',
},
},
};

export const TestQueries = [
'bytes_transferred >',
'bytes_transferred < 8000',
'bytes_transferred > 8000',
'status_code = 404',
'status_code = 501',
'status_code = 503',
'status_code = 400',
'status_code = 401',
'status_code = 403',
'status_code = 200',
'event_sequence_number > 10000000',
];

/* // TODO
export const QueryRegex = {
PPL: /.*?(source .*? 8000)(?:.*)/s,
'OpenSearch SQL': /.*?(SELECT .*? 8000)(?:.*)/s,
};*/

/**
* The configurations needed for recent queries tests
* @typedef {Object} RecentQueriesFilteringTestConfig
* @property {string} dataset - the dataset name to use
* @property {QueryEnhancementDataset} datasetType - the type of dataset
* @property {QueryEnhancementLanguage} language - the name of query language as it appears in the dashboard app
* @property {string} testName - the phrase to add to the test case's title
*/

/**
* Returns the SavedSearchTestConfig for the provided dataset, datasetType, and language
* @param {string} dataset - the dataset name
* @param {QueryEnhancementDataset} datasetType - the type of the dataset
* @param {QueryEnhancementLanguageData} language - the relevant data for the query language to use
* @returns {RecentQueriesFilteringTestConfig}
*/
export const generateRecentQueriesTestConfiguration = (dataset, datasetType, language) => {
if (language.name !== 'PPL' && language.name !== 'OpenSearch SQL') {
return; // undefined
}
const oppositeLang = {
PPL: 'OpenSearch SQL',
'OpenSearch SQL': 'PPL',
};
const defaultQuery = language.name === 'PPL' ? '' : ' LIMIT 10';
const customDatasetType = RecentQueriesDataTypes[datasetType].name;
return {
dataset,
datasetType: customDatasetType,
language: language.name,
oppositeLang: oppositeLang[language.name],
alternativeDataset: '.opensearch-sap-log-types-config',
defaultQuery: defaultQuery,
testName: `dataset: ${datasetType} and language: ${language.name}`,
};
};
13 changes: 9 additions & 4 deletions cypress/utils/apps/query_enhancements/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,23 @@ export const generateBaseConfiguration = (dataset, datasetType, language) => {
* @param {Object} [options] - Optional configuration options
* @param {string} [options.indexPattern] - Custom index pattern name (defaults to INDEX_PATTERN_WITH_TIME)
* @param {string} [options.index] - Custom index name (defaults to INDEX_WITH_TIME_1)
* @param {Object.<QueryEnhancementDataset, QueryEnhancementDatasetData>} [options.datasetTypes] - Custom dataset types (defaults to DatasetTypes)
* @returns {object[]}
*/
export const generateAllTestConfigurations = (generateTestConfigurationCallback, options = {}) => {
const { indexPattern = INDEX_PATTERN_WITH_TIME, index = INDEX_WITH_TIME_1 } = options;
return Object.values(DatasetTypes).flatMap((dataset) =>
const {
indexPattern = INDEX_PATTERN_WITH_TIME,
index = INDEX_WITH_TIME_1,
datasetTypes = DatasetTypes,
} = options;
return Object.values(datasetTypes).flatMap((dataset) =>
dataset.supportedLanguages.map((language) => {
let datasetToUse;
switch (dataset.name) {
case DatasetTypes.INDEX_PATTERN.name:
case datasetTypes.INDEX_PATTERN.name:
datasetToUse = indexPattern;
break;
case DatasetTypes.INDEXES.name:
case datasetTypes.INDEXES.name:
datasetToUse = index;
break;
default:
Expand Down
Loading

0 comments on commit 495d9b0

Please sign in to comment.