-
Notifications
You must be signed in to change notification settings - Fork 935
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Tests for Simple dataset Selector (#9255)
* 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
Showing
7 changed files
with
239 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
191 changes: 191 additions & 0 deletions
191
..._dashboards/opensearch_dashboards/apps/query_enhancements/simple_dataset_selector.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
cypress/utils/apps/query_enhancements/simple_dataset_selector.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters