mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* remove cy. wrapping as e2e(). * make trace-view-scrolling more stable and remove waits * improve stability more
42 lines
1.1 KiB
TypeScript
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 });
|
|
};
|