-
Notifications
You must be signed in to change notification settings - Fork 365
Expand file tree
/
Copy pathfull-page-examples.puppeteer.test.mjs
More file actions
172 lines (145 loc) · 4.92 KB
/
full-page-examples.puppeteer.test.mjs
File metadata and controls
172 lines (145 loc) · 4.92 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import { join } from 'path'
import { paths } from '@govuk-frontend/config'
import { getProperty, goTo } from '@govuk-frontend/helpers/puppeteer'
import { getDirectories } from '@govuk-frontend/lib/files'
import { getFullPageExamples } from '../common/lib/files.mjs'
describe('Full page examples', () => {
it('should load correctly', async () => {
const exampleNamesFullPage = await getDirectories(
join(paths.app, 'src/views/full-page-examples')
)
// Full page examples have additional context
const fullPageExamples = await getFullPageExamples()
// Check the page responded correctly
for (const exampleName of exampleNamesFullPage) {
await goTo(page, `/full-page-examples/${exampleName}`)
// Look for full page example context
const example = fullPageExamples.find(
(example) => example.path === exampleName
)
// Find title text
const $title = await page.$('title')
const titleText = await getProperty($title, 'textContent')
if (exampleName === 'non-govuk-service') {
expect(titleText).toBe(`${example.title}`)
} else {
expect(titleText).toBe(`${example.title} - GOV.UK`)
}
}
})
})
describe('Full page examples (with form submit)', () => {
describe.each([
{
title: 'Send your feedback - Verify',
path: '/full-page-examples/feedback'
},
{
title: 'Have you changed your name?',
path: '/full-page-examples/have-you-changed-your-name'
},
{
title: 'How do you want to sign in?',
path: '/full-page-examples/how-do-you-want-to-sign-in'
},
{
title: 'Passport details',
path: '/full-page-examples/passport-details'
},
{
title: 'Sign in to a service',
path: '/full-page-examples/sign-in'
},
{
title: 'Update your account details',
path: '/full-page-examples/update-your-account-details'
},
{
title: 'Upload your photo',
path: '/full-page-examples/upload-your-photo'
},
{
title: 'What is your home address?',
path: '/full-page-examples/what-is-your-address'
},
{
title: 'What is your nationality?',
path: '/full-page-examples/what-is-your-nationality'
},
{
title: 'What is your home postcode?',
path: '/full-page-examples/what-is-your-postcode'
},
{
title: 'What was the last country you visited?',
path: '/full-page-examples/what-was-the-last-country-you-visited'
}
])('$title', ({ title, path }) => {
beforeAll(async () => {
await goTo(page, path)
})
it('should not show errors', async () => {
const $title = await page.$('title')
// Check the page responded correctly
await expect(getProperty($title, 'textContent')).resolves.toBe(
`${title} - GOV.UK`
)
// Check that the error summary is not visible
await expect(
page.$('[data-module="govuk-error-summary"]')
).resolves.toBeFalsy()
})
it('should show errors if submitted without input', async () => {
await Promise.all([
page.waitForNavigation(),
page.click('main button[type="submit"]')
])
const $title = await page.$('title')
// Check the page responded with an error
await expect(getProperty($title, 'textContent')).resolves.toBe(
`Error: ${title} - GOV.UK`
)
// Check that the error summary is visible
await expect(
page.$('[data-module="govuk-error-summary"]')
).resolves.toBeTruthy()
})
})
describe('Search', () => {
beforeAll(async () => {
await goTo(page, '/full-page-examples/search')
})
it('should show most wanted results by default', async () => {
const $summary = await page.$('.app-search-results-summary')
// Check the results are correct
await expect(getProperty($summary, 'textContent')).resolves.toContain(
'812,124 results'
)
})
it('should show sorted results when selected', async () => {
await page.select('.govuk-select[name="order"]', 'updated-newest')
await Promise.all([
page.waitForNavigation(),
page.click('main button[type="submit"]')
])
const $summary = await page.$('.app-search-results-summary')
// Check the results are correct
await expect(getProperty($summary, 'textContent')).resolves.toContain(
'221,418 results'
)
})
it('should show organisation results when selected', async () => {
await page.select('.govuk-select[name="order"]', 'updated-newest')
await page.click('.govuk-checkboxes__input[value="hmrc"]')
await Promise.all([
page.waitForNavigation(),
page.click('main button[type="submit"]')
])
const $summary = await page.$('.app-search-results-summary')
// Check the results are correct
await expect(getProperty($summary, 'textContent')).resolves.toContain(
'128,421 results'
)
})
})
})