Skip to content

Commit

Permalink
Add Tests for Simple dataset Selector (#9255)
Browse files Browse the repository at this point in the history
* Add simple dataset selector tests

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

* Changeset file for PR #9255 created/updated

---------

Signed-off-by: Suchit Sahoo <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit 6c83d4e)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent c285032 commit 87d74ae
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 9 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/cypress_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,18 @@ jobs:
- group: 9
config: standard
test_location: ftr
# Dashboard tests with query enhanced
# Dashboard tests with query enhanced - group 1
- group: 10
config: query_enhanced
test_location: source
# Dashboard tests with no query enhanced
- group: 11
config: dashboard
test_location: source
# Dashboard tests with query enhanced - group 2
- group: 12
config: query_enhanced
test_location: source
container:
image: docker://opensearchstaging/ci-runner:ci-runner-rockylinux8-opensearch-dashboards-integtest-v2
options: --user 1001
Expand Down
2 changes: 2 additions & 0 deletions changelogs/fragments/9255.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Add Tests for Simple Dataset Selector ([#9255](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9255))
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import {
INDEX_PATTERN_WITH_TIME,
INDEX_WITH_TIME_1,
INDEX_PATTERN_WITH_NO_TIME,
INDEX_WITHOUT_TIME_1,
SECONDARY_ENGINE,
} from '../../../../../utils/constants';
import {
getRandomizedWorkspaceName,
getRandomizedDatasourceName,
getDefaultQuery,
setDatePickerDatesAndSearchIfRelevant,
} from '../../../../../utils/apps/query_enhancements/shared';
import { verifyDiscoverPageState } from '../../../../../utils/apps/query_enhancements/saved';
import {
generateSimpleDatasetSelectorTestConfigurations,
validateItemsInSimpleDatasetSelectorDropDown,
} from '../../../../../utils/apps/query_enhancements/simple_dataset_selector';

const workspaceName = getRandomizedWorkspaceName();
const datasourceName = getRandomizedDatasourceName();
const noIndexPatterns = 5; // Determines the no of index patterns that should be in the dropdown for filtering test case

export const runSimpleDatasetSelectorTests = () => {
describe('simple dataset selector selecting an index pattern', () => {
beforeEach(() => {
// Load test data
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`,
]
);
// Add data source
cy.addDataSource({
name: datasourceName,
url: SECONDARY_ENGINE.url,
authType: 'no_auth',
});

// Create workspace
cy.deleteWorkspaceByName(workspaceName);
cy.visit('/app/home');
cy.osd.createInitialWorkspaceWithDataSource(datasourceName, workspaceName);
cy.createWorkspaceIndexPatterns({
workspaceName: workspaceName,
indexPattern: INDEX_PATTERN_WITH_TIME.replace('*', ''),
timefieldName: 'timestamp',
dataSource: datasourceName,
isEnhancement: true,
});
cy.createWorkspaceIndexPatterns({
workspaceName: workspaceName,
indexPattern: INDEX_PATTERN_WITH_NO_TIME.replace('*', ''),
timefieldName: '',
dataSource: datasourceName,
isEnhancement: true,
indexPatternHasTimefield: false,
});
});

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

generateSimpleDatasetSelectorTestConfigurations([
{
indexPattern: INDEX_PATTERN_WITH_TIME,
time: true,
},
{
indexPattern: INDEX_PATTERN_WITH_NO_TIME,
time: false,
},
]).forEach((config) => {
it(`Select ${
config.time ? 'time-based' : 'no-time-based'
} Indexpattern when original language was ${
config.language
} from the simple dataset selector`, () => {
cy.navigateToWorkSpaceSpecificPage({
workspaceName,
page: 'discover',
isEnhancement: true,
});

// Select the original language
cy.setQueryLanguage(config.language);

// Select the index pattern
cy.setIndexPatternAsDataset(config.indexPattern, datasourceName);

// Verify if the language is unchanged, we get a default query populated, and correct dataset is set
verifyDiscoverPageState({
dataset: config.indexPattern,
queryString: getDefaultQuery(config.indexPattern, config.language),
language: config.language,
hitCount: null,
filters: null,
histogram: null,
selectFields: null,
sampleTableData: null,
});

// Verify the presence of timestamp column
// Set the time range
if (config.time) {
setDatePickerDatesAndSearchIfRelevant(config.language);
cy.getElementByTestId('docTableHeaderField').contains('Time');
}
});
});
});

describe('filtering index pattern in simple dataset selector', () => {
beforeEach(() => {
// Load test data
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`,
]
);
// Add data source
cy.addDataSource({
name: datasourceName,
url: SECONDARY_ENGINE.url,
authType: 'no_auth',
});

// Create workspace
cy.deleteWorkspaceByName(workspaceName);
cy.visit('/app/home');
cy.osd.createInitialWorkspaceWithDataSource(datasourceName, workspaceName);

for (let i = 1; i <= noIndexPatterns; i++) {
cy.createWorkspaceIndexPatterns({
workspaceName: workspaceName,
indexPattern: INDEX_PATTERN_WITH_TIME.slice(0, i),
timefieldName: 'timestamp',
dataSource: datasourceName,
isEnhancement: true,
});
}
});

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

it('validate filtering index pattern in simple dataset selector', () => {
cy.navigateToWorkSpaceSpecificPage({
workspaceName,
page: 'discover',
isEnhancement: true,
});

for (let i = 1; i <= noIndexPatterns; i++) {
validateItemsInSimpleDatasetSelectorDropDown(
`::${INDEX_PATTERN_WITH_TIME.slice(0, i)}`,
noIndexPatterns - i + 1
);
}
});
});
};

runSimpleDatasetSelectorTests();
2 changes: 2 additions & 0 deletions cypress/utils/apps/query_enhancements/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ export const DS_API = {
export const DSM_API = '/internal/data-source-management/fetchDataSourceMetaData';

export const INDEX_WITH_TIME_1 = 'data_logs_small_time_1';
export const INDEX_WITHOUT_TIME_1 = 'data_logs_small_no_time_1';
export const INDEX_WITH_TIME_2 = 'data_logs_small_time_2';
export const INDEX_PATTERN_WITH_TIME = 'data_logs_small_time_*';
export const INDEX_PATTERN_WITH_NO_TIME = 'data_logs_small_no_time_*';

/**
* The dataset type that saved search uses
Expand Down
18 changes: 11 additions & 7 deletions cypress/utils/apps/query_enhancements/saved.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,12 @@ export const verifyDiscoverPageState = ({
sampleTableData,
}) => {
cy.getElementByTestId('datasetSelectorButton').contains(dataset);
if ([QueryLanguages.SQL.name, QueryLanguages.PPL.name].includes(language)) {
cy.getElementByTestId('osdQueryEditor__multiLine').contains(queryString);
} else {
cy.getElementByTestId('osdQueryEditor__singleLine').contains(queryString);
if (queryString) {
if ([QueryLanguages.SQL.name, QueryLanguages.PPL.name].includes(language)) {
cy.getElementByTestId('osdQueryEditor__multiLine').contains(queryString);
} else {
cy.getElementByTestId('osdQueryEditor__singleLine').contains(queryString);
}
}
cy.getElementByTestId('queryEditorLanguageSelector').contains(language);

Expand Down Expand Up @@ -303,9 +305,11 @@ export const verifyDiscoverPageState = ({
}
}
// verify first row to ensure sorting is working, but ignore the timestamp field as testing environment might have differing timezones
sampleTableData.forEach(([index, value]) => {
cy.getElementByTestId('osdDocTableCellDataField').eq(index).contains(value);
});
if (sampleTableData) {
sampleTableData.forEach(([index, value]) => {
cy.getElementByTestId('osdDocTableCellDataField').eq(index).contains(value);
});
}
};

/**
Expand Down
26 changes: 26 additions & 0 deletions cypress/utils/apps/query_enhancements/simple_dataset_selector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { DatasetTypes } from './constants';

export const generateSimpleDatasetSelectorTestConfigurations = (indexPatternConfigs) => {
return indexPatternConfigs
.map((indexPatternConfig) =>
DatasetTypes.INDEX_PATTERN.supportedLanguages.map((language) => ({
...indexPatternConfig,
language: language.name,
}))
)
.flat();
};

export const validateItemsInSimpleDatasetSelectorDropDown = (searchString, noItems) => {
cy.getElementByTestId('datasetSelectorButton').click({ force: true });
cy.get('[placeholder="Filter options"]').clear().type(searchString);
cy.get('[data-test-subj*="datasetOption"]').should('have.length', noItems);
cy.getElementByTestId('dscCanvas').click({ force: true });
cy.get('[placeholder="Filter options"]').should('not.exist');
// TODO: Investigate the root cause for the failure wihtout the wait
cy.wait(1000); // Intentional Wait
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@
"release_note:generate": "scripts/use_node scripts/generate_release_note",
"cypress:run-without-security": "env TZ=America/Los_Angeles NO_COLOR=1 cypress run --env SECURITY_ENABLED=false",
"cypress:run-with-security": "env TZ=America/Los_Angeles NO_COLOR=1 cypress run --env SECURITY_ENABLED=true,openSearchUrl=https://localhost:9200,WAIT_FOR_LOADER_BUFFER_MS=500",
"osd:ciGroup10": "echo \"cypress/integration/core_opensearch_dashboards/opensearch_dashboards/apps/query_enhancements/*.js\"",
"osd:ciGroup10": "BASE_PATH='cypress/integration/core_opensearch_dashboards/opensearch_dashboards/apps/query_enhancements' && echo \"$BASE_PATH/saved_search.spec.js,$BASE_PATH/queries.spec.js,$BASE_PATH/a_check.spec.js,$BASE_PATH/dataset_selector.spec.js,$BASE_PATH/s3_dataset.spec.js,$BASE_PATH/simple_dataset_selector.spec.js\"",
"osd:ciGroup11": "echo \"cypress/integration/dashboard_sanity_test.spec.ts\"",
"osd:ciGroup12": "BASE_PATH='cypress/integration/core_opensearch_dashboards/opensearch_dashboards/apps/query_enhancements' && echo \"$BASE_PATH/time_range_selection.spec.js,$BASE_PATH/saved_queries.spec.js,$BASE_PATH/language_specific_display.spec.js,$BASE_PATH/field_display_filtering.spec.js\"",
"generate:opensearchsqlantlr": "./node_modules/antlr4ng-cli/index.js -Dlanguage=TypeScript -o ./src/plugins/data/public/antlr/opensearch_sql/.generated -visitor -no-listener -Xexact-output-dir ./src/plugins/data/public/antlr/opensearch_sql/grammar/OpenSearchSQLLexer.g4 ./src/plugins/data/public/antlr/opensearch_sql/grammar/OpenSearchSQLParser.g4",
"generate:opensearchpplantlr": "./node_modules/antlr4ng-cli/index.js -Dlanguage=TypeScript -o ./src/plugins/data/public/antlr/opensearch_ppl/.generated -visitor -no-listener -Xexact-output-dir ./src/plugins/data/public/antlr/opensearch_ppl/grammar/OpenSearchPPLLexer.g4 ./src/plugins/data/public/antlr/opensearch_ppl/grammar/OpenSearchPPLParser.g4"
},
Expand Down

0 comments on commit 87d74ae

Please sign in to comment.