|
1 | | -import { ComponentType, type UkAddressFieldComponent } from '@defra/forms-model' |
| 1 | +import { |
| 2 | + ComponentType, |
| 3 | + type TextFieldComponent, |
| 4 | + type UkAddressFieldComponent |
| 5 | +} from '@defra/forms-model' |
2 | 6 |
|
3 | 7 | import { ComponentCollection } from '~/src/server/plugins/engine/components/ComponentCollection.js' |
| 8 | +import { UkAddressField } from '~/src/server/plugins/engine/components/UkAddressField.js' |
4 | 9 | import { |
5 | 10 | getAnswer, |
6 | 11 | type Field |
@@ -272,6 +277,40 @@ describe('UkAddressField', () => { |
272 | 277 | expect(result2.errors).toBeTruthy() |
273 | 278 | expect(result3.errors).toBeTruthy() |
274 | 279 | }) |
| 280 | + |
| 281 | + it('should ensure all address fields have valid autocomplete values', () => { |
| 282 | + const ukAddressField = new UkAddressField( |
| 283 | + { |
| 284 | + type: ComponentType.UkAddressField, |
| 285 | + name: 'testAddress', |
| 286 | + title: 'Test Address', |
| 287 | + options: { |
| 288 | + required: true, |
| 289 | + hideTitle: false |
| 290 | + } |
| 291 | + }, |
| 292 | + { |
| 293 | + model |
| 294 | + } |
| 295 | + ) |
| 296 | + |
| 297 | + const expectedAutocompleteValues = [ |
| 298 | + 'address-line1', |
| 299 | + 'address-line2', |
| 300 | + 'address-level1', |
| 301 | + 'address-level2', |
| 302 | + 'postal-code' |
| 303 | + ] |
| 304 | + |
| 305 | + ukAddressField.collection.components.forEach((component) => { |
| 306 | + const addressFieldOptions = |
| 307 | + component.options as TextFieldComponent['options'] |
| 308 | + |
| 309 | + expect(expectedAutocompleteValues).toContain( |
| 310 | + addressFieldOptions.autocomplete |
| 311 | + ) |
| 312 | + }) |
| 313 | + }) |
275 | 314 | }) |
276 | 315 |
|
277 | 316 | describe('State', () => { |
@@ -396,7 +435,7 @@ describe('UkAddressField', () => { |
396 | 435 | expect.objectContaining({ |
397 | 436 | model: getViewModel(address, 'county', { |
398 | 437 | label: { text: 'County (optional)' }, |
399 | | - attributes: { autocomplete: 'county' }, |
| 438 | + attributes: { autocomplete: 'address-level1' }, |
400 | 439 | value: address.county |
401 | 440 | }) |
402 | 441 | }), |
|
0 commit comments