Skip to content
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

[Backport 2.9] Improve date selection across versions of OUI #782

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cypress/utils/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,25 @@ Cypress.Commands.add('getElementByTestId', (testId, options = {}) => {
return cy.get(`[data-test-subj="${testId}"]`, options);
});

Cypress.Commands.add('getElementsByTestIds', (testIds, options = {}) => {
const selectors = [testIds]
.flat(Infinity)
.map((testId) => `[data-test-subj="${testId}"]`);
return cy.get(selectors.join(','), options);
});

Cypress.Commands.add(
'whenTestIdNotFound',
(testIds, callbackFn, options = {}) => {
const selectors = [testIds]
.flat(Infinity)
.map((testId) => `[data-test-subj="${testId}"]`);
cy.get('body', options).then(($body) => {
if ($body.find(selectors.join(',')).length === 0) callbackFn();
});
}
);

Cypress.Commands.add('createIndex', (index, policyID = null, settings = {}) => {
cy.request('PUT', `${Cypress.env('openSearchUrl')}/${index}`, settings);
if (policyID != null) {
Expand Down
28 changes: 22 additions & 6 deletions cypress/utils/dashboards/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,29 @@ Cypress.Commands.add('setTopNavDate', (start, end, submit = true) => {
message: `Start: ${start} :: End: ${end}`,
});

// Click date picker
cy.getElementByTestId('superDatePickerShowDatesButton', opts).click(opts);

// Click start date
cy.getElementByTestId('superDatePickerstartDatePopoverButton', opts).click(
/* Find any one of the two buttons that change/open the date picker:
* * if `superDatePickerShowDatesButton` is found, it will switch the mode to dates
* * in some versions of OUI, the switch will open the date selection dialog as well
* * if `superDatePickerstartDatePopoverButton` is found, it will open the date selection dialog
*/
cy.getElementsByTestIds(
['superDatePickerstartDatePopoverButton', 'superDatePickerShowDatesButton'],
opts
);
)
.should('be.visible')
.invoke('attr', 'data-test-subj')
.then((testId) => {
cy.getElementByTestId(testId, opts).should('be.visible').click(opts);
});

/* While we surely are in the date selection mode, we don't know if the date selection dialog
* is open or not. Looking for a tab and if it is missing, click on the dialog opener.
*/
cy.whenTestIdNotFound('superDatePickerAbsoluteTab', () => {
cy.getElementByTestId('superDatePickerstartDatePopoverButton', opts)
.should('be.visible')
.click(opts);
});

// Click absolute tab
cy.getElementByTestId('superDatePickerAbsoluteTab', opts).click(opts);
Expand Down
20 changes: 19 additions & 1 deletion cypress/utils/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,25 @@
/// <reference types="cypress" />

declare namespace Cypress {
interface Chainable<Subject> {
interface Chainable<Subject> { /**
* Call a function when an element with a test id cannot be found
* @example
* cy.whenTestIdNotFound(['query', 'puery'], () => {...})
*/
whenTestIdNotFound<S = any>(
testIds: string | string[],
callbackFn: void,
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>
): Chainable<S>;
/**
* Get elements by their test ids
* @example
* cy.getElementsByTestIds(['query', 'puery'])
*/
getElementsByTestIds<S = any>(
testIds: string | string[],
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>
): Chainable<S>;
/**
* Get an element by its test id
* @example
Expand Down
Loading