Skip to content

Commit

Permalink
Add e2e test for leave confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
kuosmark committed Oct 28, 2024
1 parent badc10b commit f731ede
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cypress/tests/home.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('home', () => {
cy.url().should('match', /mentors/);

// return to home page
cy.visit('/');
cy.get('[href="/"]').click();

cy.getByText('Tiedotteet', 'h2').should('be.visible');
cy.getByText('Käsitteet', 'h2').should('be.visible');
Expand Down
2 changes: 1 addition & 1 deletion cypress/tests/mentee.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('mentee profile', () => {
api.deleteAccounts();
api.signUpMentee(mentee);
cy.loginUser(mentee.loginName, mentee.password);
cy.visit('/profile');
cy.visit('/profile/');
});

after(() => {
Expand Down
37 changes: 36 additions & 1 deletion cypress/tests/mentor.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('mentor profile', () => {
api.deleteAccounts();
api.signUpMentor(mentor);
cy.loginUser(mentor.loginName, mentor.password);
cy.visit('/profile');
cy.visit('/profile/');
});

after(() => {
Expand Down Expand Up @@ -136,6 +136,41 @@ describe('mentor profile', () => {
);
});

it('confirmation is needed to leave profile page with unsaved changes', () => {
cy.fillInputByLabel('Julkinen nimimerkki *', NEW_DISPLAY_NAME);
// cy.fillNumberInputByLabel('Syntymävuosi *', NEW_BIRTH_YEAR);
// cy.getInputByLabel('Alue').clear();
// cy.fillInputByLabel('Tilaviesti', NEW_STATUS_MESSAGE);
// cy.getByText('Hylkää muutokset', 'button').click();

// try to navigate away
cy.getByText('Mentorit', 'a').click();
cy.wait(200);

// should show notification
cy.contains('Sinulla on tallentamattomia muutoksia').should('be.visible');

// should stay on profile page after canceling dialog
cy.getByText('Peruuta', 'button').click();
cy.url().should('match', '/profile/');
cy.getInputByLabel('Julkinen nimimerkki *').should(
'have.value',
NEW_DISPLAY_NAME,
);

// confirming leave discards changes
cy.getByText('Mentorit', 'a').click();
cy.wait(200);
cy.getByText('Poistu tallentamatta', 'button').click();
cy.url().should('match', '/mentors/');

cy.get('[href="/profile"]').click();
cy.getInputByLabel('Julkinen nimimerkki *').should(
'have.value',
mentor.displayName,
);
});

it('display name error message is shown for invalid inputs ', () => {
cy.fillInputByLabel('Julkinen nimimerkki *', TOO_SHORT_DISPLAY_NAME);
cy.wait(200);
Expand Down

0 comments on commit f731ede

Please sign in to comment.