-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor this PR #9128 * Clean up structures Signed-off-by: Anan <[email protected]>
- Loading branch information
Showing
7 changed files
with
435 additions
and
77 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
75 changes: 75 additions & 0 deletions
75
...re-opensearch-dashboards/opensearch-dashboards/apps/query_enhancements/helpers/commons.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,75 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { | ||
DatasetTypes, | ||
DATASOURCE_NAME, | ||
END_TIME, | ||
INDEX_PATTERN_WITH_TIME, | ||
INDEX_WITH_TIME_1, | ||
QueryLanguages, | ||
START_TIME, | ||
WORKSPACE_NAME, | ||
} from '../../../../../../utils/apps/query_enhancements/constants'; | ||
// TODO: Make generateTestConfiguration more general and move it out from saved_search | ||
import { generateTestConfiguration } from './saved_search'; | ||
|
||
const randomString = Math.random().toString(36); | ||
|
||
/** | ||
* randomized workspace name | ||
* @constant | ||
* @type {string} | ||
* @default | ||
*/ | ||
export const workspaceName = `${WORKSPACE_NAME}-${randomString.substring(7)}`; | ||
|
||
/** | ||
* randomized datasource name | ||
* @constant | ||
* @type {string} | ||
* @default | ||
*/ | ||
export const datasourceName = `${DATASOURCE_NAME}-${randomString.substring(0, 18)}`; | ||
|
||
/** | ||
* Returns an array of test configurations for every query language + dataset permutation | ||
* @returns {SavedSearchTestConfig[]} | ||
*/ | ||
export const generateAllTestConfigurations = ( | ||
indexPatternName = INDEX_PATTERN_WITH_TIME, | ||
indexName = INDEX_WITH_TIME_1 | ||
) => { | ||
return Object.values(DatasetTypes).flatMap((dataset) => | ||
dataset.supportedLanguages.map((language) => { | ||
let datasetToUse; | ||
switch (dataset.name) { | ||
case DatasetTypes.INDEX_PATTERN.name: | ||
datasetToUse = indexPatternName; | ||
break; | ||
case DatasetTypes.INDEXES.name: | ||
datasetToUse = indexName; | ||
break; | ||
default: | ||
throw new Error( | ||
`generateAllTestConfigurations encountered unsupported dataset: ${dataset.name}` | ||
); | ||
} | ||
return generateTestConfiguration(datasetToUse, dataset.name, language); | ||
}) | ||
); | ||
}; | ||
|
||
/** | ||
* Sets the top nav date if it is relevant for the passed language | ||
* @param {QueryEnhancementLanguage} language - query language | ||
*/ | ||
export const setDatePickerDatesAndSearchIfRelevant = (language) => { | ||
if (language === QueryLanguages.SQL.name) { | ||
return; | ||
} | ||
|
||
cy.setTopNavDate(START_TIME, END_TIME); | ||
}; |
File renamed without changes.
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
76 changes: 76 additions & 0 deletions
76
...rch-dashboards/opensearch-dashboards/apps/query_enhancements/helpers/sidebar_filtering.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,76 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** | ||
* Sends a new query via the query multiline editor. | ||
* @param {string} query Query string | ||
* @see https://docs.cypress.io/api/commands/type#Arguments | ||
*/ | ||
export const sendQueryOnMultilineEditor = (query) => { | ||
// remove syntax helper | ||
cy.getElementByTestId('headerGlobalNav').click(); | ||
// Clear default text on the editor by an alternative method, since | ||
// cy.clear() won't work for some reason | ||
cy.get('.view-line') | ||
.invoke('text') | ||
.then(($content) => { | ||
const contentLen = $content.length + 1; | ||
cy.get('.view-line').type('a'); // make sure we're at the end of the string | ||
cy.get('.view-line').type('{backspace}'.repeat(contentLen)); | ||
}); | ||
// Type query | ||
cy.get('.view-line').type(query); | ||
// Send query | ||
cy.getElementByTestId('querySubmitButton').click(); | ||
}; | ||
|
||
/** | ||
* Click on the sidebar collapse button. | ||
* @param {boolean} collapse true for collapsing, false for expanding | ||
*/ | ||
export const clickSidebarCollapseBtn = (collapse = true) => { | ||
if (collapse) { | ||
cy.getElementByTestId('euiResizableButton').trigger('mouseover').click(); | ||
} | ||
cy.get('.euiResizableToggleButton').click({ force: true }); | ||
}; | ||
|
||
/** | ||
* Check the results of the sidebar filter bar search. | ||
* @param {string} search text to look up | ||
* @param {string} assertion the type of assertion that is going to be performed. Example: 'eq', 'include'. If an assertion is not passed, a negative test is performend. | ||
*/ | ||
export const checkSidebarFilterBarResults = (search, assertion) => { | ||
cy.getElementByTestId('fieldFilterSearchInput').type(search, { force: true }); | ||
if (assertion) { | ||
// Get all sidebar fields and iterate over all of them | ||
cy.get('[data-test-subj^="field-"]:not([data-test-subj$="showDetails"])').each(($field) => { | ||
cy.wrap($field) | ||
.should('be.visible') | ||
.invoke('text') | ||
.then(($fieldTxt) => { | ||
cy.wrap($fieldTxt).should(assertion, search); | ||
}); | ||
}); | ||
} else { | ||
// No match should be found | ||
cy.get('[data-test-subj^="field-"]:not([data-test-subj$="showDetails"])').should('not.exist'); | ||
} | ||
cy.get('button[aria-label="Clear input"]').click(); | ||
}; | ||
|
||
/** | ||
* Removes all currently selected fields from the sidebar | ||
*/ | ||
export const removeAllSelectedFields = () => { | ||
cy.get('[data-test-subj="fieldList-selected"]').then(($list) => { | ||
if ($list.find('[data-test-subj^="field-"]').length > 0) { | ||
// Remove all selected fields | ||
$list.find('[data-test-subj^="fieldToggle-"]').each((_, el) => { | ||
cy.wrap(el).click(); | ||
}); | ||
} | ||
}); | ||
}; |
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.