generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapply.ts
150 lines (129 loc) · 5.63 KB
/
apply.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { Page, expect } from '@playwright/test'
import { faker } from '@faker-js/faker/locale/en_GB'
import {
BeforeYouStartPage,
DashboardPage,
FindByPrisonNumberPage,
TaskListPage,
ApplicationOriginPage,
} from '../pages/apply'
import {
completeConsentTask,
completeEligibilityTask,
completeReferrerDetailsTask,
completeSolicitorDetailsTask,
} from './beforeYouStartSection'
import {
completeAddressHistoryTask,
completeEqualityAndDiversityTask,
completePersonalInformationTask,
} from './aboutThePersonSection'
import { completeHealthNeedsTask, completeRiskInformationTask } from './risksAndNeedsSection'
import { completeAreaInformationTask, completeFundingInformationTask } from './areaAndFundingSection'
import {
completeAllegedOffencesTask,
completeCommunitySupervisionAndCurrentOffencesTask,
completeOffenceHistoryTask,
} from './offenceAndLicenceInformationSection'
import { completeCheckAnswersTask } from './checkAnswersSection'
import { TestOptions } from '../testOptions'
import {
completeBailConditionsAndSupportSessionsTask,
completeBailHearingInformationTask,
} from './bailInformationSection'
export const startAnApplication = async (page: Page) => {
// Start page
// --------
// visit the root url
const dashboardPage = new DashboardPage(page)
await dashboardPage.goto()
// Follow link to 'new application'
await dashboardPage.makeNewApplication()
// // confirm that I'm ready to start
const beforeYouStartPage = new BeforeYouStartPage(page)
await beforeYouStartPage.startNow()
}
export const selectApplicationOrigin = async (page: Page) => {
const applicationOriginPage = new ApplicationOriginPage(page)
await applicationOriginPage.choosePrisonBail()
}
export const enterPrisonerNumber = async (page: Page, prisonNumber: string) => {
const prisonNumberPage = new FindByPrisonNumberPage(page)
await prisonNumberPage.enterPrisonNumber(prisonNumber)
await prisonNumberPage.clickButton('Search for applicant')
}
export const confirmApplicant = async (page: Page) => {
const confirmApplicantPage = new TaskListPage(page)
await confirmApplicantPage.clickButton('Confirm and continue')
}
export const completeBeforeYouStartSection = async (page: Page, name: string) => {
await completeEligibilityTask(page, name)
await completeConsentTask(page, name)
await completeReferrerDetailsTask(page)
await completeSolicitorDetailsTask(page, name)
}
export const completeAreaAndFundingSection = async (page: Page, name: string) => {
await completeAreaInformationTask(page, name)
await completeFundingInformationTask(page)
}
export const completeAboutThePersonSection = async (page: Page, name: string) => {
await completePersonalInformationTask(page, name)
await completeEqualityAndDiversityTask(page, name)
await completeAddressHistoryTask(page, name)
}
export const completeRisksAndNeedsSection = async (page: Page, name: string) => {
await completeHealthNeedsTask(page, name)
await completeRiskInformationTask(page)
}
export const completeOffenceInformationSection = async (page: Page, name: string) => {
await completeAllegedOffencesTask(page, name)
await completeCommunitySupervisionAndCurrentOffencesTask(page, name)
await completeOffenceHistoryTask(page, name)
}
export const completeBailInformationSection = async (page: Page, name: string) => {
await completeBailConditionsAndSupportSessionsTask(page, name)
await completeBailHearingInformationTask(page, name)
}
export const completeCheckAnswersSection = async (page: Page, name: string) => {
await completeCheckAnswersTask(page, name)
}
export const submitApplication = async (page: Page) => {
await page.getByRole('link', { name: 'Submit application' }).click()
await expect(page.locator('h1')).toContainText('Are you sure you want to submit the application?')
await page.getByRole('button', { name: 'Yes, I am sure' }).click()
await expect(page.locator('h1')).toContainText('Application submitted')
}
export const viewSubmittedApplication = async (page: Page, name: string) => {
await page.goto('/applications#submitted')
await expect(page.locator('h1')).toContainText('Your CAS-2 applications')
await page.getByRole('link', { name }).first().click()
await expect(page.locator('h1')).toContainText(name)
await expect(page.locator('h2').first()).toContainText('Application history')
}
export const viewInProgressDashboard = async (page: Page) => {
await page.goto('/applications')
}
export const addNote = async (page: Page) => {
const note = faker.lorem.paragraph()
await page.getByLabel('Add a note for the assessor', { exact: true }).fill(note)
await page.getByTestId('submit-button').click()
await expect(page.locator('h2').first()).toContainText('Success')
await expect(page.locator('.moj-timeline__description').first()).toContainText(note)
await expect(page.locator('.moj-timeline__title').first()).toContainText('Note')
}
export const checkAnApplicationByUserExists = async (page: Page, name: string) => {
const tableRows = page.locator('.govuk-table__row')
expect(tableRows.filter({ hasText: name }).first()).toBeVisible()
}
export const viewApplicationMadeByAnotherUser = async (page: Page, name: string) => {
const tableRows = page.locator('.govuk-table__row')
const rowWithOtherUser = tableRows.filter({ hasNotText: name }).last()
await rowWithOtherUser.getByRole('link').click()
await expect(page.locator('h2').first()).toContainText('Application history')
}
export const createAnInProgressApplication = async (page: Page, person: TestOptions['person']) => {
await startAnApplication(page)
await selectApplicationOrigin(page)
await enterPrisonerNumber(page, person.nomsNumber)
await confirmApplicant(page)
}