Skip to content

Commit f795005

Browse files
committed
Update tests
1 parent b0c083b commit f795005

File tree

6 files changed

+40
-9
lines changed

6 files changed

+40
-9
lines changed

packages/govuk-frontend/src/govuk/components/accordion/accordion.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,15 @@ examples:
234234
</ul>
235235
236236
# Hidden examples are not shown in the review app, but are used for tests and HTML fixtures
237+
- name: id
238+
hidden: true
239+
options:
240+
id: custom-id
241+
items:
242+
- heading:
243+
text: Section A
244+
content:
245+
text: Some content
237246
- name: classes
238247
hidden: true
239248
options:

packages/govuk-frontend/src/govuk/components/accordion/template.jsdom.test.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,18 @@ describe('Accordion', () => {
4444
it('renders with id', () => {
4545
const $component = document.querySelector('.govuk-accordion')
4646

47-
expect($component).toHaveAttribute('id', 'default-example')
47+
expect($component).toHaveAttribute('id', 'accordion')
4848
})
4949
})
5050

5151
describe('custom options', () => {
52+
it('renders with id', () => {
53+
document.body.innerHTML = render('accordion', examples.id)
54+
const $component = document.querySelector('.govuk-accordion')
55+
56+
expect($component).toHaveAttribute('id', 'custom-id')
57+
})
58+
5259
it('renders with classes', () => {
5360
document.body.innerHTML = render('accordion', examples.classes)
5461
const $component = document.querySelector('.govuk-accordion')

packages/govuk-frontend/src/govuk/components/date-input/__snapshots__/template.test.js.snap

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ exports[`Date input nested dependant components passes through fieldset params w
1313

1414
exports[`Date input nested dependant components passes through label params without breaking 1`] = `
1515
<label class="govuk-label govuk-date-input__label"
16-
for="dob-day"
16+
for="date-input-day"
1717
>
1818
Day
1919
</label>
2020
<label class="govuk-label govuk-date-input__label"
21-
for="dob-month"
21+
for="date-input-month"
2222
>
2323
Month
2424
</label>
2525
<label class="govuk-label govuk-date-input__label"
26-
for="dob-year"
26+
for="date-input-year"
2727
>
2828
Year
2929
</label>

packages/govuk-frontend/src/govuk/components/date-input/template.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('Date input', () => {
1717
const $ = render('date-input', examples.default)
1818

1919
const $component = $('.govuk-date-input')
20-
expect($component.attr('id')).toBe('dob')
20+
expect($component.attr('id')).toBe('date-input')
2121
})
2222

2323
it('renders default inputs', () => {

packages/govuk-frontend/src/govuk/components/input/input.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,13 @@ examples:
388388
value: QQ 12 34 56 C
389389

390390
# Hidden examples are not shown in the review app, but are used for tests and HTML fixtures
391+
- name: id
392+
hidden: true
393+
options:
394+
id: test-id
395+
name: different-name
396+
label:
397+
text: With custom ID
391398
- name: classes
392399
hidden: true
393400
options:

packages/govuk-frontend/src/govuk/components/input/template.jsdom.test.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ describe('Input', () => {
1717
$label = document.querySelector('.govuk-label')
1818
})
1919

20-
it('sets the `id` attribute based on the `id` option', () => {
21-
expect($component).toHaveAttribute('id', 'input-example')
22-
})
23-
2420
it('sets the `name` attribute based on the `name` option', () => {
2521
expect($component).toHaveAttribute('name', 'test-name')
2622
})
2723

24+
it('sets the `id` attribute based on the `name` option', () => {
25+
const inputName = $component.getAttribute('name')
26+
expect($component).toHaveAttribute('id', inputName)
27+
})
28+
2829
it('sets the `type` attribute to a default value of "text"', () => {
2930
expect($component).toHaveAttribute('type', 'text')
3031
})
@@ -65,6 +66,13 @@ describe('Input', () => {
6566
})
6667

6768
describe('custom options', () => {
69+
it('sets the `id` attribute based on the `id` option', () => {
70+
document.body.innerHTML = render('input', examples.id)
71+
72+
const $component = document.querySelector('.govuk-input')
73+
expect($component).toHaveAttribute('id', 'test-id')
74+
})
75+
6876
it('includes additional classes from the `classes` option', () => {
6977
document.body.innerHTML = render('input', examples.classes)
7078

0 commit comments

Comments
 (0)