grafana/e2e/utils/flows/selectOption.ts
Ashley Harrison 247d91be2b
Chore: remove wrapping of cy in the e2e object (#74650)
* remove cy. wrapping as e2e().

* make trace-view-scrolling more stable and remove waits

* improve stability more
2023-09-11 11:20:54 +01:00

42 lines
1.1 KiB
TypeScript

import { e2e } from '../index';
export interface SelectOptionConfig {
clickToOpen?: boolean;
container: any;
forceClickOption?: boolean;
optionText: string | RegExp;
}
// @todo this actually returns type `Cypress.Chainable`
export const selectOption = (config: SelectOptionConfig): any => {
const fullConfig: SelectOptionConfig = {
clickToOpen: true,
forceClickOption: false,
...config,
};
const { clickToOpen, container, forceClickOption, optionText } = fullConfig;
container.within(() => {
if (clickToOpen) {
cy.get('[class$="-input-suffix"]', { timeout: 1000 }).then((element) => {
expect(Cypress.dom.isAttached(element)).to.eq(true);
cy.get('[class$="-input-suffix"]', { timeout: 1000 }).click({ force: true });
});
}
});
return e2e.components.Select.option()
.filter((_, { textContent }) => {
if (textContent === null) {
return false;
} else if (typeof optionText === 'string') {
return textContent.includes(optionText);
} else {
return optionText.test(textContent);
}
})
.scrollIntoView()
.click({ force: forceClickOption });
};