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
Markus Kuosmanen committed Oct 28, 2024
1 parent 6be222b commit dc6d60d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
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
32 changes: 32 additions & 0 deletions cypress/tests/mentor.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,38 @@ describe('mentor profile', () => {
);
});

it('confirmation is needed to leave profile page with unsaved changes', () => {
cy.fillInputByLabel('Julkinen nimimerkki *', NEW_DISPLAY_NAME);

// 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.wait(200);
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 dc6d60d

Please sign in to comment.