@ons/design-system 72.1.0 → 72.1.2
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/README.md +1 -1
- package/components/accordion/_macro.spec.js +2 -2
- package/components/address-input/_macro.spec.js +245 -322
- package/components/address-input/autosuggest.address.spec.js +16 -14
- package/components/address-output/_macro.spec.js +121 -74
- package/components/address-output/_test_examples.js +8 -0
- package/components/autosuggest/_macro.spec.js +373 -184
- package/components/back-to-top/back-to-top.dom.js +4 -4
- package/components/back-to-top/back-to-top.js +1 -1
- package/components/browser-banner/_macro.spec.js +11 -11
- package/components/button/_button.scss +1 -1
- package/components/button/_macro.njk +1 -1
- package/components/button/_macro.spec.js +405 -351
- package/components/button/example-button-group.njk +1 -0
- package/components/checkboxes/_checkbox.scss +3 -3
- package/components/description-list/_description-list.scss +40 -9
- package/components/description-list/_macro.njk +20 -12
- package/components/description-list/_macro.spec.js +11 -1
- package/components/description-list/example-inline-description-list.njk +58 -0
- package/components/details/_details.scss +1 -2
- package/components/details/example-details-open.njk +10 -0
- package/components/external-link/_macro.spec.js +66 -69
- package/components/external-link/_test_examples.js +4 -0
- package/components/feedback/_macro.spec.js +109 -80
- package/components/feedback/_test_examples.js +17 -0
- package/components/field/_macro.spec.js +106 -69
- package/components/header/_macro.njk +92 -90
- package/components/header/_macro.spec.js +10 -0
- package/components/header/example-header-basic.njk +11 -0
- package/components/hero/_hero.scss +239 -2
- package/components/hero/_macro.njk +7 -0
- package/components/hero/_macro.spec.js +5 -0
- package/components/hero/example-hero-navy-blue.njk +14 -0
- package/components/section-navigation/_macro.njk +9 -6
- package/components/table-of-contents/_macro.njk +3 -3
- package/components/table-of-contents/_macro.spec.js +3 -3
- package/components/table-of-contents/{_toc.scss → _table-of-contents.scss} +1 -1
- package/components/table-of-contents/table-of-contents.dom.js +13 -0
- package/components/table-of-contents/{toc.js → table-of-contents.js} +4 -4
- package/components/table-of-contents/{toc.spec.js → table-of-contents.spec.js} +2 -2
- package/components/tabs/_tabs.scss +10 -11
- package/components/tabs/tabs.js +3 -3
- package/components/timeout-modal/timeout-modal.spec.js +1 -1
- package/css/main.css +1 -1
- package/js/main.js +1 -1
- package/package.json +1 -1
- package/scripts/main.es5.js +1 -1
- package/scripts/main.js +1 -1
- package/scss/main.scss +1 -1
- package/scss/utilities/_margin.scss +4 -0
- package/scss/utilities/_padding.scss +4 -0
- package/scss/vars/_colors.scss +2 -0
- package/components/table-of-contents/toc.dom.js +0 -13
|
@@ -4,69 +4,22 @@ import * as cheerio from 'cheerio';
|
|
|
4
4
|
|
|
5
5
|
import axe from '../../tests/helpers/axe';
|
|
6
6
|
import { renderComponent, templateFaker } from '../../tests/helpers/rendering';
|
|
7
|
+
import { EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL, EXAMPLE_MANUAL_INPUT_FIELDS } from './_test-examples';
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
ariaMinChars: 'Enter 3 or more characters for suggestions.',
|
|
19
|
-
ariaOneResult: 'There is one suggestion available.',
|
|
20
|
-
ariaNResults: 'There are {n} suggestions available.',
|
|
21
|
-
ariaLimitedResults: 'Results have been limited to 10 suggestions. Type more characters to improve your search',
|
|
22
|
-
ariaGroupedResults: 'There are {n} for {x}',
|
|
23
|
-
groupCount: '{n} addresses',
|
|
24
|
-
moreResults: 'Enter more of the address to improve results',
|
|
25
|
-
noResults: 'No results found. Try entering a different part of the address',
|
|
26
|
-
tooManyResults: '{n} results found. Enter more of the address to improve results',
|
|
27
|
-
typeMore: 'Enter more of the address to get results',
|
|
28
|
-
resultsTitle: 'Select an address',
|
|
29
|
-
resultsTitleId: 'address-suggestions',
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const EXAMPLE_MANUAL_INPUT_FIELDS = {
|
|
33
|
-
organisation: {
|
|
34
|
-
label: 'Organisation name',
|
|
35
|
-
value: 'Example Organisation',
|
|
36
|
-
error: { text: 'Server error: organisation name' },
|
|
37
|
-
},
|
|
38
|
-
line1: {
|
|
39
|
-
label: 'Address line 1',
|
|
40
|
-
value: 'Flat 12345',
|
|
41
|
-
error: { text: 'Server error: address line 1' },
|
|
42
|
-
},
|
|
43
|
-
line2: {
|
|
44
|
-
label: 'Address line 2',
|
|
45
|
-
value: '12345 The Road',
|
|
46
|
-
error: { text: 'Server error: address line 2' },
|
|
47
|
-
},
|
|
48
|
-
town: {
|
|
49
|
-
label: 'Town or city',
|
|
50
|
-
value: 'The Town',
|
|
51
|
-
error: { text: 'Server error: town or city' },
|
|
52
|
-
},
|
|
53
|
-
postcode: {
|
|
54
|
-
label: 'Postcode',
|
|
55
|
-
value: 'PO57 6ODE',
|
|
56
|
-
error: { text: 'Server error: postcode' },
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
describe('macro: address-input', () => {
|
|
61
|
-
it('passes jest-axe checks', async () => {
|
|
62
|
-
const $ = cheerio.load(renderComponent('address-input', EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL));
|
|
63
|
-
|
|
64
|
-
const results = await axe($.html());
|
|
65
|
-
expect(results).toHaveNoViolations();
|
|
9
|
+
describe('FOR: Macro: Address-input', () => {
|
|
10
|
+
describe('GIVEN: Params: required', () => {
|
|
11
|
+
describe('WHEN: required params are provided', () => {
|
|
12
|
+
const $ = cheerio.load(renderComponent('address-input', EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL));
|
|
13
|
+
|
|
14
|
+
test('THEN: jest-axe tests pass', async () => {
|
|
15
|
+
const results = await axe($.html());
|
|
16
|
+
expect(results).toHaveNoViolations();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
66
19
|
});
|
|
67
20
|
|
|
68
|
-
describe('
|
|
69
|
-
|
|
21
|
+
describe('GIVEN: Params: manualEntry', () => {
|
|
22
|
+
describe('WHEN: manualEntry is set to false', () => {
|
|
70
23
|
const $ = cheerio.load(
|
|
71
24
|
renderComponent('address-input', {
|
|
72
25
|
...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
|
|
@@ -75,10 +28,15 @@ describe('macro: address-input', () => {
|
|
|
75
28
|
}),
|
|
76
29
|
);
|
|
77
30
|
|
|
78
|
-
|
|
31
|
+
test('THEN: it renders with class to hide manual input fields', () => {
|
|
32
|
+
expect($('.ons-js-address-input__manual').hasClass('ons-u-db-no-js_enabled')).toBe(true);
|
|
33
|
+
});
|
|
79
34
|
});
|
|
80
35
|
|
|
81
|
-
|
|
36
|
+
describe('WHEN: manualEntry is set to true', () => {
|
|
37
|
+
const faker = templateFaker();
|
|
38
|
+
const autosuggestSpy = faker.spy('autosuggest', { suppressOutput: true });
|
|
39
|
+
|
|
82
40
|
const $ = cheerio.load(
|
|
83
41
|
renderComponent('address-input', {
|
|
84
42
|
...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
|
|
@@ -87,126 +45,209 @@ describe('macro: address-input', () => {
|
|
|
87
45
|
}),
|
|
88
46
|
);
|
|
89
47
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
it('renders "organisation" input field with expected parameters', () => {
|
|
94
|
-
const faker = templateFaker();
|
|
95
|
-
const inputSpy = faker.spy('input', { suppressOutput: true });
|
|
96
|
-
|
|
97
|
-
faker.renderComponent('address-input', {
|
|
98
|
-
...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
|
|
99
|
-
...EXAMPLE_MANUAL_INPUT_FIELDS,
|
|
100
|
-
isEditable: true,
|
|
48
|
+
test('THEN: it renders with class to show manual input fields', () => {
|
|
49
|
+
expect($('.ons-js-address-input__manual').hasClass('ons-u-db-no-js_enabled')).toBe(false);
|
|
101
50
|
});
|
|
102
51
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
name: 'address-input-example-id-organisation',
|
|
106
|
-
classes: 'ons-js-address-organisation',
|
|
107
|
-
label: {
|
|
108
|
-
text: 'Organisation name',
|
|
109
|
-
},
|
|
110
|
-
value: 'Example Organisation',
|
|
111
|
-
width: '20@m',
|
|
112
|
-
error: { text: 'Server error: organisation name' },
|
|
52
|
+
test('THEN: autosuggest search field is not shown', () => {
|
|
53
|
+
expect(autosuggestSpy.occurrences.length).toBe(0);
|
|
113
54
|
});
|
|
114
55
|
});
|
|
115
56
|
|
|
116
|
-
|
|
57
|
+
describe('WHEN: manualEntry is not set', () => {
|
|
117
58
|
const faker = templateFaker();
|
|
118
|
-
const
|
|
59
|
+
const autosuggestSpy = faker.spy('autosuggest', { suppressOutput: true });
|
|
119
60
|
|
|
61
|
+
// Since autosuggestSpy suppresses output the values being tested below do not
|
|
62
|
+
// need to represent real values. This test is only interested in verifying that
|
|
63
|
+
// the provided values are being passed through to the autosuggest component.
|
|
120
64
|
faker.renderComponent('address-input', {
|
|
121
65
|
...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
|
|
122
|
-
...EXAMPLE_MANUAL_INPUT_FIELDS,
|
|
123
|
-
isEditable: true,
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
expect(inputSpy.occurrences).toContainEqual({
|
|
127
|
-
id: 'address-input-example-id-line1',
|
|
128
|
-
name: 'address-input-example-id-line1',
|
|
129
|
-
classes: 'ons-js-address-line1',
|
|
130
66
|
label: {
|
|
131
|
-
text: '
|
|
67
|
+
text: '[params.label.text]',
|
|
68
|
+
id: '[params.label.id]',
|
|
132
69
|
},
|
|
133
|
-
value: '
|
|
134
|
-
|
|
135
|
-
error:
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
70
|
+
value: '[params.value]',
|
|
71
|
+
attributes: '[params.attributes]',
|
|
72
|
+
error: '[params.error]',
|
|
73
|
+
name: '[params.name]',
|
|
74
|
+
mutuallyExclusive: '[params.mutuallyExclusive]',
|
|
75
|
+
apiDomain: '[params.apiDomain]',
|
|
76
|
+
apiDomainBearerToken: '[params.apiDomainBearerToken]',
|
|
77
|
+
apiManualQueryParams: '[params.apiManualQueryParams]',
|
|
78
|
+
allowMultiple: '[params.allowMultiple]',
|
|
79
|
+
mandatory: '[params.mandatory]',
|
|
80
|
+
instructions: '[params.instructions]',
|
|
81
|
+
autocomplete: '[params.autocomplete]',
|
|
82
|
+
isEditable: '[params.isEditable]',
|
|
83
|
+
ariaYouHaveSelected: '[params.ariaYouHaveSelected]',
|
|
84
|
+
ariaMinChars: '[params.ariaMinChars]',
|
|
85
|
+
minChars: '[params.minChars]',
|
|
86
|
+
ariaResultsLabel: '[params.ariaResultsLabel]',
|
|
87
|
+
ariaOneResult: '[params.ariaOneResult]',
|
|
88
|
+
ariaNResults: '[params.ariaNResults]',
|
|
89
|
+
ariaLimitedResults: '[params.ariaLimitedResults]',
|
|
90
|
+
ariaGroupedResults: '[params.ariaGroupedResults]',
|
|
91
|
+
groupCount: '[params.groupCount]',
|
|
92
|
+
moreResults: '[params.moreResults]',
|
|
93
|
+
tooManyResults: '[params.tooManyResults]',
|
|
94
|
+
resultsTitle: '[params.resultsTitle]',
|
|
95
|
+
resultsTitleId: '[params.resultsTitleId]',
|
|
96
|
+
noResults: '[params.noResults]',
|
|
97
|
+
typeMore: '[params.typeMore]',
|
|
98
|
+
errorTitle: '[params.errorTitle]',
|
|
99
|
+
errorMessageEnter: '[params.errorMessageEnter]',
|
|
100
|
+
errorMessageSelect: '[params.errorMessageSelect]',
|
|
101
|
+
errorMessageApi: '[params.errorMessageApi]',
|
|
102
|
+
errorMessageApiLinkText: '[params.errorMessageApiLinkText]',
|
|
103
|
+
options: '[params.options]',
|
|
104
|
+
manualLinkUrl: '[params.manualLinkUrl]',
|
|
105
|
+
manualLinkText: '[params.manualLinkText]',
|
|
147
106
|
});
|
|
148
107
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
108
|
+
test('THEN: the provided attributes are passed through to the autosuggest component', () => {
|
|
109
|
+
expect(autosuggestSpy.occurrences[0]).toEqual({
|
|
110
|
+
id: 'address-input-example-id-autosuggest',
|
|
111
|
+
classes: 'ons-address-input__autosuggest ons-u-mb-no',
|
|
112
|
+
input: {
|
|
113
|
+
width: '50',
|
|
114
|
+
label: {
|
|
115
|
+
text: '[params.label.text]',
|
|
116
|
+
id: '[params.label.id]',
|
|
117
|
+
classes: 'ons-js-autosuggest-label',
|
|
118
|
+
},
|
|
119
|
+
value: '[params.value]',
|
|
120
|
+
attributes: '[params.attributes]',
|
|
121
|
+
error: '[params.error]',
|
|
122
|
+
name: '[params.name]',
|
|
123
|
+
mutuallyExclusive: '[params.mutuallyExclusive]',
|
|
124
|
+
},
|
|
125
|
+
externalInitialiser: true,
|
|
126
|
+
apiDomain: '[params.apiDomain]',
|
|
127
|
+
apiDomainBearerToken: '[params.apiDomainBearerToken]',
|
|
128
|
+
apiManualQueryParams: '[params.apiManualQueryParams]',
|
|
129
|
+
allowMultiple: '[params.allowMultiple]',
|
|
130
|
+
mandatory: '[params.mandatory]',
|
|
131
|
+
instructions: '[params.instructions]',
|
|
132
|
+
autocomplete: '[params.autocomplete]',
|
|
133
|
+
isEditable: '[params.isEditable]',
|
|
134
|
+
ariaYouHaveSelected: '[params.ariaYouHaveSelected]',
|
|
135
|
+
ariaMinChars: '[params.ariaMinChars]',
|
|
136
|
+
minChars: '[params.minChars]',
|
|
137
|
+
ariaOneResult: '[params.ariaOneResult]',
|
|
138
|
+
ariaNResults: '[params.ariaNResults]',
|
|
139
|
+
ariaLimitedResults: '[params.ariaLimitedResults]',
|
|
140
|
+
ariaGroupedResults: '[params.ariaGroupedResults]',
|
|
141
|
+
groupCount: '[params.groupCount]',
|
|
142
|
+
moreResults: '[params.moreResults]',
|
|
143
|
+
tooManyResults: '[params.tooManyResults]',
|
|
144
|
+
resultsTitle: '[params.resultsTitle]',
|
|
145
|
+
resultsTitleId: '[params.resultsTitleId]',
|
|
146
|
+
noResults: '[params.noResults]',
|
|
147
|
+
typeMore: '[params.typeMore]',
|
|
148
|
+
errorTitle: '[params.errorTitle]',
|
|
149
|
+
errorMessageEnter: '[params.errorMessageEnter]',
|
|
150
|
+
errorMessageSelect: '[params.errorMessageSelect]',
|
|
151
|
+
errorMessageApi: '[params.errorMessageApi]',
|
|
152
|
+
errorMessageApiLinkText: '[params.errorMessageApiLinkText]',
|
|
153
|
+
options: '[params.options]',
|
|
154
|
+
manualLinkUrl: '[params.manualLinkUrl]',
|
|
155
|
+
manualLinkText: '[params.manualLinkText]',
|
|
156
|
+
});
|
|
159
157
|
});
|
|
160
158
|
});
|
|
159
|
+
});
|
|
161
160
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
161
|
+
describe('GIVEN: Params: AddressField object', () => {
|
|
162
|
+
const faker = templateFaker();
|
|
163
|
+
const inputSpy = faker.spy('input', { suppressOutput: true });
|
|
165
164
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
165
|
+
faker.renderComponent('address-input', {
|
|
166
|
+
...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
|
|
167
|
+
...EXAMPLE_MANUAL_INPUT_FIELDS,
|
|
168
|
+
isEditable: true,
|
|
169
|
+
});
|
|
170
|
+
describe('WHEN: organisation is provided', () => {
|
|
171
|
+
test('THEN: it renders "organisation" input field with expected parameters', () => {
|
|
172
|
+
expect(inputSpy.occurrences).toContainEqual({
|
|
173
|
+
id: 'address-input-example-id-organisation',
|
|
174
|
+
name: 'address-input-example-id-organisation',
|
|
175
|
+
classes: 'ons-js-address-organisation',
|
|
176
|
+
label: {
|
|
177
|
+
text: 'Organisation name',
|
|
178
|
+
},
|
|
179
|
+
value: 'Example Organisation',
|
|
180
|
+
width: '20@m',
|
|
181
|
+
error: { text: 'Server error: organisation name' },
|
|
182
|
+
});
|
|
170
183
|
});
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
184
|
+
});
|
|
185
|
+
describe('WHEN: line1 is provided', () => {
|
|
186
|
+
test('THEN: it renders "address line 1" input field with expected parameters', () => {
|
|
187
|
+
expect(inputSpy.occurrences).toContainEqual({
|
|
188
|
+
id: 'address-input-example-id-line1',
|
|
189
|
+
name: 'address-input-example-id-line1',
|
|
190
|
+
classes: 'ons-js-address-line1',
|
|
191
|
+
label: {
|
|
192
|
+
text: 'Address line 1',
|
|
193
|
+
},
|
|
194
|
+
value: 'Flat 12345',
|
|
195
|
+
width: '20@m',
|
|
196
|
+
error: { text: 'Server error: address line 1' },
|
|
197
|
+
});
|
|
181
198
|
});
|
|
182
199
|
});
|
|
183
200
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
201
|
+
describe('WHEN: line2 is provided', () => {
|
|
202
|
+
test('THEN: it renders "address line 2" input field with expected parameters', () => {
|
|
203
|
+
expect(inputSpy.occurrences).toContainEqual({
|
|
204
|
+
id: 'address-input-example-id-line2',
|
|
205
|
+
name: 'address-input-example-id-line2',
|
|
206
|
+
classes: 'ons-js-address-line2',
|
|
207
|
+
label: {
|
|
208
|
+
text: 'Address line 2',
|
|
209
|
+
},
|
|
210
|
+
value: '12345 The Road',
|
|
211
|
+
width: '20@m',
|
|
212
|
+
error: { text: 'Server error: address line 2' },
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
});
|
|
187
216
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
217
|
+
describe('WHEN: town is provided', () => {
|
|
218
|
+
test('THEN: it renders "town or city" input field with expected parameters', () => {
|
|
219
|
+
expect(inputSpy.occurrences).toContainEqual({
|
|
220
|
+
id: 'address-input-example-id-town',
|
|
221
|
+
name: 'address-input-example-id-town',
|
|
222
|
+
classes: 'ons-js-address-town',
|
|
223
|
+
label: {
|
|
224
|
+
text: 'Town or city',
|
|
225
|
+
},
|
|
226
|
+
value: 'The Town',
|
|
227
|
+
error: { text: 'Server error: town or city' },
|
|
228
|
+
});
|
|
192
229
|
});
|
|
230
|
+
});
|
|
193
231
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
232
|
+
describe('WHEN: postcode is provided', () => {
|
|
233
|
+
test('THEN: it renders "postcode" input field with expected parameters', () => {
|
|
234
|
+
expect(inputSpy.occurrences).toContainEqual({
|
|
235
|
+
id: 'address-input-example-id-postcode',
|
|
236
|
+
name: 'address-input-example-id-postcode',
|
|
237
|
+
classes: 'ons-js-address-postcode',
|
|
238
|
+
label: {
|
|
239
|
+
text: 'Postcode',
|
|
240
|
+
},
|
|
241
|
+
value: 'PO57 6ODE',
|
|
242
|
+
width: '7',
|
|
243
|
+
error: { text: 'Server error: postcode' },
|
|
244
|
+
});
|
|
204
245
|
});
|
|
205
246
|
});
|
|
206
247
|
});
|
|
207
248
|
|
|
208
|
-
describe('
|
|
209
|
-
|
|
249
|
+
describe('GIVEN: Params: searchButton for no-js', () => {
|
|
250
|
+
describe('WHEN: manualEntry parameter is set to true', () => {
|
|
210
251
|
const $ = cheerio.load(
|
|
211
252
|
renderComponent('address-input', {
|
|
212
253
|
...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
|
|
@@ -215,11 +256,12 @@ describe('macro: address-input', () => {
|
|
|
215
256
|
searchButton: 'Search for address',
|
|
216
257
|
}),
|
|
217
258
|
);
|
|
218
|
-
|
|
219
|
-
|
|
259
|
+
test('THEN: search button does not render', () => {
|
|
260
|
+
expect($('.ons-js-address-search-btn').length).toBe(0);
|
|
261
|
+
});
|
|
220
262
|
});
|
|
221
263
|
|
|
222
|
-
|
|
264
|
+
describe('WHEN: manualEntry parameter is not set', () => {
|
|
223
265
|
const $ = cheerio.load(
|
|
224
266
|
renderComponent('address-input', {
|
|
225
267
|
...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
|
|
@@ -228,39 +270,35 @@ describe('macro: address-input', () => {
|
|
|
228
270
|
}),
|
|
229
271
|
);
|
|
230
272
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
it('renders provided text for search button', () => {
|
|
235
|
-
const $ = cheerio.load(
|
|
236
|
-
renderComponent('address-input', {
|
|
237
|
-
...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
|
|
238
|
-
isEditable: true,
|
|
239
|
-
searchButton: 'Search for address',
|
|
240
|
-
}),
|
|
241
|
-
);
|
|
273
|
+
test('THEN: search button is displayed', () => {
|
|
274
|
+
expect($('.ons-js-address-search-btn').hasClass('ons-u-db-no-js_disabled')).toBe(true);
|
|
275
|
+
});
|
|
242
276
|
|
|
243
|
-
|
|
277
|
+
test('THEN: it renders search button with provided text', () => {
|
|
278
|
+
expect($('.ons-js-address-search-btn').text().trim()).toBe('Search for address');
|
|
279
|
+
});
|
|
244
280
|
});
|
|
245
281
|
});
|
|
246
282
|
|
|
247
|
-
describe('
|
|
248
|
-
|
|
283
|
+
describe('GIVEN: Params: uprn', () => {
|
|
284
|
+
describe('WHEN: uprn.value is not provided', () => {
|
|
249
285
|
const faker = templateFaker();
|
|
250
286
|
const inputSpy = faker.spy('input', { suppressOutput: true });
|
|
251
287
|
|
|
252
288
|
faker.renderComponent('address-input', EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL);
|
|
253
289
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
290
|
+
test('THEN: it renders hidden input component with expected parameters', () => {
|
|
291
|
+
expect(inputSpy.occurrences).toContainEqual({
|
|
292
|
+
id: 'address-input-example-id-uprn',
|
|
293
|
+
classes: 'ons-js-hidden-uprn ons-u-d-no',
|
|
294
|
+
type: 'hidden',
|
|
295
|
+
name: 'address-input-example-id-uprn',
|
|
296
|
+
value: '',
|
|
297
|
+
});
|
|
260
298
|
});
|
|
261
299
|
});
|
|
262
300
|
|
|
263
|
-
|
|
301
|
+
describe('WHEN: uprn.value is provided', () => {
|
|
264
302
|
const faker = templateFaker();
|
|
265
303
|
const inputSpy = faker.spy('input', { suppressOutput: true });
|
|
266
304
|
|
|
@@ -271,131 +309,20 @@ describe('macro: address-input', () => {
|
|
|
271
309
|
},
|
|
272
310
|
});
|
|
273
311
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
312
|
+
test('THEN: it renders hidden input component with expected parameters', () => {
|
|
313
|
+
expect(inputSpy.occurrences).toContainEqual({
|
|
314
|
+
id: 'address-input-example-id-uprn',
|
|
315
|
+
classes: 'ons-js-hidden-uprn ons-u-d-no',
|
|
316
|
+
type: 'hidden',
|
|
317
|
+
name: 'address-input-example-id-uprn',
|
|
318
|
+
value: '[params.uprn.value]',
|
|
319
|
+
});
|
|
280
320
|
});
|
|
281
321
|
});
|
|
282
322
|
});
|
|
283
323
|
|
|
284
|
-
describe('
|
|
285
|
-
|
|
286
|
-
const faker = templateFaker();
|
|
287
|
-
const autosuggestSpy = faker.spy('autosuggest', { suppressOutput: true });
|
|
288
|
-
|
|
289
|
-
faker.renderComponent('address-input', {
|
|
290
|
-
...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
|
|
291
|
-
manualEntry: true,
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
expect(autosuggestSpy.occurrences.length).toBe(0);
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
it('renders `autosuggest` component with expected parameters', () => {
|
|
298
|
-
const faker = templateFaker();
|
|
299
|
-
const autosuggestSpy = faker.spy('autosuggest', { suppressOutput: true });
|
|
300
|
-
|
|
301
|
-
// Since `autosuggestSpy` suppresses output the values being tested below do not
|
|
302
|
-
// need to represent real values. This test is only interested in verifying that
|
|
303
|
-
// the provided values are being passed through to the `autosuggest` component.
|
|
304
|
-
faker.renderComponent('address-input', {
|
|
305
|
-
...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
|
|
306
|
-
label: {
|
|
307
|
-
text: '[params.label.text]',
|
|
308
|
-
id: '[params.label.id]',
|
|
309
|
-
},
|
|
310
|
-
value: '[params.value]',
|
|
311
|
-
attributes: '[params.attributes]',
|
|
312
|
-
error: '[params.error]',
|
|
313
|
-
name: '[params.name]',
|
|
314
|
-
mutuallyExclusive: '[params.mutuallyExclusive]',
|
|
315
|
-
apiDomain: '[params.apiDomain]',
|
|
316
|
-
apiDomainBearerToken: '[params.apiDomainBearerToken]',
|
|
317
|
-
apiManualQueryParams: '[params.apiManualQueryParams]',
|
|
318
|
-
allowMultiple: '[params.allowMultiple]',
|
|
319
|
-
mandatory: '[params.mandatory]',
|
|
320
|
-
instructions: '[params.instructions]',
|
|
321
|
-
autocomplete: '[params.autocomplete]',
|
|
322
|
-
isEditable: '[params.isEditable]',
|
|
323
|
-
ariaYouHaveSelected: '[params.ariaYouHaveSelected]',
|
|
324
|
-
ariaMinChars: '[params.ariaMinChars]',
|
|
325
|
-
minChars: '[params.minChars]',
|
|
326
|
-
ariaResultsLabel: '[params.ariaResultsLabel]',
|
|
327
|
-
ariaOneResult: '[params.ariaOneResult]',
|
|
328
|
-
ariaNResults: '[params.ariaNResults]',
|
|
329
|
-
ariaLimitedResults: '[params.ariaLimitedResults]',
|
|
330
|
-
ariaGroupedResults: '[params.ariaGroupedResults]',
|
|
331
|
-
groupCount: '[params.groupCount]',
|
|
332
|
-
moreResults: '[params.moreResults]',
|
|
333
|
-
tooManyResults: '[params.tooManyResults]',
|
|
334
|
-
resultsTitle: '[params.resultsTitle]',
|
|
335
|
-
resultsTitleId: '[params.resultsTitleId]',
|
|
336
|
-
noResults: '[params.noResults]',
|
|
337
|
-
typeMore: '[params.typeMore]',
|
|
338
|
-
errorTitle: '[params.errorTitle]',
|
|
339
|
-
errorMessageEnter: '[params.errorMessageEnter]',
|
|
340
|
-
errorMessageSelect: '[params.errorMessageSelect]',
|
|
341
|
-
errorMessageApi: '[params.errorMessageApi]',
|
|
342
|
-
errorMessageApiLinkText: '[params.errorMessageApiLinkText]',
|
|
343
|
-
options: '[params.options]',
|
|
344
|
-
manualLinkUrl: '[params.manualLinkUrl]',
|
|
345
|
-
manualLinkText: '[params.manualLinkText]',
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
expect(autosuggestSpy.occurrences[0]).toEqual({
|
|
349
|
-
id: 'address-input-example-id-autosuggest',
|
|
350
|
-
classes: 'ons-address-input__autosuggest ons-u-mb-no',
|
|
351
|
-
input: {
|
|
352
|
-
width: '50',
|
|
353
|
-
label: {
|
|
354
|
-
text: '[params.label.text]',
|
|
355
|
-
id: '[params.label.id]',
|
|
356
|
-
classes: 'ons-js-autosuggest-label',
|
|
357
|
-
},
|
|
358
|
-
value: '[params.value]',
|
|
359
|
-
attributes: '[params.attributes]',
|
|
360
|
-
error: '[params.error]',
|
|
361
|
-
name: '[params.name]',
|
|
362
|
-
mutuallyExclusive: '[params.mutuallyExclusive]',
|
|
363
|
-
},
|
|
364
|
-
externalInitialiser: true,
|
|
365
|
-
apiDomain: '[params.apiDomain]',
|
|
366
|
-
apiDomainBearerToken: '[params.apiDomainBearerToken]',
|
|
367
|
-
apiManualQueryParams: '[params.apiManualQueryParams]',
|
|
368
|
-
allowMultiple: '[params.allowMultiple]',
|
|
369
|
-
mandatory: '[params.mandatory]',
|
|
370
|
-
instructions: '[params.instructions]',
|
|
371
|
-
autocomplete: '[params.autocomplete]',
|
|
372
|
-
isEditable: '[params.isEditable]',
|
|
373
|
-
ariaYouHaveSelected: '[params.ariaYouHaveSelected]',
|
|
374
|
-
ariaMinChars: '[params.ariaMinChars]',
|
|
375
|
-
minChars: '[params.minChars]',
|
|
376
|
-
ariaOneResult: '[params.ariaOneResult]',
|
|
377
|
-
ariaNResults: '[params.ariaNResults]',
|
|
378
|
-
ariaLimitedResults: '[params.ariaLimitedResults]',
|
|
379
|
-
ariaGroupedResults: '[params.ariaGroupedResults]',
|
|
380
|
-
groupCount: '[params.groupCount]',
|
|
381
|
-
moreResults: '[params.moreResults]',
|
|
382
|
-
tooManyResults: '[params.tooManyResults]',
|
|
383
|
-
resultsTitle: '[params.resultsTitle]',
|
|
384
|
-
resultsTitleId: '[params.resultsTitleId]',
|
|
385
|
-
noResults: '[params.noResults]',
|
|
386
|
-
typeMore: '[params.typeMore]',
|
|
387
|
-
errorTitle: '[params.errorTitle]',
|
|
388
|
-
errorMessageEnter: '[params.errorMessageEnter]',
|
|
389
|
-
errorMessageSelect: '[params.errorMessageSelect]',
|
|
390
|
-
errorMessageApi: '[params.errorMessageApi]',
|
|
391
|
-
errorMessageApiLinkText: '[params.errorMessageApiLinkText]',
|
|
392
|
-
options: '[params.options]',
|
|
393
|
-
manualLinkUrl: '[params.manualLinkUrl]',
|
|
394
|
-
manualLinkText: '[params.manualLinkText]',
|
|
395
|
-
});
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
it('renders manualLinkText` when provided with a default value for `manualLinkUrl`', () => {
|
|
324
|
+
describe('GIVEN: Params: manualLink', () => {
|
|
325
|
+
describe('WHEN: provided with a default value for manualLink', () => {
|
|
399
326
|
const $ = cheerio.load(
|
|
400
327
|
renderComponent('address-input', {
|
|
401
328
|
...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
|
|
@@ -404,26 +331,18 @@ describe('macro: address-input', () => {
|
|
|
404
331
|
}),
|
|
405
332
|
);
|
|
406
333
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
it('renders `manualLinkText` with `manualLinkUrl` when provided', () => {
|
|
412
|
-
const $ = cheerio.load(
|
|
413
|
-
renderComponent('address-input', {
|
|
414
|
-
...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
|
|
415
|
-
manualLinkUrl: 'https://example.com/edit-address',
|
|
416
|
-
manualLinkText: 'Manually enter address',
|
|
417
|
-
}),
|
|
418
|
-
);
|
|
334
|
+
test('THEN: it renders the manual link with the provided url', () => {
|
|
335
|
+
expect($('.ons-js-address-manual-btn').attr('href')).toBe('#0');
|
|
336
|
+
});
|
|
419
337
|
|
|
420
|
-
|
|
421
|
-
|
|
338
|
+
test('THEN: it renders the manual link with the provided text', () => {
|
|
339
|
+
expect($('.ons-js-address-manual-btn').text().trim()).toBe('Manually enter address');
|
|
340
|
+
});
|
|
422
341
|
});
|
|
423
342
|
});
|
|
424
343
|
|
|
425
|
-
describe('
|
|
426
|
-
|
|
344
|
+
describe('GIVEN: Params: dontWrap', () => {
|
|
345
|
+
describe('WHEN: dontWrap is true', () => {
|
|
427
346
|
const faker = templateFaker();
|
|
428
347
|
const fieldsetSpy = faker.spy('fieldset', { suppressOutput: true });
|
|
429
348
|
|
|
@@ -432,10 +351,12 @@ describe('macro: address-input', () => {
|
|
|
432
351
|
dontWrap: true,
|
|
433
352
|
});
|
|
434
353
|
|
|
435
|
-
|
|
354
|
+
test('THEN: it does not render fieldset component', () => {
|
|
355
|
+
expect(fieldsetSpy.occurrences.length).toBe(0);
|
|
356
|
+
});
|
|
436
357
|
});
|
|
437
358
|
|
|
438
|
-
|
|
359
|
+
describe('WHEN: dontWrap is not set', () => {
|
|
439
360
|
const faker = templateFaker();
|
|
440
361
|
const fieldsetSpy = faker.spy('fieldset', { suppressOutput: true });
|
|
441
362
|
|
|
@@ -445,11 +366,13 @@ describe('macro: address-input', () => {
|
|
|
445
366
|
legendClasses: 'extra-legend-class',
|
|
446
367
|
});
|
|
447
368
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
369
|
+
test('THEN: it renders the fieldset component with expected parameters', () => {
|
|
370
|
+
expect(fieldsetSpy.occurrences[0]).toEqual({
|
|
371
|
+
id: 'address-input-example-id',
|
|
372
|
+
classes: 'extra-field-class',
|
|
373
|
+
legend: 'What is the address?',
|
|
374
|
+
legendClasses: 'extra-legend-class',
|
|
375
|
+
});
|
|
453
376
|
});
|
|
454
377
|
});
|
|
455
378
|
});
|