Skip to content

Commit 11a9881

Browse files
Update cypress tests
1 parent 3b6f01a commit 11a9881

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

cypress/e2e/ui/settings.cy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('Settings > My Settings', () => {
1010
expect(value[0].value).to.be.oneOf(['', 'Overview / Dashboard']);
1111
});
1212
cy.changeSelect('display\\.startpage', 'Overview / Utilization');
13-
cy.intercept('PATCH', '/api/users/1').as('settingsUpdate');
13+
cy.intercept('PATCH', '/api/users/*').as('settingsUpdate');
1414
cy.contains('button', 'Save').click();
1515
cy.wait('@settingsUpdate').its('response.statusCode').should('eq', 200);
1616

@@ -25,7 +25,7 @@ describe('Settings > My Settings', () => {
2525
expect(value[0].value).to.equal('Overview / Utilization');
2626
});
2727
cy.changeSelect('display\\.startpage', 'Overview / Dashboard');
28-
cy.intercept('PATCH', '/api/users/1').as('settingsUpdate');
28+
cy.intercept('PATCH', '/api/users/*').as('settingsUpdate');
2929
cy.contains('button', 'Save').click();
3030
cy.wait('@settingsUpdate').its('response.statusCode').should('eq', 200);
3131

cypress/support/commands/select.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,27 @@
33
// selectId: String of the ID of the select element to interact with.
44
// optionToSelect: String of the option to select from the dropdown.
55
Cypress.Commands.add('changeSelect', (selectId, optionToSelect) => {
6-
cy.get(`#${selectId}`).click();
7-
cy.get('.bx--list-box__menu-item__option').then((options) => {
8-
const optionArray = Cypress.$.makeArray(options);
9-
const match = optionArray.find((el) => el.innerText.trim() === optionToSelect);
10-
if (match) {
11-
cy.wrap(match).click();
12-
} else {
13-
throw new Error('No match');
14-
}
6+
// First, get the select element and store its text
7+
let selectElementText = '';
8+
cy.get(`#${selectId}`).then((selectElement) => {
9+
// Get the currently displayed text in the select element
10+
selectElementText = selectElement.text().trim();
11+
// Click to open the dropdown
12+
cy.wrap(selectElement).click();
13+
}).then(() => {
14+
// Now find the options and try to select the requested one
15+
cy.get('.bx--list-box__menu-item__option').then((options) => {
16+
const optionArray = Cypress.$.makeArray(options);
17+
const match = optionArray.find((el) => el.innerText.trim() === optionToSelect);
18+
19+
if (match) {
20+
cy.wrap(match).click();
21+
} else {
22+
// Include both the requested option and the select element's text in the error
23+
cy.logAndThrowError(
24+
`Could not find "${optionToSelect}" in select element with text "${selectElementText}"`
25+
);
26+
}
27+
});
1528
});
1629
});

0 commit comments

Comments
 (0)