Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
querkmachine committed Dec 6, 2024
1 parent b0c083b commit f795005
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ examples:
</ul>
# Hidden examples are not shown in the review app, but are used for tests and HTML fixtures
- name: id
hidden: true
options:
id: custom-id
items:
- heading:
text: Section A
content:
text: Some content
- name: classes
hidden: true
options:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,18 @@ describe('Accordion', () => {
it('renders with id', () => {
const $component = document.querySelector('.govuk-accordion')

expect($component).toHaveAttribute('id', 'default-example')
expect($component).toHaveAttribute('id', 'accordion')
})
})

describe('custom options', () => {
it('renders with id', () => {
document.body.innerHTML = render('accordion', examples.id)
const $component = document.querySelector('.govuk-accordion')

expect($component).toHaveAttribute('id', 'custom-id')
})

it('renders with classes', () => {
document.body.innerHTML = render('accordion', examples.classes)
const $component = document.querySelector('.govuk-accordion')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ exports[`Date input nested dependant components passes through fieldset params w

exports[`Date input nested dependant components passes through label params without breaking 1`] = `
<label class="govuk-label govuk-date-input__label"
for="dob-day"
for="date-input-day"
>
Day
</label>
<label class="govuk-label govuk-date-input__label"
for="dob-month"
for="date-input-month"
>
Month
</label>
<label class="govuk-label govuk-date-input__label"
for="dob-year"
for="date-input-year"
>
Year
</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Date input', () => {
const $ = render('date-input', examples.default)

const $component = $('.govuk-date-input')
expect($component.attr('id')).toBe('dob')
expect($component.attr('id')).toBe('date-input')
})

it('renders default inputs', () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/govuk-frontend/src/govuk/components/input/input.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,13 @@ examples:
value: QQ 12 34 56 C

# Hidden examples are not shown in the review app, but are used for tests and HTML fixtures
- name: id
hidden: true
options:
id: test-id
name: different-name
label:
text: With custom ID
- name: classes
hidden: true
options:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ describe('Input', () => {
$label = document.querySelector('.govuk-label')
})

it('sets the `id` attribute based on the `id` option', () => {
expect($component).toHaveAttribute('id', 'input-example')
})

it('sets the `name` attribute based on the `name` option', () => {
expect($component).toHaveAttribute('name', 'test-name')
})

it('sets the `id` attribute based on the `name` option', () => {
const inputName = $component.getAttribute('name')
expect($component).toHaveAttribute('id', inputName)
})

it('sets the `type` attribute to a default value of "text"', () => {
expect($component).toHaveAttribute('type', 'text')
})
Expand Down Expand Up @@ -65,6 +66,13 @@ describe('Input', () => {
})

describe('custom options', () => {
it('sets the `id` attribute based on the `id` option', () => {
document.body.innerHTML = render('input', examples.id)

const $component = document.querySelector('.govuk-input')
expect($component).toHaveAttribute('id', 'test-id')
})

it('includes additional classes from the `classes` option', () => {
document.body.innerHTML = render('input', examples.classes)

Expand Down

0 comments on commit f795005

Please sign in to comment.