@ministryofjustice/frontend 3.4.0 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/moj/all.jquery.min.js +7 -70
- package/moj/all.js +2856 -2865
- package/moj/components/add-another/add-another.js +135 -104
- package/moj/components/alert/alert.js +482 -247
- package/moj/components/alert/alert.spec.helper.js +30 -5
- package/moj/components/button-menu/button-menu.js +346 -319
- package/moj/components/date-picker/date-picker.js +925 -900
- package/moj/components/filter-toggle-button/filter-toggle-button.js +122 -91
- package/moj/components/form-validator/form-validator.js +399 -164
- package/moj/components/multi-file-upload/multi-file-upload.js +445 -210
- package/moj/components/multi-select/multi-select.js +106 -75
- package/moj/components/password-reveal/password-reveal.js +64 -33
- package/moj/components/rich-text-editor/rich-text-editor.js +186 -153
- package/moj/components/search-toggle/search-toggle.js +77 -46
- package/moj/components/sortable-table/sortable-table.js +167 -146
- package/moj/helpers/_links.scss +1 -1
- package/moj/helpers.js +218 -180
- package/moj/moj-frontend.min.js +7 -70
- package/moj/version.js +28 -1
- package/package.json +1 -1
- package/moj/all.spec.js +0 -24
- package/moj/components/add-another/add-another.spec.js +0 -165
- package/moj/components/alert/alert.spec.js +0 -229
- package/moj/components/button-menu/button-menu.spec.js +0 -360
- package/moj/components/date-picker/date-picker.spec.js +0 -1178
- package/moj/components/filter-toggle-button/filter-toggle-button.spec.js +0 -302
- package/moj/components/multi-file-upload/multi-file-upload.spec.js +0 -510
- package/moj/components/multi-select/multi-select.spec.js +0 -128
- package/moj/components/password-reveal/password-reveal.spec.js +0 -57
- package/moj/components/search-toggle/search-toggle.spec.js +0 -129
- package/moj/components/sortable-table/sortable-table.spec.js +0 -362
- package/moj/helpers.spec.js +0 -235
- package/moj/namespace.js +0 -2
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-new */
|
|
2
|
-
|
|
3
|
-
const { queryByRole } = require('@testing-library/dom')
|
|
4
|
-
const { userEvent } = require('@testing-library/user-event')
|
|
5
|
-
const { configureAxe } = require('jest-axe')
|
|
6
|
-
const merge = require('lodash/merge')
|
|
7
|
-
const { setMedia } = require('mock-match-media')
|
|
8
|
-
|
|
9
|
-
require('./filter-toggle-button.js')
|
|
10
|
-
|
|
11
|
-
const user = userEvent.setup()
|
|
12
|
-
const axe = configureAxe({
|
|
13
|
-
rules: {
|
|
14
|
-
// disable landmark rules when testing isolated components.
|
|
15
|
-
region: { enabled: false }
|
|
16
|
-
}
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
const createTemplate = () => {
|
|
20
|
-
const html = `
|
|
21
|
-
<div class="moj-filter">
|
|
22
|
-
<div class="moj-filter__header">
|
|
23
|
-
<div class="moj-filter__header-title">
|
|
24
|
-
<h2 class="govuk-heading-m">Filter</h2>
|
|
25
|
-
</div>
|
|
26
|
-
<div class="moj-filter__header-action"></div>
|
|
27
|
-
</div>
|
|
28
|
-
</div>
|
|
29
|
-
<div class="moj-action-bar">
|
|
30
|
-
<div class="moj-action-bar__filter"></div>
|
|
31
|
-
</div>`
|
|
32
|
-
document.body.insertAdjacentHTML('afterbegin', html)
|
|
33
|
-
|
|
34
|
-
const buttonContainer = document.querySelector('.moj-action-bar__filter')
|
|
35
|
-
const closeButtonContainer = document.querySelector(
|
|
36
|
-
'.moj-filter__header-action'
|
|
37
|
-
)
|
|
38
|
-
const filterContainer = document.querySelector('.moj-filter')
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
buttonContainer,
|
|
42
|
-
closeButtonContainer,
|
|
43
|
-
filterContainer
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
let baseConfig
|
|
48
|
-
|
|
49
|
-
beforeEach(() => {
|
|
50
|
-
baseConfig = {
|
|
51
|
-
bigModeMediaQuery: '(min-width: 600px)',
|
|
52
|
-
startHidden: true,
|
|
53
|
-
toggleButton: {
|
|
54
|
-
container: document.querySelector('.moj-action-bar__filter'),
|
|
55
|
-
showText: 'Show filter',
|
|
56
|
-
hideText: 'Hide filter',
|
|
57
|
-
classes: 'govuk-button--secondary'
|
|
58
|
-
},
|
|
59
|
-
closeButton: {
|
|
60
|
-
container: document.querySelector('.moj-filter__header-action'),
|
|
61
|
-
text: 'Close'
|
|
62
|
-
},
|
|
63
|
-
filter: {
|
|
64
|
-
container: document.querySelector('.moj-filter')
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
describe('Filter toggle in big mode', () => {
|
|
70
|
-
let defaultConfig, buttonContainer, filterContainer
|
|
71
|
-
|
|
72
|
-
beforeEach(() => {
|
|
73
|
-
setMedia({
|
|
74
|
-
width: '800px'
|
|
75
|
-
})
|
|
76
|
-
;({ buttonContainer, filterContainer } = createTemplate())
|
|
77
|
-
|
|
78
|
-
defaultConfig = merge(baseConfig, {
|
|
79
|
-
toggleButton: {
|
|
80
|
-
container: document.querySelector('.moj-action-bar__filter')
|
|
81
|
-
},
|
|
82
|
-
closeButton: {
|
|
83
|
-
container: document.querySelector('.moj-filter__header-action')
|
|
84
|
-
},
|
|
85
|
-
filter: { container: document.querySelector('.moj-filter') }
|
|
86
|
-
})
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
afterEach(() => {
|
|
90
|
-
document.body.innerHTML = ''
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
test('creates toggle button', () => {
|
|
94
|
-
new MOJFrontend.FilterToggleButton(defaultConfig)
|
|
95
|
-
const toggleButton = queryByRole(buttonContainer, 'button')
|
|
96
|
-
|
|
97
|
-
expect(toggleButton).toBeInTheDocument()
|
|
98
|
-
expect(toggleButton.innerHTML).toBe('Show filter')
|
|
99
|
-
expect(toggleButton).toHaveAttribute('aria-expanded', 'false')
|
|
100
|
-
expect(toggleButton).toHaveClass('govuk-button--secondary')
|
|
101
|
-
|
|
102
|
-
expect(filterContainer).toHaveAttribute('tabindex', '-1')
|
|
103
|
-
expect(filterContainer).toHaveClass('moj-js-hidden')
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
test('toggle button reveals filters', async () => {
|
|
107
|
-
new MOJFrontend.FilterToggleButton(defaultConfig)
|
|
108
|
-
const toggleButton = queryByRole(buttonContainer, 'button')
|
|
109
|
-
|
|
110
|
-
expect(filterContainer).toHaveAttribute('tabindex', '-1')
|
|
111
|
-
expect(filterContainer).toHaveClass('moj-js-hidden')
|
|
112
|
-
|
|
113
|
-
await user.click(toggleButton)
|
|
114
|
-
|
|
115
|
-
expect(toggleButton).toHaveAttribute('aria-expanded', 'true')
|
|
116
|
-
expect(toggleButton.innerHTML).toBe('Hide filter')
|
|
117
|
-
expect(filterContainer).not.toHaveClass('moj-js-hidden')
|
|
118
|
-
expect(filterContainer).toHaveFocus()
|
|
119
|
-
|
|
120
|
-
await user.click(toggleButton)
|
|
121
|
-
|
|
122
|
-
expect(toggleButton).toHaveAttribute('aria-expanded', 'false')
|
|
123
|
-
expect(toggleButton.innerHTML).toBe('Show filter')
|
|
124
|
-
expect(filterContainer).toHaveClass('moj-js-hidden')
|
|
125
|
-
|
|
126
|
-
expect(toggleButton).toHaveFocus()
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
test('start visible', () => {
|
|
130
|
-
const config = merge(defaultConfig, { startHidden: false })
|
|
131
|
-
new MOJFrontend.FilterToggleButton(config)
|
|
132
|
-
const toggleButton = queryByRole(buttonContainer, 'button')
|
|
133
|
-
|
|
134
|
-
expect(toggleButton.innerHTML).toBe('Hide filter')
|
|
135
|
-
expect(filterContainer).not.toHaveClass('moj-js-hidden')
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
test('custom button text', async () => {
|
|
139
|
-
const config = merge(defaultConfig, {
|
|
140
|
-
toggleButton: { showText: 'Custom label', hideText: 'Hide me' }
|
|
141
|
-
})
|
|
142
|
-
new MOJFrontend.FilterToggleButton(config)
|
|
143
|
-
const toggleButton = queryByRole(buttonContainer, 'button')
|
|
144
|
-
|
|
145
|
-
expect(toggleButton.innerHTML).toBe('Custom label')
|
|
146
|
-
await user.click(toggleButton)
|
|
147
|
-
expect(toggleButton.innerHTML).toBe('Hide me')
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
test('custom toggle button classes', () => {
|
|
151
|
-
const config = merge(defaultConfig, {
|
|
152
|
-
toggleButton: { classes: 'classname-1 classname-2' }
|
|
153
|
-
})
|
|
154
|
-
new MOJFrontend.FilterToggleButton(config)
|
|
155
|
-
const toggleButton = queryByRole(buttonContainer, 'button')
|
|
156
|
-
|
|
157
|
-
expect(toggleButton).toHaveClass('classname-1 classname-2')
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
describe('accessibility', () => {
|
|
161
|
-
test('component has no wcag violations', async () => {
|
|
162
|
-
new MOJFrontend.FilterToggleButton(defaultConfig)
|
|
163
|
-
const toggleButton = queryByRole(buttonContainer, 'button')
|
|
164
|
-
expect(await axe(document.body)).toHaveNoViolations()
|
|
165
|
-
await user.click(toggleButton)
|
|
166
|
-
expect(await axe(document.body)).toHaveNoViolations()
|
|
167
|
-
})
|
|
168
|
-
})
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
describe('Filter toggle in small mode', () => {
|
|
172
|
-
let defaultConfig, buttonContainer, closeButtonContainer, filterContainer
|
|
173
|
-
|
|
174
|
-
beforeEach(() => {
|
|
175
|
-
setMedia({
|
|
176
|
-
width: '500px'
|
|
177
|
-
})
|
|
178
|
-
;({ buttonContainer, closeButtonContainer, filterContainer } =
|
|
179
|
-
createTemplate())
|
|
180
|
-
defaultConfig = merge(baseConfig, {
|
|
181
|
-
toggleButton: {
|
|
182
|
-
container: document.querySelector('.moj-action-bar__filter')
|
|
183
|
-
},
|
|
184
|
-
closeButton: {
|
|
185
|
-
container: document.querySelector('.moj-filter__header-action')
|
|
186
|
-
},
|
|
187
|
-
filter: { container: document.querySelector('.moj-filter') }
|
|
188
|
-
})
|
|
189
|
-
})
|
|
190
|
-
|
|
191
|
-
afterEach(() => {
|
|
192
|
-
document.body.innerHTML = ''
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
test('creates toggle button', () => {
|
|
196
|
-
new MOJFrontend.FilterToggleButton(defaultConfig)
|
|
197
|
-
const toggleButton = queryByRole(buttonContainer, 'button')
|
|
198
|
-
|
|
199
|
-
expect(toggleButton).toBeInTheDocument()
|
|
200
|
-
expect(toggleButton.innerHTML).toBe('Show filter')
|
|
201
|
-
expect(toggleButton).toHaveAttribute('aria-expanded', 'false')
|
|
202
|
-
expect(toggleButton).toHaveClass('govuk-button--secondary')
|
|
203
|
-
|
|
204
|
-
expect(filterContainer).toHaveAttribute('tabindex', '-1')
|
|
205
|
-
expect(filterContainer).toHaveClass('moj-js-hidden')
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
test('toggle button reveals filters', async () => {
|
|
209
|
-
new MOJFrontend.FilterToggleButton(defaultConfig)
|
|
210
|
-
const toggleButton = queryByRole(buttonContainer, 'button')
|
|
211
|
-
|
|
212
|
-
expect(filterContainer).toHaveAttribute('tabindex', '-1')
|
|
213
|
-
expect(filterContainer).toHaveClass('moj-js-hidden')
|
|
214
|
-
|
|
215
|
-
await user.click(toggleButton)
|
|
216
|
-
|
|
217
|
-
expect(toggleButton).toHaveAttribute('aria-expanded', 'true')
|
|
218
|
-
expect(toggleButton.innerHTML).toBe('Hide filter')
|
|
219
|
-
expect(filterContainer).not.toHaveClass('moj-js-hidden')
|
|
220
|
-
expect(filterContainer).toHaveFocus()
|
|
221
|
-
|
|
222
|
-
await user.click(toggleButton)
|
|
223
|
-
|
|
224
|
-
expect(toggleButton).toHaveAttribute('aria-expanded', 'false')
|
|
225
|
-
expect(toggleButton.innerHTML).toBe('Show filter')
|
|
226
|
-
expect(filterContainer).toHaveClass('moj-js-hidden')
|
|
227
|
-
|
|
228
|
-
expect(toggleButton).toHaveFocus()
|
|
229
|
-
})
|
|
230
|
-
|
|
231
|
-
test('start visible is ignored', () => {
|
|
232
|
-
const config = merge(defaultConfig, { startHidden: false })
|
|
233
|
-
new MOJFrontend.FilterToggleButton(config)
|
|
234
|
-
const toggleButton = queryByRole(buttonContainer, 'button')
|
|
235
|
-
|
|
236
|
-
expect(toggleButton.innerHTML).toBe('Show filter')
|
|
237
|
-
expect(filterContainer).toHaveClass('moj-js-hidden')
|
|
238
|
-
})
|
|
239
|
-
|
|
240
|
-
test('adds a close button', async () => {
|
|
241
|
-
const config = merge(defaultConfig, { startHidden: false })
|
|
242
|
-
new MOJFrontend.FilterToggleButton(config)
|
|
243
|
-
const toggleButton = queryByRole(buttonContainer, 'button')
|
|
244
|
-
|
|
245
|
-
await user.click(toggleButton)
|
|
246
|
-
|
|
247
|
-
const closeButton = queryByRole(closeButtonContainer, 'button')
|
|
248
|
-
|
|
249
|
-
expect(closeButton).toBeInTheDocument()
|
|
250
|
-
expect(closeButton.innerHTML).toBe('Close')
|
|
251
|
-
})
|
|
252
|
-
|
|
253
|
-
test('hides on resize from big to small', async () => {
|
|
254
|
-
setMedia({
|
|
255
|
-
width: '800px'
|
|
256
|
-
})
|
|
257
|
-
|
|
258
|
-
const config = merge(defaultConfig, { startHidden: false })
|
|
259
|
-
new MOJFrontend.FilterToggleButton(config)
|
|
260
|
-
const toggleButton = queryByRole(buttonContainer, 'button')
|
|
261
|
-
|
|
262
|
-
expect(toggleButton.innerHTML).toBe('Hide filter')
|
|
263
|
-
expect(filterContainer).not.toHaveClass('moj-js-hidden')
|
|
264
|
-
|
|
265
|
-
setMedia({
|
|
266
|
-
width: '500px'
|
|
267
|
-
})
|
|
268
|
-
|
|
269
|
-
expect(toggleButton.innerHTML).toBe('Show filter')
|
|
270
|
-
expect(filterContainer).toHaveClass('moj-js-hidden')
|
|
271
|
-
})
|
|
272
|
-
|
|
273
|
-
test('shows on resize from small to big', async () => {
|
|
274
|
-
setMedia({
|
|
275
|
-
width: '500px'
|
|
276
|
-
})
|
|
277
|
-
|
|
278
|
-
const config = merge(defaultConfig)
|
|
279
|
-
new MOJFrontend.FilterToggleButton(config)
|
|
280
|
-
const toggleButton = queryByRole(buttonContainer, 'button')
|
|
281
|
-
|
|
282
|
-
expect(toggleButton.innerHTML).toBe('Show filter')
|
|
283
|
-
expect(filterContainer).toHaveClass('moj-js-hidden')
|
|
284
|
-
|
|
285
|
-
setMedia({
|
|
286
|
-
width: '800px'
|
|
287
|
-
})
|
|
288
|
-
|
|
289
|
-
expect(toggleButton.innerHTML).toBe('Hide filter')
|
|
290
|
-
expect(filterContainer).not.toHaveClass('moj-js-hidden')
|
|
291
|
-
})
|
|
292
|
-
|
|
293
|
-
describe('accessibility', () => {
|
|
294
|
-
test('component has no wcag violations', async () => {
|
|
295
|
-
new MOJFrontend.FilterToggleButton(defaultConfig)
|
|
296
|
-
const toggleButton = queryByRole(buttonContainer, 'button')
|
|
297
|
-
expect(await axe(document.body)).toHaveNoViolations()
|
|
298
|
-
await user.click(toggleButton)
|
|
299
|
-
expect(await axe(document.body)).toHaveNoViolations()
|
|
300
|
-
})
|
|
301
|
-
})
|
|
302
|
-
})
|