govuk_publishing_components 12.13.0 → 12.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/govuk_publishing_components/components/accessible-autocomplete.js +37 -0
- data/app/assets/javascripts/govuk_publishing_components/components/checkboxes.js +6 -5
- data/app/assets/javascripts/govuk_publishing_components/components/copy-to-clipboard.js +15 -15
- data/app/assets/javascripts/govuk_publishing_components/components/feedback.js +2 -4
- data/app/assets/javascripts/govuk_publishing_components/components/initial-focus.js +8 -8
- data/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js +3 -3
- data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_accessible-autocomplete.scss +16 -0
- data/app/views/govuk_publishing_components/components/_accessible_autocomplete.html.erb +24 -0
- data/app/views/govuk_publishing_components/components/docs/accessible_autocomplete.yml +42 -0
- data/config/initializers/assets.rb +1 -0
- data/lib/govuk_publishing_components/version.rb +1 -1
- data/node_modules/accessible-autocomplete/CHANGELOG.md +269 -0
- data/node_modules/accessible-autocomplete/CONTRIBUTING.md +150 -0
- data/node_modules/accessible-autocomplete/LICENSE.txt +20 -0
- data/node_modules/accessible-autocomplete/Procfile +1 -0
- data/node_modules/accessible-autocomplete/README.md +416 -0
- data/node_modules/accessible-autocomplete/accessibility-criteria.md +42 -0
- data/node_modules/accessible-autocomplete/app.json +15 -0
- data/node_modules/accessible-autocomplete/dist/accessible-autocomplete.min.css +1 -0
- data/node_modules/accessible-autocomplete/dist/accessible-autocomplete.min.js +2 -0
- data/node_modules/accessible-autocomplete/dist/accessible-autocomplete.min.js.map +1 -0
- data/node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.preact.min.js +2 -0
- data/node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.preact.min.js.map +1 -0
- data/node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.react.min.js +2 -0
- data/node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.react.min.js.map +1 -0
- data/node_modules/accessible-autocomplete/examples/form.html +671 -0
- data/node_modules/accessible-autocomplete/examples/index.html +616 -0
- data/node_modules/accessible-autocomplete/examples/preact/index.html +346 -0
- data/node_modules/accessible-autocomplete/examples/react/index.html +347 -0
- data/node_modules/accessible-autocomplete/package.json +192 -0
- data/node_modules/accessible-autocomplete/preact.js +1 -0
- data/node_modules/accessible-autocomplete/react.js +1 -0
- data/node_modules/accessible-autocomplete/scripts/check-staged.js +14 -0
- data/node_modules/accessible-autocomplete/src/autocomplete.css +141 -0
- data/node_modules/accessible-autocomplete/src/autocomplete.js +524 -0
- data/node_modules/accessible-autocomplete/src/dropdown-arrow-down.js +11 -0
- data/node_modules/accessible-autocomplete/src/status.js +80 -0
- data/node_modules/accessible-autocomplete/src/wrapper.js +60 -0
- data/node_modules/accessible-autocomplete/test/functional/dropdown-arrow-down.js +44 -0
- data/node_modules/accessible-autocomplete/test/functional/index.js +485 -0
- data/node_modules/accessible-autocomplete/test/functional/wrapper.js +267 -0
- data/node_modules/accessible-autocomplete/test/integration/index.js +188 -0
- data/node_modules/accessible-autocomplete/test/karma.config.js +42 -0
- data/node_modules/accessible-autocomplete/test/wdio.config.js +80 -0
- data/node_modules/accessible-autocomplete/webpack.config.babel.js +193 -0
- data/node_modules/preact/LICENSE +21 -0
- data/node_modules/preact/README.md +580 -0
- data/node_modules/preact/debug.js +112 -0
- data/node_modules/preact/debug.js.map +1 -0
- data/node_modules/preact/debug/index.js +121 -0
- data/node_modules/preact/devtools.js +403 -0
- data/node_modules/preact/devtools.js.map +1 -0
- data/node_modules/preact/devtools/devtools.js +395 -0
- data/node_modules/preact/devtools/index.js +4 -0
- data/node_modules/preact/dist/preact.d.ts +891 -0
- data/node_modules/preact/dist/preact.dev.js +718 -0
- data/node_modules/preact/dist/preact.dev.js.map +1 -0
- data/node_modules/preact/dist/preact.js +408 -0
- data/node_modules/preact/dist/preact.js.flow +13 -0
- data/node_modules/preact/dist/preact.js.map +1 -0
- data/node_modules/preact/dist/preact.min.js +2 -0
- data/node_modules/preact/dist/preact.min.js.map +1 -0
- data/node_modules/preact/dist/preact.mjs +715 -0
- data/node_modules/preact/dist/preact.mjs.map +1 -0
- data/node_modules/preact/package.json +218 -0
- data/node_modules/preact/src/clone-element.js +18 -0
- data/node_modules/preact/src/component.js +90 -0
- data/node_modules/preact/src/constants.js +17 -0
- data/node_modules/preact/src/dom/index.js +138 -0
- data/node_modules/preact/src/h.js +86 -0
- data/node_modules/preact/src/options.js +22 -0
- data/node_modules/preact/src/preact.d.ts +891 -0
- data/node_modules/preact/src/preact.js +26 -0
- data/node_modules/preact/src/preact.js.flow +13 -0
- data/node_modules/preact/src/render-queue.js +28 -0
- data/node_modules/preact/src/render.js +22 -0
- data/node_modules/preact/src/util.js +19 -0
- data/node_modules/preact/src/vdom/component-recycler.js +48 -0
- data/node_modules/preact/src/vdom/component.js +296 -0
- data/node_modules/preact/src/vdom/diff.js +336 -0
- data/node_modules/preact/src/vdom/index.js +54 -0
- data/node_modules/preact/src/vnode.js +9 -0
- data/node_modules/preact/typings.json +5 -0
- metadata +78 -2
@@ -0,0 +1,267 @@
|
|
1
|
+
/* global before, beforeEach, after, describe, expect, it */
|
2
|
+
import accessibleAutocomplete from '../../src/wrapper'
|
3
|
+
|
4
|
+
const DEFAULT_OPTIONS = {
|
5
|
+
'': 'Select',
|
6
|
+
fr: 'France',
|
7
|
+
de: 'Germany',
|
8
|
+
gb: 'United Kingdom of Great Britain & Northern Ireland'
|
9
|
+
}
|
10
|
+
|
11
|
+
const injectSelectToEnhanceIntoDOM = (element, settings) => {
|
12
|
+
settings = settings || {}
|
13
|
+
settings.options = settings.options || DEFAULT_OPTIONS
|
14
|
+
settings.id = settings.id !== undefined ? settings.id : 'location-picker-id'
|
15
|
+
settings.name = settings.name !== undefined ? settings.name : 'location-picker-name'
|
16
|
+
var $select = document.createElement('select')
|
17
|
+
if (settings.id) {
|
18
|
+
$select.id = settings.id
|
19
|
+
}
|
20
|
+
if (settings.name) {
|
21
|
+
$select.name = settings.name
|
22
|
+
}
|
23
|
+
|
24
|
+
Object.keys(settings.options)
|
25
|
+
.map(optionKey => {
|
26
|
+
const option = document.createElement('option')
|
27
|
+
option.value = optionKey
|
28
|
+
option.text = settings.options[optionKey]
|
29
|
+
option.selected = (settings.selected === optionKey)
|
30
|
+
return option
|
31
|
+
})
|
32
|
+
.forEach(option => $select.appendChild(option))
|
33
|
+
|
34
|
+
element.appendChild($select)
|
35
|
+
|
36
|
+
return $select
|
37
|
+
}
|
38
|
+
|
39
|
+
describe('Wrapper', () => {
|
40
|
+
let scratch
|
41
|
+
before(() => {
|
42
|
+
scratch = document.createElement('div');
|
43
|
+
(document.body || document.documentElement).appendChild(scratch)
|
44
|
+
})
|
45
|
+
|
46
|
+
beforeEach(() => {
|
47
|
+
scratch.innerHTML = ''
|
48
|
+
})
|
49
|
+
|
50
|
+
after(() => {
|
51
|
+
scratch.parentNode.removeChild(scratch)
|
52
|
+
scratch = null
|
53
|
+
})
|
54
|
+
|
55
|
+
it('throws an error when called on nonexistent element', () => {
|
56
|
+
expect(
|
57
|
+
accessibleAutocomplete.bind(null, {
|
58
|
+
element: document.querySelector('#nothing-container'),
|
59
|
+
id: 'scratch',
|
60
|
+
source: () => {}
|
61
|
+
})
|
62
|
+
).to.throw('element is not defined')
|
63
|
+
})
|
64
|
+
|
65
|
+
it('throws an error when called without an id ', () => {
|
66
|
+
expect(
|
67
|
+
accessibleAutocomplete.bind(null, {
|
68
|
+
element: scratch,
|
69
|
+
source: () => {}
|
70
|
+
})
|
71
|
+
).to.throw('id is not defined')
|
72
|
+
})
|
73
|
+
|
74
|
+
it('throws an error when called without a source', () => {
|
75
|
+
expect(
|
76
|
+
accessibleAutocomplete.bind(null, {
|
77
|
+
element: scratch,
|
78
|
+
id: 'scratch'
|
79
|
+
})
|
80
|
+
).to.throw('source is not defined')
|
81
|
+
})
|
82
|
+
|
83
|
+
it('throws an error when called on nonexistent selectElement', () => {
|
84
|
+
expect(
|
85
|
+
accessibleAutocomplete.enhanceSelectElement.bind(null, {
|
86
|
+
selectElement: document.querySelector('#nothing')
|
87
|
+
})
|
88
|
+
).to.throw('selectElement is not defined')
|
89
|
+
})
|
90
|
+
|
91
|
+
it('can enhance a select element', () => {
|
92
|
+
const select = injectSelectToEnhanceIntoDOM(scratch)
|
93
|
+
const id = select.id
|
94
|
+
|
95
|
+
accessibleAutocomplete.enhanceSelectElement({
|
96
|
+
selectElement: select
|
97
|
+
})
|
98
|
+
|
99
|
+
const autocompleteInstances = document.querySelectorAll('.autocomplete__wrapper')
|
100
|
+
expect(autocompleteInstances.length).to.equal(1)
|
101
|
+
|
102
|
+
const autocompleteInstance = autocompleteInstances[0]
|
103
|
+
|
104
|
+
const autocompleteInput = autocompleteInstance.querySelector('.autocomplete__input')
|
105
|
+
expect(autocompleteInput.tagName.toLowerCase()).to.equal('input')
|
106
|
+
expect(autocompleteInput.id).to.equal(id)
|
107
|
+
})
|
108
|
+
|
109
|
+
it('uses the defaultValue setting to populate the input field if no option is selected', () => {
|
110
|
+
const select = injectSelectToEnhanceIntoDOM(scratch, { selected: '' })
|
111
|
+
accessibleAutocomplete.enhanceSelectElement({
|
112
|
+
defaultValue: '',
|
113
|
+
selectElement: select
|
114
|
+
})
|
115
|
+
|
116
|
+
const autocompleteInstances = document.querySelectorAll('.autocomplete__wrapper')
|
117
|
+
const autocompleteInstance = autocompleteInstances[0]
|
118
|
+
|
119
|
+
const autocompleteInput = autocompleteInstance.querySelector('.autocomplete__input')
|
120
|
+
expect(autocompleteInput.value).to.equal('')
|
121
|
+
})
|
122
|
+
|
123
|
+
it('uses the option label as the default input element value if an option is selected', () => {
|
124
|
+
const select = injectSelectToEnhanceIntoDOM(scratch, { selected: 'de' })
|
125
|
+
accessibleAutocomplete.enhanceSelectElement({
|
126
|
+
defaultValue: '',
|
127
|
+
selectElement: select
|
128
|
+
})
|
129
|
+
|
130
|
+
const autocompleteInstances = document.querySelectorAll('.autocomplete__wrapper')
|
131
|
+
const autocompleteInstance = autocompleteInstances[0]
|
132
|
+
|
133
|
+
const autocompleteInput = autocompleteInstance.querySelector('.autocomplete__input')
|
134
|
+
expect(autocompleteInput.value).to.equal('Germany')
|
135
|
+
})
|
136
|
+
|
137
|
+
it('gives the autocomplete element a blank name attribute by default', () => {
|
138
|
+
const select = injectSelectToEnhanceIntoDOM(scratch)
|
139
|
+
|
140
|
+
accessibleAutocomplete.enhanceSelectElement({
|
141
|
+
selectElement: select
|
142
|
+
})
|
143
|
+
|
144
|
+
const autocompleteInstances = document.querySelectorAll('.autocomplete__wrapper')
|
145
|
+
|
146
|
+
const autocompleteInstance = autocompleteInstances[0]
|
147
|
+
|
148
|
+
const autocompleteInput = autocompleteInstance.querySelector('.autocomplete__input')
|
149
|
+
expect(autocompleteInput.name).to.equal('')
|
150
|
+
})
|
151
|
+
|
152
|
+
it('can define a name for the autocomplete element', () => {
|
153
|
+
const select = injectSelectToEnhanceIntoDOM(scratch)
|
154
|
+
|
155
|
+
accessibleAutocomplete.enhanceSelectElement({
|
156
|
+
name: 'location-picker-autocomplete',
|
157
|
+
selectElement: select
|
158
|
+
})
|
159
|
+
|
160
|
+
const autocompleteInstances = document.querySelectorAll('.autocomplete__wrapper')
|
161
|
+
|
162
|
+
const autocompleteInstance = autocompleteInstances[0]
|
163
|
+
|
164
|
+
const autocompleteInput = autocompleteInstance.querySelector('.autocomplete__input')
|
165
|
+
expect(autocompleteInput.name).to.equal('location-picker-autocomplete')
|
166
|
+
})
|
167
|
+
|
168
|
+
it('does not include "null" options in autocomplete', (done) => {
|
169
|
+
const select = injectSelectToEnhanceIntoDOM(scratch)
|
170
|
+
|
171
|
+
accessibleAutocomplete.enhanceSelectElement({
|
172
|
+
selectElement: select
|
173
|
+
})
|
174
|
+
|
175
|
+
const autocompleteInstances = document.querySelectorAll('.autocomplete__wrapper')
|
176
|
+
const autocompleteInstance = autocompleteInstances[0]
|
177
|
+
const autocompleteInput = autocompleteInstance.querySelector('.autocomplete__input')
|
178
|
+
|
179
|
+
// Using setTimeouts here since changes in values take a while to reflect in lists
|
180
|
+
autocompleteInput.value = 'e'
|
181
|
+
setTimeout(() => {
|
182
|
+
const autocompleteOptions = autocompleteInstance.querySelectorAll('.autocomplete__option')
|
183
|
+
expect(autocompleteOptions.length).to.equal(3)
|
184
|
+
expect([].map.call(autocompleteOptions, o => o.textContent)).not.to.contain('Select')
|
185
|
+
done()
|
186
|
+
}, 250)
|
187
|
+
})
|
188
|
+
|
189
|
+
it('includes "null" options in autocomplete if `preserveNullOptions` flag is true', (done) => {
|
190
|
+
const select = injectSelectToEnhanceIntoDOM(scratch)
|
191
|
+
|
192
|
+
accessibleAutocomplete.enhanceSelectElement({
|
193
|
+
preserveNullOptions: true,
|
194
|
+
selectElement: select
|
195
|
+
})
|
196
|
+
|
197
|
+
const autocompleteInstances = document.querySelectorAll('.autocomplete__wrapper')
|
198
|
+
const autocompleteInstance = autocompleteInstances[0]
|
199
|
+
const autocompleteInput = autocompleteInstance.querySelector('.autocomplete__input')
|
200
|
+
|
201
|
+
// Using setTimeouts here since changes in values take a while to reflect in lists
|
202
|
+
autocompleteInput.value = 'e'
|
203
|
+
setTimeout(() => {
|
204
|
+
const autocompleteOptions = autocompleteInstance.querySelectorAll('.autocomplete__option')
|
205
|
+
expect(autocompleteOptions.length).to.equal(4)
|
206
|
+
expect([].map.call(autocompleteOptions, o => o.textContent)).to.contain('Select')
|
207
|
+
done()
|
208
|
+
}, 250)
|
209
|
+
})
|
210
|
+
|
211
|
+
it('has all options when typing', (done) => {
|
212
|
+
const select = injectSelectToEnhanceIntoDOM(scratch)
|
213
|
+
|
214
|
+
accessibleAutocomplete.enhanceSelectElement({
|
215
|
+
selectElement: select
|
216
|
+
})
|
217
|
+
|
218
|
+
const autocompleteInstances = document.querySelectorAll('.autocomplete__wrapper')
|
219
|
+
const autocompleteInstance = autocompleteInstances[0]
|
220
|
+
const autocompleteInput = autocompleteInstance.querySelector('.autocomplete__input')
|
221
|
+
const autocompleteOption = autocompleteInstance.querySelector('.autocomplete__option')
|
222
|
+
|
223
|
+
// Using setTimeouts here since changes in values take a while to reflect in lists
|
224
|
+
autocompleteInput.value = 'Fran'
|
225
|
+
setTimeout(() => {
|
226
|
+
expect(autocompleteOption.textContent).to.equal('France')
|
227
|
+
autocompleteInput.value = 'Ger'
|
228
|
+
setTimeout(() => {
|
229
|
+
expect(autocompleteOption.textContent).to.equal('Germany')
|
230
|
+
autocompleteInput.value = 'United'
|
231
|
+
setTimeout(() => {
|
232
|
+
const autocompleteHint = autocompleteInstance.querySelector('.autocomplete__hint')
|
233
|
+
expect(autocompleteOption.textContent).to.equal('United Kingdom of Great Britain & Northern Ireland')
|
234
|
+
expect(autocompleteHint.value).to.equal('United Kingdom of Great Britain & Northern Ireland')
|
235
|
+
done()
|
236
|
+
}, 250)
|
237
|
+
}, 250)
|
238
|
+
}, 250)
|
239
|
+
})
|
240
|
+
|
241
|
+
it('onConfirm updates original select', (done) => {
|
242
|
+
const select = injectSelectToEnhanceIntoDOM(scratch, { selected: 'de' })
|
243
|
+
|
244
|
+
accessibleAutocomplete.enhanceSelectElement({
|
245
|
+
selectElement: select
|
246
|
+
})
|
247
|
+
|
248
|
+
const autocompleteInstances = document.querySelectorAll('.autocomplete__wrapper')
|
249
|
+
const autocompleteInstance = autocompleteInstances[0]
|
250
|
+
const autocompleteInput = autocompleteInstance.querySelector('.autocomplete__input')
|
251
|
+
const autocompleteOption = autocompleteInstance.querySelector('.autocomplete__option')
|
252
|
+
|
253
|
+
// Check the initial value of the original selectElement
|
254
|
+
expect(select.value).to.equal('de')
|
255
|
+
// Using setTimeouts here since changes in values take a while to reflect in lists
|
256
|
+
autocompleteInput.value = 'United'
|
257
|
+
setTimeout(() => {
|
258
|
+
expect(autocompleteOption.textContent).to.equal('United Kingdom of Great Britain & Northern Ireland')
|
259
|
+
autocompleteOption.click()
|
260
|
+
expect(select.value).to.equal('gb')
|
261
|
+
setTimeout(() => {
|
262
|
+
expect(autocompleteInput.value).to.equal('United Kingdom of Great Britain & Northern Ireland')
|
263
|
+
done()
|
264
|
+
}, 250)
|
265
|
+
}, 250)
|
266
|
+
})
|
267
|
+
})
|
@@ -0,0 +1,188 @@
|
|
1
|
+
/* global afterEach, before, beforeEach, browser, describe, it */
|
2
|
+
const expect = require('chai').expect
|
3
|
+
const { browserName, version } = browser.desiredCapabilities
|
4
|
+
const isChrome = browserName === 'chrome'
|
5
|
+
const isFireFox = browserName === 'firefox'
|
6
|
+
const isIE = browserName === 'internet explorer'
|
7
|
+
// const isIE9 = isIE && version === '9'
|
8
|
+
// const isIE10 = isIE && version === '10'
|
9
|
+
// const isIE11 = isIE && version === '11.103'
|
10
|
+
|
11
|
+
const basicExample = () => {
|
12
|
+
describe('basic example', function () {
|
13
|
+
this.retries(3)
|
14
|
+
|
15
|
+
const input = 'input#autocomplete-default'
|
16
|
+
const menu = `${input} + ul`
|
17
|
+
const firstOption = `${menu} > li:first-child`
|
18
|
+
const secondOption = `${menu} > li:nth-child(2)`
|
19
|
+
|
20
|
+
beforeEach(() => {
|
21
|
+
browser.setValue(input, '') // Prevent autofilling, IE likes to do this.
|
22
|
+
})
|
23
|
+
|
24
|
+
it('should show the input', () => {
|
25
|
+
browser.waitForExist(input)
|
26
|
+
expect(browser.isVisible(input)).to.equal(true)
|
27
|
+
})
|
28
|
+
|
29
|
+
it('should allow focusing the input', () => {
|
30
|
+
browser.click(input)
|
31
|
+
expect(browser.hasFocus(input)).to.equal(true)
|
32
|
+
})
|
33
|
+
|
34
|
+
it('should display suggestions', () => {
|
35
|
+
browser.click(input)
|
36
|
+
browser.setValue(input, 'ita')
|
37
|
+
browser.waitForVisible(menu)
|
38
|
+
expect(browser.isVisible(menu)).to.equal(true)
|
39
|
+
})
|
40
|
+
|
41
|
+
describe('keyboard use', () => {
|
42
|
+
it('should allow typing', () => {
|
43
|
+
browser.click(input)
|
44
|
+
browser.addValue(input, 'ita')
|
45
|
+
expect(browser.getValue(input)).to.equal('ita')
|
46
|
+
})
|
47
|
+
|
48
|
+
it('should allow selecting an option', () => {
|
49
|
+
browser.click(input)
|
50
|
+
browser.setValue(input, 'ita')
|
51
|
+
browser.addValue(input, ['ArrowDown'])
|
52
|
+
expect(browser.hasFocus(input)).to.equal(false)
|
53
|
+
expect(browser.hasFocus(firstOption)).to.equal(true)
|
54
|
+
browser.addValue(firstOption, ['ArrowDown'])
|
55
|
+
expect(browser.isVisible(menu)).to.equal(true)
|
56
|
+
expect(browser.getValue(input)).to.equal('ita')
|
57
|
+
expect(browser.hasFocus(firstOption)).to.equal(false)
|
58
|
+
expect(browser.hasFocus(secondOption)).to.equal(true)
|
59
|
+
})
|
60
|
+
|
61
|
+
it('should allow confirming an option', () => {
|
62
|
+
browser.click(input)
|
63
|
+
browser.setValue(input, 'ita')
|
64
|
+
browser.addValue(input, ['ArrowDown', 'Enter'])
|
65
|
+
browser.waitUntil(() => browser.getValue(input) !== 'ita')
|
66
|
+
expect(browser.hasFocus(input)).to.equal(true)
|
67
|
+
expect(browser.getValue(input)).to.equal('Italy')
|
68
|
+
})
|
69
|
+
|
70
|
+
it('should redirect keypresses on an option to input', () => {
|
71
|
+
if (!isIE) {
|
72
|
+
browser.click(input)
|
73
|
+
browser.setValue(input, 'ita')
|
74
|
+
browser.addValue(input, ['ArrowDown'])
|
75
|
+
expect(browser.hasFocus(input)).to.equal(false)
|
76
|
+
expect(browser.hasFocus(firstOption)).to.equal(true)
|
77
|
+
browser.addValue(firstOption, ['l'])
|
78
|
+
expect(browser.hasFocus(input)).to.equal(true)
|
79
|
+
expect(browser.getValue(input)).to.equal('ital')
|
80
|
+
} else {
|
81
|
+
// FIXME: This feature does not work correctly on IE 9 to 11.
|
82
|
+
}
|
83
|
+
})
|
84
|
+
})
|
85
|
+
|
86
|
+
describe('mouse use', () => {
|
87
|
+
it('should allow confirming an option', () => {
|
88
|
+
browser.click(input)
|
89
|
+
browser.setValue(input, 'ita')
|
90
|
+
browser.click(firstOption)
|
91
|
+
expect(browser.hasFocus(input)).to.equal(true)
|
92
|
+
expect(browser.getValue(input)).to.equal('Italy')
|
93
|
+
})
|
94
|
+
})
|
95
|
+
})
|
96
|
+
}
|
97
|
+
|
98
|
+
const customTemplatesExample = () => {
|
99
|
+
describe('custom templates example', function () {
|
100
|
+
this.retries(3)
|
101
|
+
|
102
|
+
const input = 'input#autocomplete-customTemplates'
|
103
|
+
const menu = `${input} + ul`
|
104
|
+
const firstOption = `${menu} > li:first-child`
|
105
|
+
const firstOptionInnerElement = `${firstOption} > strong`
|
106
|
+
|
107
|
+
beforeEach(() => {
|
108
|
+
browser.setValue(input, '') // Prevent autofilling, IE likes to do this.
|
109
|
+
})
|
110
|
+
|
111
|
+
describe('mouse use', () => {
|
112
|
+
it('should allow confirming an option by clicking on child elements', () => {
|
113
|
+
browser.setValue(input, 'uni')
|
114
|
+
if (isChrome) {
|
115
|
+
const errorRegex = /Other element would receive the click/
|
116
|
+
expect(browser.click.bind(browser, firstOptionInnerElement)).to.throw(errorRegex)
|
117
|
+
expect(browser.hasFocus(input)).to.equal(true)
|
118
|
+
expect(browser.getValue(input)).to.equal('uni')
|
119
|
+
}
|
120
|
+
if (isFireFox) {
|
121
|
+
browser.click(firstOptionInnerElement)
|
122
|
+
expect(browser.hasFocus(input)).to.equal(true)
|
123
|
+
expect(browser.getValue(input)).to.equal('United Kingdom')
|
124
|
+
}
|
125
|
+
if (isIE) {
|
126
|
+
// FIXME: This feature works correctly on IE but testing it doesn't seem to work.
|
127
|
+
}
|
128
|
+
})
|
129
|
+
})
|
130
|
+
})
|
131
|
+
}
|
132
|
+
|
133
|
+
const takeScreenshotsIfFail = () => {
|
134
|
+
afterEach(function () {
|
135
|
+
const testFailed = this.currentTest.state === 'failed'
|
136
|
+
if (testFailed) {
|
137
|
+
const timestamp = +new Date()
|
138
|
+
const browserVariant = isIE ? `ie${version}` : browserName
|
139
|
+
const testTitle = this.currentTest.title.replace(/\W/g, '-')
|
140
|
+
const filename = `./screenshots/${timestamp}-${browserVariant}-${testTitle}.png`
|
141
|
+
browser.saveScreenshot(filename)
|
142
|
+
console.log(`Test failed, created: ${filename}`)
|
143
|
+
}
|
144
|
+
})
|
145
|
+
}
|
146
|
+
|
147
|
+
describe('Accessible Autocomplete', () => {
|
148
|
+
before(() => {
|
149
|
+
browser.url('/')
|
150
|
+
})
|
151
|
+
|
152
|
+
it('should have the right title', () => {
|
153
|
+
expect(browser.getTitle()).to.equal('Accessible Autocomplete examples')
|
154
|
+
})
|
155
|
+
|
156
|
+
basicExample()
|
157
|
+
customTemplatesExample()
|
158
|
+
|
159
|
+
takeScreenshotsIfFail()
|
160
|
+
})
|
161
|
+
|
162
|
+
describe('Accessible Autocomplete Preact', () => {
|
163
|
+
before(() => {
|
164
|
+
browser.url('/preact')
|
165
|
+
})
|
166
|
+
|
167
|
+
it('should have the right title', () => {
|
168
|
+
expect(browser.getTitle()).to.equal('Accessible Autocomplete Preact examples')
|
169
|
+
})
|
170
|
+
|
171
|
+
basicExample()
|
172
|
+
|
173
|
+
takeScreenshotsIfFail()
|
174
|
+
})
|
175
|
+
|
176
|
+
describe('Accessible Autocomplete React', () => {
|
177
|
+
before(() => {
|
178
|
+
browser.url('/react')
|
179
|
+
})
|
180
|
+
|
181
|
+
it('should have the right title', () => {
|
182
|
+
expect(browser.getTitle()).to.equal('Accessible Autocomplete React examples')
|
183
|
+
})
|
184
|
+
|
185
|
+
basicExample()
|
186
|
+
|
187
|
+
takeScreenshotsIfFail()
|
188
|
+
})
|