Skip to content

Commit 31b33e6

Browse files
Optimize cy.toolbar: remove extra iterations, ensure chainable return
1 parent a2c7783 commit 31b33e6

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

cypress/e2e/ui/Settings/Application-Settings/schedule.cy.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const textConstants = {
3737
resetButton: 'Reset',
3838

3939
// Config options
40+
configToolbarButton: 'Configuration',
4041
addScheduleConfigOption: 'Add a new Schedule',
4142
deleteScheduleConfigOption: 'Delete this Schedule from the Database',
4243
editScheduleConfigOption: 'Edit this Schedule',
@@ -105,6 +106,7 @@ const {
105106
startTime,
106107
deleteScheduleConfigOption,
107108
schedulesAccordionItem,
109+
configToolbarButton,
108110
flashTypeSuccess,
109111
flashTypeWarning,
110112
flashTypeError,
@@ -120,15 +122,8 @@ const {
120122
browserAlertDeleteConfirmText,
121123
} = textConstants;
122124

123-
function selectConfigMenu(configuration = addScheduleConfigOption) {
124-
cy.get(
125-
`.miq-toolbar-actions .miq-toolbar-group button[title="Configuration"]`
126-
).click();
127-
return cy
128-
.get(
129-
`ul#overflow-menu-1__menu-body button[title="${configuration}"][role="menuitem"]`
130-
)
131-
.click();
125+
function selectConfigMenu(menuOption = addScheduleConfigOption) {
126+
return cy.toolbar(configToolbarButton, menuOption);
132127
}
133128

134129
function addSchedule() {

cypress/support/commands/toolbar.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@ Cypress.Commands.add('toolbar', (toolbarButton, dropdownButton = '') => {
1515
});
1616

1717
if (dropdownButton) {
18-
cy.get('.bx--overflow-menu-options').then((dropdownButtons) => {
18+
return cy.get('.bx--overflow-menu-options').then((dropdownButtons) => {
1919
const buttons = dropdownButtons.children();
20-
const nums = [...Array(buttons.length).keys()];
21-
nums.forEach((index) => {
20+
for (let index = 0; index < buttons.length; index++) {
2221
const button = buttons[index];
23-
if (button && button.innerText && button.innerText.includes(dropdownButton)) {
24-
button.children[0].click();
25-
return;
22+
if (
23+
button &&
24+
button.innerText &&
25+
button.innerText.includes(dropdownButton)
26+
) {
27+
return cy.wrap(button.children[0]).click();
2628
}
27-
});
29+
}
30+
return cy.wrap(null);
2831
});
2932
}
33+
return cy.wrap(null);
3034
});
3135

3236
// toolbarButton: String for the text of the toolbar button to click.

0 commit comments

Comments
 (0)