Skip to content

Commit

Permalink
Add Tests for Simple dataset Selector
Browse files Browse the repository at this point in the history
Signed-off-by: Suchit Sahoo <[email protected]>
  • Loading branch information
LDrago27 committed Jan 23, 2025
1 parent 33cb5b7 commit 3fd4b98
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const runSavedQueriesFlyoutUITests = () => {
// Create workspace
cy.deleteWorkspaceByName(workspaceName);
cy.visit('/app/home');
cy.createInitialWorkspaceWithDataSource(datasourceName, workspaceName);
cy.osd.createInitialWorkspaceWithDataSource(datasourceName, workspaceName);
cy.createWorkspaceIndexPatterns({
workspaceName: workspaceName,
indexPattern: INDEX_PATTERN_WITH_TIME.replace('*', ''),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const runSavedQueriesPopoverUITests = () => {
// Create workspace
cy.deleteWorkspaceByName(workspaceName);
cy.visit('/app/home');
cy.createInitialWorkspaceWithDataSource(datasourceName, workspaceName);
cy.osd.createInitialWorkspaceWithDataSource(datasourceName, workspaceName);
cy.createWorkspaceIndexPatterns({
workspaceName: workspaceName,
indexPattern: INDEX_PATTERN_WITH_TIME.replace('*', ''),
Expand Down
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;

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 indexpattern
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
12 changes: 8 additions & 4 deletions cypress/utils/apps/query_enhancements/saved.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ export const verifyDiscoverPageState = ({
if ([QueryLanguages.SQL.name, QueryLanguages.PPL.name].includes(language)) {
cy.getElementByTestId('osdQueryEditor__multiLine').contains(queryString);
} else {
cy.getElementByTestId('osdQueryEditor__singleLine').contains(queryString);
if (queryString) {
cy.getElementByTestId('osdQueryEditor__singleLine').contains(queryString);
}
}
cy.getElementByTestId('queryEditorLanguageSelector').contains(language);

Expand Down Expand Up @@ -297,9 +299,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
19 changes: 19 additions & 0 deletions cypress/utils/apps/query_enhancements/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,22 @@ export const setDatePickerDatesAndSearchIfRelevant = (language) => {
cy.setTopNavDate(START_TIME, END_TIME);
}
};

/**
* Returns the default query for a given dataset and language combination
* @param {string} datasetName - the dataset name
* @param {QueryEnhancementLanguage} - the name of the query language
* @returns {string}
*/
export const getDefaultQuery = (datasetName, language) => {
switch (language) {
case QueryLanguages.DQL.name:
return '';
case QueryLanguages.Lucene.name:
return '';
case QueryLanguages.PPL.name:
return `source = ${datasetName}`;
case QueryLanguages.SQL.name:
return `SELECT * FROM ${datasetName} LIMIT 10`;
}
};
25 changes: 25 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,25 @@
/*
* 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();
cy.get('[placeholder="Filter options"]').should('not.be.visible');
cy.wait(1000); // Intentional Wait
};

0 comments on commit 3fd4b98

Please sign in to comment.