-
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
Signed-off-by: Suchit Sahoo <[email protected]>
- Loading branch information
Showing
7 changed files
with
247 additions
and
6 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
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; | ||
|
||
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(); |
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
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
25 changes: 25 additions & 0 deletions
25
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,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 | ||
}; |