Skip to content

Commit

Permalink
Add integration tests for funding cas2 accommodation page
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Liburd committed Feb 19, 2025
1 parent fc54824 commit 793e2b9
Show file tree
Hide file tree
Showing 7 changed files with 343 additions and 7 deletions.
17 changes: 10 additions & 7 deletions integration_tests/fixtures/applicationData.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@
}
},
"funding-information": {
"funding-source": {
"fundingSource": "benefits"
},
"identification": {
"funding-cas2-accommodation": {
"fundingSource": "personalSavings",
"fundingSourceDetail": "Personal savings details",
"hasNationalInsuranceNumber": "yes",
"nationalInsuranceNumber": "SF123456X",
"receivingBenefits": "yes",
"receivedBenefitSanctions": "no",
"inEducationOrTraining": "no"
},
"applicant-id": {
"idDocuments": "passport"
},
"national-insurance": {
"nationalInsuranceNumber": "12345"
}
},
"solicitor-details": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Cas2v2Application as Application } from '../../../../../server/@types/shared/models/Cas2v2Application'
import ApplyPage from '../../applyPage'
import paths from '../../../../../server/paths/apply'

export default class AlternativeApplicantIdPage extends ApplyPage {
constructor(private readonly application: Application) {
super(
'What other identification document (ID) does the applicant have?',
application,
'funding-information',
'alternative-applicant-id',
)
}

static visit(application: Application): void {
cy.visit(
paths.applications.pages.show({
id: application.id,
task: 'funding-information',
page: 'alternative-applicant-id',
}),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Cas2v2Application as Application } from '../../../../../server/@types/shared/models/Cas2v2Application'
import ApplyPage from '../../applyPage'
import paths from '../../../../../server/paths/apply'

export default class ApplicantIdPage extends ApplyPage {
constructor(private readonly application: Application) {
super(`What identity document (ID) does the applicant have?`, application, 'funding-information', 'applicant-id')
}

static visit(application: Application): void {
cy.visit(
paths.applications.pages.show({
id: application.id,
task: 'funding-information',
page: 'applicant-id',
}),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Cas2v2Application as Application } from '@approved-premises/api'
import ApplyPage from '../../applyPage'
import { FundingSources } from '../../../../../server/form-pages/apply/area-and-funding/funding-information/fundingCas2Accommodation'

export default class FundingCas2AccommodationPage extends ApplyPage {
constructor(private readonly application: Application) {
super('Funding CAS-2 accommodation', application, 'funding-information', 'funding-cas2-accommodation')
}

completeWithPersonalSavings(): void {
this.selectFundingSource('personalSavings')
this.enterFundingSourceDetails()
this.enterNationalInsuranceNumber()
this.enterBenefitsDetails()
this.selectInEducationOrTraining()
}

completeWithHousingBenefits(): void {
this.selectFundingSource('benefits')
this.enterNationalInsuranceNumber()
this.enterBenefitsDetails()
this.selectInEducationOrTraining()
}

private selectFundingSource(fundingSource: FundingSources): void {
this.checkRadioByNameAndValue('fundingSource', fundingSource)
}

private enterFundingSourceDetails(): void {
this.getTextInputByIdAndEnterDetails('fundingSourceDetail', 'Funding source details')
}

private enterNationalInsuranceNumber(): void {
this.checkRadioByNameAndValue('hasNationalInsuranceNumber', 'yes')
this.getTextInputByIdAndEnterDetails('nationalInsuranceNumber', 'SF123456X')
}

private enterBenefitsDetails(): void {
this.checkRadioByNameAndValue('receivingBenefits', 'yes')
this.checkRadioByNameAndValue('receivedBenefitSanctions', 'no')
}

private selectInEducationOrTraining(): void {
this.checkRadioByNameAndValue('inEducationOrTraining', 'no')
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Feature: Referrer completes 'alternative applicant ID' page
// So that I can complete the "Funding information" task
// As a referrer
// I want to complete the 'alternative applicant ID' page
//
// Background:
// Given an application exists
// And I am logged in
// And I visit the 'alternative applicant ID' page
//
// Scenario: navigate to task list page
// When I select a form of ID
// And I continue to the next task / page
// Then I am redirected to the task list page

import Page from '../../../../pages/page'
import { personFactory, applicationFactory } from '../../../../../server/testutils/factories/index'
import AlternativeApplicantIdPage from '../../../../pages/apply/area-and-funding/funding-information/alternativeApplicantIdPage'
import TaskListPage from '../../../../pages/apply/taskListPage'

context('Visit alternative applicant ID page', () => {
const person = personFactory.build({ name: 'Roger Smith' })

beforeEach(function test() {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')

cy.fixture('applicationData.json').then(applicationData => {
applicationData['funding-information'] = {}
const application = applicationFactory.build({
id: 'abc123',
person,
data: applicationData,
})
cy.wrap(application).as('application')
})
})

beforeEach(function test() {
// And an application exists
// -------------------------
cy.task('stubApplicationGet', { application: this.application })
cy.task('stubApplicationUpdate', { application: this.application })

// Given I am logged in
//---------------------
cy.signIn()

// And I am on the alternative applicant ID page
// --------------------------------
AlternativeApplicantIdPage.visit(this.application)
})

// Scenario: navigate to task list page
// ----------------------------------------
it('redirects to the task list page', function test() {
// When I select a form of ID
const page = Page.verifyOnPage(AlternativeApplicantIdPage, this.application)
page.checkCheckboxByValue('contract')

// And I continue to the next task / page
page.clickSubmit()

// Then I am redirected to the task list page
Page.verifyOnPage(TaskListPage, this.application)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Feature: Referrer completes 'applicant ID' page
// So that I can complete the "Funding information" task
// As a referrer
// I want to complete the 'applicant ID' page
//
// Background:
// Given an application exists
// And I am logged in
// And I visit the 'applicant ID' page
//
// Scenario: navigate to alternative applicant ID page
// When I select 'none'
// And I continue to the next task / page
// Then I am redirected to the alternative applicant ID page
//
// Scenario: navigate to task list page
// When I select a form of ID
// And I continue to the next task / page
// Then I am redirected to the task list page

import Page from '../../../../pages/page'
import ApplicantIdPage from '../../../../pages/apply/area-and-funding/funding-information/applicantIdPage'
import TaskListPage from '../../../../pages/apply/taskListPage'
import { personFactory, applicationFactory } from '../../../../../server/testutils/factories/index'
import AlternativeApplicantIdPage from '../../../../pages/apply/area-and-funding/funding-information/alternativeApplicantIdPage'

context('Visit applicant ID page', () => {
const person = personFactory.build({ name: 'Roger Smith' })

beforeEach(function test() {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')

cy.fixture('applicationData.json').then(applicationData => {
applicationData['funding-information'] = {}
const application = applicationFactory.build({
id: 'abc123',
person,
data: applicationData,
})
cy.wrap(application).as('application')
})
})

beforeEach(function test() {
// And an application exists
// -------------------------
cy.task('stubApplicationGet', { application: this.application })
cy.task('stubApplicationUpdate', { application: this.application })

// Given I am logged in
//---------------------
cy.signIn()

// And I am on the applicant ID page
// --------------------------------
ApplicantIdPage.visit(this.application)
})

// Scenario: navigate to alternative applicant ID page
// ----------------------------------------
it('redirects to the alternative applicant ID page', function test() {
// When I select 'none'
const page = Page.verifyOnPage(ApplicantIdPage, this.application)
page.checkCheckboxByValue('none')

// And I continue to the next task / page
page.clickSubmit()

// Then I am redirected to the alternative applicant ID page
Page.verifyOnPage(AlternativeApplicantIdPage, this.application)
})

// Scenario: navigate to the task list page
// ----------------------------------------
it('redirects to the task list page', function test() {
// When I select a form of ID
const page = Page.verifyOnPage(ApplicantIdPage, this.application)
page.checkCheckboxByValue('passport')

// And I continue to the next task / page
page.clickSubmit()

// Then I am redirected to the task list page
Page.verifyOnPage(TaskListPage, this.application)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Feature: Referrer completes 'Funding CAS-2 Accommodation' question page
// As a referrer,
// I want to confirm how the applicant is funding their CAS2 accommodation
// So that I can get the applicant into accommodation as quickly as possible with no FIEs
//
// Scenario: When the applicant is using personal savings to fund the accommodation
// Given I'm on the 'Funding CAS-2 Accommodation' question page
// When I select personal savings and give valid answers for all other questions
// Then I am taken to the task list page
//
// Scenario: When the applicant is using house benefits to fund the accommodation
// Given I'm on the 'Funding CAS-2 Accommodation' question page
// When I select housing benefits and give valid answers for all other questions
// Then I am taken to the task list page

import FundingCas2AccommodationPage from '../../../../pages/apply/area-and-funding/funding-information/fundingCas2AccommodationPage'
import Page from '../../../../pages/page'
import TaskListPage from '../../../../pages/apply/taskListPage'
import ApplicantIdPage from '../../../../pages/apply/area-and-funding/funding-information/applicantIdPage'
import { personFactory, applicationFactory } from '../../../../../server/testutils/factories/index'

context('Visit "Confirm funding and ID" section', () => {
const person = personFactory.build({ name: 'Roger Smith' })

beforeEach(function test() {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')

cy.fixture('applicationData.json').then(applicationData => {
applicationData['funding-information'] = {}
const application = applicationFactory.build({
id: 'abc123',
person,
})
application.data = applicationData
cy.wrap(application).as('application')
cy.wrap(application.data).as('applicationData')
})
})

beforeEach(function test() {
// And an application exists
cy.task('stubApplicationGet', { application: this.application })
cy.task('stubApplicationUpdate', { application: this.application })

// Given I am logged in
//---------------------
cy.signIn()

// And I am on the Funding CAS-2 accommodation page
// --------------------------------
cy.visit('applications/abc123/tasks/funding-information/pages/funding-cas2-accommodation')
Page.verifyOnPage(FundingCas2AccommodationPage, this.application)
})

// Scenario: When the applicant is using personal savings to fund the accommodation
// ----------------------------
it('continues to the task list page', function test() {
// Given I am on the Funding CAS-2 Accommodation
const page = Page.verifyOnPage(FundingCas2AccommodationPage, this.application)

// When I complete the answers on the page
page.completeWithPersonalSavings()

// And I click submit
page.clickSubmit()

// I am taken to the task list page
Page.verifyOnPage(TaskListPage, this.application)
})

// Scenario: When the applicant is using house benefits to fund the accommodation
// ----------------------------
it('continues to the applicant ID page', function test() {
// Given I am on the Funding CAS-2 Accommodation
const page = Page.verifyOnPage(FundingCas2AccommodationPage, this.application)

// When I complete the answers on the page
page.completeWithHousingBenefits()

// And I click submit
page.clickSubmit()

// I am taken to the applicant ID page
Page.verifyOnPage(ApplicantIdPage, this.application)
})
})

0 comments on commit 793e2b9

Please sign in to comment.