Skip to content

Commit 2088fc7

Browse files
Added cypress tests for startpage
1 parent 3e912b5 commit 2088fc7

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

cypress/e2e/ui/settings.cy.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
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+
// Wait for page to load before clicking log out to prevent errors
18+
cy.get('#view\.compare');
19+
cy.get('#menu_item_logout').click();
20+
cy.login();
21+
cy.url().should('include', '/utilization');
22+
23+
cy.menu('Settings', 'My Settings');
24+
cy.get('#display\\.startpage').then((value) => {
25+
expect(value[0].value).to.equal('Overview / Utilization');
26+
});
27+
cy.changeSelect('display\\.startpage', 'Overview / Dashboard');
28+
cy.intercept('PATCH', '/api/users/1').as('settingsUpdate');
29+
cy.contains('button', 'Save').click();
30+
cy.wait('@settingsUpdate').its('response.statusCode').should('eq', 200);
31+
32+
cy.get('#menu_item_logout').click();
33+
cy.login();
34+
cy.url().should('include', '/dashboard');
535
});
636
});

cypress/support/commands/select.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
} else {
13+
throw new Error('No match');
14+
}
15+
});
16+
});

cypress/support/e2e.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import './commands/menu.js';
4949
import './commands/stub_notifications.js';
5050
import './commands/throttle_response.js';
5151
import './commands/toolbar.js';
52+
import './commands/select.js';
5253

5354
// Assertions
5455
import './assertions/expect_alerts.js';

0 commit comments

Comments
 (0)