From 1ba25b69f9dd8266798f200a5a33c8f7b364f72e Mon Sep 17 00:00:00 2001 From: Sweety Mariam John <162119856+sweetymj@users.noreply.github.com> Date: Fri, 7 Feb 2025 11:32:08 +0000 Subject: [PATCH] Feature/RA-247-swap vos pin credit details page tests (#19) * adding tests for swap vos pin credit details page * Fixing a linter check error * Trying the standard approach for testing * Fxing and trying the standard approach for testing * Fixing a test * Fix: improve test structure and fix errors in test execution * Refactoring the code * Renaming the file to make it consistent --- .../e2e/swap-vos-pin-credit-details.cy.ts | 49 +++++++++++++++++++ .../pages/swapVosPinCreditDetailsPage.ts | 23 +++++++++ 2 files changed, 72 insertions(+) create mode 100644 integration_tests/e2e/swap-vos-pin-credit-details.cy.ts create mode 100644 integration_tests/pages/swapVosPinCreditDetailsPage.ts diff --git a/integration_tests/e2e/swap-vos-pin-credit-details.cy.ts b/integration_tests/e2e/swap-vos-pin-credit-details.cy.ts new file mode 100644 index 0000000..387d5cd --- /dev/null +++ b/integration_tests/e2e/swap-vos-pin-credit-details.cy.ts @@ -0,0 +1,49 @@ +import Page from '../pages/page' +import SwapVosPinCreditDetailsPage from '../pages/swapVosPinCreditDetailsPage' + +context('Swap VOs for PIN Credit Details Page', () => { + let page: SwapVosPinCreditDetailsPage + beforeEach(() => { + cy.task('reset') + cy.task('stubSignIn') + cy.signIn() + cy.visit('/log/swap-vos-pin-credit-details') + + // Navigate through the pages + cy.contains('Swap visiting orders (VOs) for PIN credit').click() + cy.contains('button', 'Continue').click() // Click the Continue button on the 'Select application type' page + cy.contains('button', 'Continue').click() // Click the Continue button on the 'Log prisoner details' page + page = Page.verifyOnPage(SwapVosPinCreditDetailsPage) + }) + + it('should direct the user to the correct page', () => { + Page.verifyOnPage(SwapVosPinCreditDetailsPage) + }) + it('should display the correct page title', () => { + page.pageTitle().should('include', 'Log swap VOs for PIN credit details') + }) + it('should render the page heading correctly', () => { + page.checkOnPage() + }) + it('should render the back link with correct text and href', () => { + page.backLink().should('have.text', 'Back').and('have.attr', 'href', '/log/prisoner-details') + }) + it('should render the correct app type title', () => { + page.appTypeTitle().should('have.text', 'Swap VOs for PIN credit') + }) + it('should render the correct form label for the textarea', () => { + page.formLabel().should('contain.text', 'Details (optional)') + }) + it('should display the hint text correctly', () => { + page.hintText().should('contain.text', 'Add a brief summary, for example, if this person is a Foreign National') + }) + it('should contain a textarea with the correct ID', () => { + page.textArea().should('have.attr', 'id', 'swap-vos-pin-credit-details') + }) + it('should include a hidden CSRF token input field', () => { + page.csrfToken().should('exist') + }) + it('should render a Continue button with the correct text', () => { + page.continueButton().should('contain.text', 'Continue') + }) +}) diff --git a/integration_tests/pages/swapVosPinCreditDetailsPage.ts b/integration_tests/pages/swapVosPinCreditDetailsPage.ts new file mode 100644 index 0000000..7149d48 --- /dev/null +++ b/integration_tests/pages/swapVosPinCreditDetailsPage.ts @@ -0,0 +1,23 @@ +import Page from './page' + +export default class SwapVosPinCreditDetailsPage extends Page { + constructor() { + super('Log details') + } + + backLink = () => cy.get('.govuk-back-link') + + appTypeTitle = () => cy.get('.govuk-caption-xl') + + pageTitle = () => cy.title() + + hintText = () => cy.get('#swap-vos-pin-credit-details-hint') + + formLabel = () => cy.get('label[for="swap-vos-pin-credit-details"]') + + textArea = () => cy.get('#swap-vos-pin-credit-details') + + csrfToken = () => cy.get('input[name="_csrf"]') + + continueButton = () => cy.get('.govuk-button--primary') +}