-
Notifications
You must be signed in to change notification settings - Fork 936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TESTID-116, TESTID-115, TESTID-61 - Tests for Saved Searches in Dashboard #9288
Merged
LDrago27
merged 7 commits into
opensearch-project:main
from
angle943:saved-search-in-dashboards
Jan 30, 2025
+189
−1
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6174c1a
add tests for saved searches in dashboard: TESTID-116, TESTID-115, TE…
angle943 69d2f80
Changeset file for PR #9288 created/updated
opensearch-changeset-bot[bot] 7771a7b
update test case to change date to where we have some results
angle943 d6d1838
Merge remote-tracking branch 'origin/saved-search-in-dashboards' into…
angle943 8ef5611
Merge branch 'main' into saved-search-in-dashboards
angle943 8e38749
Merge branch 'main' into saved-search-in-dashboards
angle943 3595893
add to ci group 12
angle943 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
test: | ||
- Add tests for saved searches in dashboards ([#9288](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9288)) |
156 changes: 156 additions & 0 deletions
156
...shboards/opensearch_dashboards/apps/query_enhancements/saved_search_in_dashboards.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,156 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { | ||
DatasetTypes, | ||
INDEX_PATTERN_WITH_TIME, | ||
INDEX_WITH_TIME_1, | ||
INDEX_WITH_TIME_2, | ||
QueryLanguages, | ||
SECONDARY_ENGINE, | ||
START_TIME, | ||
} from '../../../../../utils/constants'; | ||
import { | ||
getRandomizedWorkspaceName, | ||
getRandomizedDatasourceName, | ||
setDatePickerDatesAndSearchIfRelevant, | ||
} from '../../../../../utils/apps/query_enhancements/shared'; | ||
import { | ||
postRequestSaveSearch, | ||
generateSavedTestConfiguration, | ||
getExpectedHitCount, | ||
loadSavedSearchFromDashboards, | ||
navigateToDashboardAndOpenSavedSearchPanel, | ||
} from '../../../../../utils/apps/query_enhancements/saved'; | ||
|
||
const workspaceName = getRandomizedWorkspaceName(); | ||
const datasourceName = getRandomizedDatasourceName(); | ||
|
||
export const runSavedSearchTests = () => { | ||
describe('saved search in dashboards', () => { | ||
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_2/${INDEX_WITH_TIME_2}.mapping.json`, | ||
], | ||
[ | ||
`cypress/fixtures/query_enhancements/data_logs_1/${INDEX_WITH_TIME_1}.data.ndjson`, | ||
`cypress/fixtures/query_enhancements/data_logs_2/${INDEX_WITH_TIME_2}.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, | ||
}); | ||
}); | ||
|
||
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_WITH_TIME_2); | ||
}); | ||
|
||
it('Load a saved search', () => { | ||
const config = generateSavedTestConfiguration( | ||
INDEX_PATTERN_WITH_TIME, | ||
DatasetTypes.INDEX_PATTERN.name, | ||
QueryLanguages.DQL | ||
); | ||
// using a POST request to create a saved search to load | ||
postRequestSaveSearch(config); | ||
|
||
loadSavedSearchFromDashboards(config, workspaceName); | ||
|
||
// verify that there are results | ||
cy.getElementByTestId('docTableField').should('be.visible'); | ||
|
||
const expectedHitCount = getExpectedHitCount(config.datasetType, config.language); | ||
cy.getElementByTestId('osdDocTablePagination').contains(new RegExp(`of ${expectedHitCount}`)); | ||
// verify that the proper fields are loaded as well as sorting is working as expected | ||
config.sampleTableData.forEach(([index, value]) => { | ||
cy.getElementByTestId('osdDocTableCellDataField').eq(index).contains(value); | ||
}); | ||
}); | ||
|
||
it('Changing the time range updates the saved search elements in dashboards', () => { | ||
const config = generateSavedTestConfiguration( | ||
INDEX_PATTERN_WITH_TIME, | ||
DatasetTypes.INDEX_PATTERN.name, | ||
QueryLanguages.DQL | ||
); | ||
// using a POST request to create a saved search to load | ||
postRequestSaveSearch(config); | ||
|
||
loadSavedSearchFromDashboards(config, workspaceName); | ||
|
||
// verify that there are results | ||
const expectedHitCount = getExpectedHitCount(config.datasetType, config.language); | ||
cy.getElementByTestId('osdDocTablePagination').contains(new RegExp(`of ${expectedHitCount}`)); | ||
|
||
// set a date where there should different number of results | ||
setDatePickerDatesAndSearchIfRelevant( | ||
config.language, | ||
START_TIME, | ||
'Oct 1, 2022 @ 00:00:00.000' | ||
); | ||
cy.getElementByTestId('osdDocTablePagination').contains(/of 15/); | ||
}); | ||
|
||
it('Show valid saved searches', () => { | ||
const dqlConfig = generateSavedTestConfiguration( | ||
INDEX_PATTERN_WITH_TIME, | ||
DatasetTypes.INDEX_PATTERN.name, | ||
QueryLanguages.DQL | ||
); | ||
const luceneConfig = generateSavedTestConfiguration( | ||
INDEX_PATTERN_WITH_TIME, | ||
DatasetTypes.INDEX_PATTERN.name, | ||
QueryLanguages.Lucene | ||
); | ||
const sqlConfig = generateSavedTestConfiguration( | ||
INDEX_PATTERN_WITH_TIME, | ||
DatasetTypes.INDEX_PATTERN.name, | ||
QueryLanguages.SQL | ||
); | ||
const pplConfig = generateSavedTestConfiguration( | ||
INDEX_PATTERN_WITH_TIME, | ||
DatasetTypes.INDEX_PATTERN.name, | ||
QueryLanguages.PPL | ||
); | ||
// using a POST request to create a saved search to load | ||
postRequestSaveSearch(dqlConfig); | ||
postRequestSaveSearch(luceneConfig); | ||
postRequestSaveSearch(sqlConfig); | ||
postRequestSaveSearch(pplConfig); | ||
|
||
navigateToDashboardAndOpenSavedSearchPanel(workspaceName); | ||
cy.getElementByTestId(`savedObjectTitle${dqlConfig.saveName}`).should('exist'); | ||
cy.getElementByTestId(`savedObjectTitle${luceneConfig.saveName}`).should('exist'); | ||
cy.getElementByTestId(`savedObjectTitle${sqlConfig.saveName}`).should('not.exist'); | ||
cy.getElementByTestId(`savedObjectTitle${pplConfig.saveName}`).should('not.exist'); | ||
}); | ||
}); | ||
}; | ||
|
||
runSavedSearchTests(); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets change to a valid time range where we have atleast some hits which is different from the expected hits in the config. That will ensure that changing time ranges actually updates the underlying search.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok sounds good. i'm a bit concerned though about timezone differences between my env and the CI/CD (or does that matter)? Lets see though, i'll push out a change that works on my end