From f731edea0bfe4d059c4b84a3b9bcc1b2631e4138 Mon Sep 17 00:00:00 2001 From: Markus Kuosmanen Date: Mon, 28 Oct 2024 12:46:24 +0200 Subject: [PATCH] Add e2e test for leave confirmation --- cypress/tests/home.cy.ts | 2 +- cypress/tests/mentee.cy.ts | 2 +- cypress/tests/mentor.cy.ts | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/cypress/tests/home.cy.ts b/cypress/tests/home.cy.ts index 7c005484..8949977d 100644 --- a/cypress/tests/home.cy.ts +++ b/cypress/tests/home.cy.ts @@ -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'); diff --git a/cypress/tests/mentee.cy.ts b/cypress/tests/mentee.cy.ts index 62ff3f37..c2411d0a 100644 --- a/cypress/tests/mentee.cy.ts +++ b/cypress/tests/mentee.cy.ts @@ -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(() => { diff --git a/cypress/tests/mentor.cy.ts b/cypress/tests/mentor.cy.ts index 963573e9..80dcf864 100644 --- a/cypress/tests/mentor.cy.ts +++ b/cypress/tests/mentor.cy.ts @@ -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(() => { @@ -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);