diff --git a/tests/DFE.FindInformationAcademiesTrusts.CypressTests/cypress/e2e/regression/trusts/contacts-page.cy.ts b/tests/DFE.FindInformationAcademiesTrusts.CypressTests/cypress/e2e/regression/trusts/contacts-page.cy.ts index 93f2b0675..11d09c7b6 100644 --- a/tests/DFE.FindInformationAcademiesTrusts.CypressTests/cypress/e2e/regression/trusts/contacts-page.cy.ts +++ b/tests/DFE.FindInformationAcademiesTrusts.CypressTests/cypress/e2e/regression/trusts/contacts-page.cy.ts @@ -64,6 +64,26 @@ describe("Testing the components of the Trust contacts page", () => { .checkSuccessPopup('Changes made to the SFSO (Schools financial support and oversight) lead name and email were updated') .checkErrorPopupNotPresent(); }); + + it(`Checks that when cancelling the edit of a TRM contact that I am taken back to the previous page and that entered data is not saved`, () => { + contactsPage + .editTrustRelationshipManagerWithoutSaving("Should Notbe Seen", "exittest@education.gov.uk") + .clickContactUpdateCancelButton() + .checkTrustRelationshipManagerIsNotUpdated("Should Notbe Seen", "exittest@education.gov.uk"); + + navigation + .checkCurrentURLIsCorrect(`/trusts/contacts/in-dfe?uid=${uid}`); + }); + + it(`Checks that when cancelling the edit of a SFSO contact that I am taken back to the previous page and that entered data is not saved`, () => { + contactsPage + .editSfsoLeadWithoutSaving("Should Notbe Seen", "exittest@education.gov.uk") + .clickContactUpdateCancelButton() + .checkSfsoLeadIsNotUpdated("Should Notbe Seen", "exittest@education.gov.uk"); + + navigation + .checkCurrentURLIsCorrect(`/trusts/contacts/in-dfe?uid=${uid}`); + }); }); describe(`On the edit Trust relationship manager contact details page for a ${typeOfTrust}`, () => { diff --git a/tests/DFE.FindInformationAcademiesTrusts.CypressTests/cypress/pages/trusts/contactsPage.ts b/tests/DFE.FindInformationAcademiesTrusts.CypressTests/cypress/pages/trusts/contactsPage.ts index 17d61ecb6..d08304e50 100644 --- a/tests/DFE.FindInformationAcademiesTrusts.CypressTests/cypress/pages/trusts/contactsPage.ts +++ b/tests/DFE.FindInformationAcademiesTrusts.CypressTests/cypress/pages/trusts/contactsPage.ts @@ -20,7 +20,8 @@ class ContactsPage { editContacts: { nameInput: () => cy.get('[name="Name"]'), emailInput: () => cy.get('[name="Email"]'), - saveButton: () => cy.contains('Save and continue') + saveButton: () => cy.contains('Save and continue'), + cancelButton: () => cy.contains('Cancel') }, accountingOfficer: { @@ -59,6 +60,12 @@ class ContactsPage { }, }; + + public clickContactUpdateCancelButton(): this { + this.elements.editContacts.cancelButton().click(); + return this; + } + public editTrustRelationshipManager(name: string, email: string): this { const { trustRelationshipManager, editContacts } = this.elements; trustRelationshipManager.editLink().click(); @@ -68,18 +75,46 @@ class ContactsPage { return this; } + public editTrustRelationshipManagerWithoutSaving(name: string, email: string): this { + const { trustRelationshipManager, editContacts } = this.elements; + trustRelationshipManager.editLink().click(); + editContacts.nameInput().clear().type(name); + editContacts.emailInput().clear().type(email); + return this; + } + public checkTrustRelationshipManagerIsSuccessfullyUpdated(name: string, email: string): this { this.elements.trustRelationshipManager.name().should('contain.text', name); this.elements.trustRelationshipManager.email().should('contain.text', email); return this; } + public checkTrustRelationshipManagerIsNotUpdated(dontDisplayName: string, dontDisplayEmail: string): this { + this.elements.trustRelationshipManager.name().should('not.contain.text', dontDisplayName); + this.elements.trustRelationshipManager.email().should('not.contain.text', dontDisplayEmail); + return this; + } + + public checkSfsoLeadIsNotUpdated(dontDisplayName: string, dontDisplayEmail: string): this { + this.elements.schoolsFinancialSupportOversight.name().should('not.contain.text', dontDisplayName); + this.elements.schoolsFinancialSupportOversight.email().should('not.contain.text', dontDisplayEmail); + return this; + } + public editSfsoLead(name: string, email: string): this { - const { schoolsFinancialSupportOversight, editContacts: EditContacts } = this.elements; + const { schoolsFinancialSupportOversight, editContacts } = this.elements; schoolsFinancialSupportOversight.editLink().click(); - EditContacts.nameInput().clear().type(name); - EditContacts.emailInput().clear().type(email); - EditContacts.saveButton().click(); + editContacts.nameInput().clear().type(name); + editContacts.emailInput().clear().type(email); + editContacts.saveButton().click(); + return this; + } + + public editSfsoLeadWithoutSaving(name: string, email: string): this { + const { schoolsFinancialSupportOversight, editContacts } = this.elements; + schoolsFinancialSupportOversight.editLink().click(); + editContacts.nameInput().clear().type(name); + editContacts.emailInput().clear().type(email); return this; }