From 08fe575aa78dab897ee279a3e1868f4629388672 Mon Sep 17 00:00:00 2001 From: FahadDarw Date: Fri, 17 May 2024 17:41:13 +0100 Subject: [PATCH] Cypress refactor --- .../application_Form_tests.cy.js | 95 +++++++++++++++++++ .../cypress/pages/applicationFormTaskList.js | 85 +++++++++++++++++ .../cypress/pages/projectTaskList.js | 4 + .../Pages/ApplicationForm/Index.cshtml | 4 +- .../Pages/FormAMat/Index.cshtml | 4 +- .../Pages/Shared/_Layout.cshtml | 2 +- .../Pages/Shared/_ProjectHeader.cshtml | 2 +- .../Pages/Shared/_SubMenu.cshtml | 4 +- 8 files changed, 192 insertions(+), 8 deletions(-) create mode 100644 Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests/cypress/e2e/Core-journeys/application_Form_tests.cy.js create mode 100644 Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests/cypress/pages/applicationFormTaskList.js diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests/cypress/e2e/Core-journeys/application_Form_tests.cy.js b/Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests/cypress/e2e/Core-journeys/application_Form_tests.cy.js new file mode 100644 index 000000000..af3d32752 --- /dev/null +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests/cypress/e2e/Core-journeys/application_Form_tests.cy.js @@ -0,0 +1,95 @@ +import '../../support/commands'; +import projectTaskList from "../../pages/projectTaskList"; +const applicationFormTaskList = require('../../pages/applicationFormTaskList'); + +describe('Test Application Form for Voluntary and Form a MAT', { tags: ['@dev', '@stage'] }, () => { + + beforeEach(() => { + projectTaskList.getHomePage(); + }); + + it('Should filter and select the project, then verify details of Voluntary', () => { + + // Step 1: Filter search + applicationFormTaskList.filterSearch('Fahads Cypress Trust'); + + // Step 2: Verify the title and route + applicationFormTaskList.checkTitle('Fahads Cypress Trust'); + applicationFormTaskList.checkRoute('Voluntary conversion'); + + // Step 3: Select the first search result + applicationFormTaskList.selectFirstSearchResult(); + + // Step 4: Click on school application form + applicationFormTaskList.clickSchoolApplicationForm(); + + //Step 4.1: Check URL contains to contain school-application-form + applicationFormTaskList.checkUrlContainsSchoolApplicationForm(); + + //Step 4.2: Check the route + applicationFormTaskList.checkRouteAppForm('Voluntary conversion'); + + // Step 5: Check the table contents + const expectedContents = [ + 'Overview', + 'About the conversion', + 'Further information', + 'Finances', + 'Future pupil numbers', + 'Land and buildings', + 'Pre-opening support grant', + 'Consultation', + 'Declaration' + ]; + applicationFormTaskList.checkTableContents(expectedContents); + + // Step 6: Check Overview1_value + applicationFormTaskList.checkElementText('[test-id="Overview1_value"]', 'PLYMOUTH CAST with Plymstock School'); + + // Step 7: Check Application reference + applicationFormTaskList.checkElementText('[test-id="Overview2"]', 'A2B_124378'); + }); + + it('Should filter and select the project, then verify details of a Form a MAT project', () => { + + // Step 1: Filter search + applicationFormTaskList.clickFormAMAT(); + applicationFormTaskList.filterSearch('Fahads Cypress Trust'); + + + // Step 2: Select the first search result + applicationFormTaskList.selectFirstSearchResultFormAMAT(); + + //Step 2.1: Check URL contains to contain school-application-form + applicationFormTaskList.checkUrlContainsschoolsinthismat(); +//step 2.2: Click on the first project + applicationFormTaskList.selectFirstProjectFormAMAT(); + //Step 2.3: Check the route + applicationFormTaskList.checkRouteAppForm('Form a MAT Voluntary conversion'); + // Step 3: Click on school application form + applicationFormTaskList.clickSchoolApplicationFormForFormAMAT(); + + // Step 4: Check the table contents + + const expectedContents = [ + 'Overview', + 'Trust information', + 'Key people within the trust', + 'About the conversion', + 'Further information', + 'Finances', + 'Future pupil numbers', + 'Land and buildings', + 'Pre-opening support grant', + 'Consultation', + 'Declaration' + ]; + applicationFormTaskList.checkTableContents(expectedContents); + + // Step 5: Check Overview1_value + applicationFormTaskList.checkElementText('[test-id="Overview1_value"]', 'Plymouth with Fahads Cypress Trust'); + + // Step 6: Check Application reference + applicationFormTaskList.checkElementText('[test-id="Overview2"]', 'A2B_124335'); + }); +}); diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests/cypress/pages/applicationFormTaskList.js b/Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests/cypress/pages/applicationFormTaskList.js new file mode 100644 index 000000000..7e10389e7 --- /dev/null +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests/cypress/pages/applicationFormTaskList.js @@ -0,0 +1,85 @@ +class ApplicationFormTaskList { + // Method to interact with the filter search input + filterSearch(title) { + cy.get('[data-cy="select-projectlist-filter-title"]').type(title); + cy.get('[data-cy="select-projectlist-filter-apply"]').click(); + } + + // Method to select the first search result + selectFirstSearchResult() { + cy.get('#school-name-0').click(); + } + + // Method to select the first search result for Form a MAT + selectFirstSearchResultFormAMAT() { + cy.get('#trust-name-0').click(); + } + + // Method to check the route + checkRoute(expectedRoute) { + cy.get('#type-and-route-0 > span').should('contain', expectedRoute); + } + + // Method to check the page title + checkTitle(title) { + cy.get('#school-name-0').should('contain', title); + } + + //method to click on the first form a mat project + selectFirstProjectFormAMAT() { + cy.get('#school-name-0').click(); + } + + // Method to click on school application form + clickSchoolApplicationForm() { + + cy.get('[data-cy="school_application_form"]').click(); + } + // Method to click on school application form for Form a MAT page + clickSchoolApplicationFormForFormAMAT() { + + cy.get('[data-cy="school_application_form_formamat"]').click(); + } + // Method to click on school application form First project + clickSchoolApplicationFormFirstProjet() { + + cy.get('#school-name-0').click(); + } + + // Method to check the url contains school-application-form + checkUrlContainsSchoolApplicationForm() { + cy.url().should('contain', 'school-application-form'); + } + + // Method to check the url contains schools-in-this-mat + checkUrlContainsschoolsinthismat() { + cy.url().should('contain', 'schools-in-this-mat'); + } + + // Method to check the route in Application Form page + checkRouteAppForm(expectedRouteAppRoute) { + + cy.get('[data-cy="route"]').should('contain', expectedRouteAppRoute); + + } + // Method to check the contents of the table + checkTableContents(expectedContents) { + cy.get('[data-cy="content-Table"]').within(() => { + expectedContents.forEach((content, index) => { + cy.get('[data-cy="contents_list_items"]').eq(index).should('contain', content); + }); + }); + } + + // Method to check specific elements for expected text + checkElementText(selector, expectedText) { + cy.get(selector).should('contain', expectedText); + } + + clickFormAMAT() { + cy.get('[data-cy="formAMatLink"]').click(); + } +} + + module.exports = new ApplicationFormTaskList(); + \ No newline at end of file diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests/cypress/pages/projectTaskList.js b/Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests/cypress/pages/projectTaskList.js index da0effb04..d590331b0 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests/cypress/pages/projectTaskList.js +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions.CypressTests/cypress/pages/projectTaskList.js @@ -96,6 +96,10 @@ export default class ProjectTaskList extends BasePage { cy.checkPath(this.path) return cy.get(this.selectors.riskAndIssuesStatus) } + + static getHomePage() { + cy.visit(`${Cypress.env('url')}`) + } static selectLA() { cy.checkPath(this.path) diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/ApplicationForm/Index.cshtml b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/ApplicationForm/Index.cshtml index 18ea33f59..ed463c820 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/ApplicationForm/Index.cshtml +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Pages/ApplicationForm/Index.cshtml @@ -17,12 +17,12 @@

School application form

-