Skip to content

Commit 5fd0f94

Browse files
Added cypress tests for startpage
1 parent b4052f8 commit 5fd0f94

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

cypress/e2e/ui/settings.cy.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
/* eslint-disable no-undef */
2-
describe('GTL', () => {
2+
describe('Settings > My Settings', () => {
33
beforeEach(() => {
44
cy.login();
5+
cy.menu('Settings', 'My Settings');
6+
});
7+
8+
it('Saves the start page setting', () => {
9+
cy.get('#display\\.startpage').then((value) => {
10+
expect(value[0].value).to.be.oneOf(['', 'Overview / Dashboard']);
11+
});
12+
cy.changeSelect('display\\.startpage', 'Overview / Utilization');
13+
cy.intercept('PATCH', '/api/users/1').as('settingsUpdate');
14+
cy.contains('button', 'Save').click();
15+
cy.wait('@settingsUpdate').its('response.statusCode').should('eq', 200);
16+
17+
cy.get('#menu_item_logout').click();
18+
cy.login();
19+
cy.url().should('include', '/utilization');
20+
21+
cy.menu('Settings', 'My Settings');
22+
cy.get('#display\\.startpage').then((value) => {
23+
expect(value[0].value).to.equal('Overview / Utilization');
24+
});
25+
cy.changeSelect('display\\.startpage', 'Overview / Dashboard');
26+
cy.intercept('PATCH', '/api/users/1').as('settingsUpdate');
27+
cy.contains('button', 'Save').click();
28+
cy.wait('@settingsUpdate').its('response.statusCode').should('eq', 200);
29+
30+
cy.get('#menu_item_logout').click();
31+
cy.login();
32+
cy.url().should('include', '/dashboard');
533
});
634
});

cypress/support/commands/select.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* eslint-disable no-undef */
2+
3+
// selectId: String of the ID of the select element to interact with.
4+
// optionToSelect: String of the option to select from the dropdown.
5+
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+
}
13+
});
14+
});

cypress/support/e2e.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import './commands/menu.js'
4747
import './commands/stub_notifications.js'
4848
import './commands/toolbar.js'
4949
import './commands/throttle_response.js'
50+
import './commands/select.js'
5051

5152
// Assertions
5253
import './assertions/expect_rates_table.js';

0 commit comments

Comments
 (0)