Skip to content

Commit

Permalink
Fix missing elements using id="content" on the preview container
Browse files Browse the repository at this point in the history
Fixes Skip link `href` target and various ARIA referenced elements
  • Loading branch information
colinrotherham committed Nov 1, 2023
1 parent 345abcd commit 3ed9d1f
Show file tree
Hide file tree
Showing 22 changed files with 65 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,13 @@ import { axe, render } from '@govuk-frontend/helpers/puppeteer'
import { getExamples } from '@govuk-frontend/lib/components'

describe('/components/button', () => {
let axeRules

beforeAll(() => {
axeRules = {
/**
* Ignore 'Invalid ARIA attribute value: aria-controls="example-id"'
* for missing IDs
*/
'aria-valid-attr-value': { enabled: false }
}
})

describe('component examples', () => {
it('passes accessibility tests', async () => {
const examples = await getExamples('button')

for (const exampleName in examples) {
await render(page, 'button', examples[exampleName])
await expect(axe(page, axeRules)).resolves.toHaveNoViolations()
await expect(axe(page)).resolves.toHaveNoViolations()
}
}, 120000)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,23 +186,23 @@ examples:
element: button
text: Submit
attributes:
aria-controls: example-id
aria-controls: content
data-tracking-dimension: 123
- name: link attributes
hidden: true
options:
element: a
text: Submit
attributes:
aria-controls: example-id
aria-controls: content
data-tracking-dimension: 123
- name: input attributes
hidden: true
options:
element: input
text: Submit
attributes:
aria-controls: example-id
aria-controls: content
data-tracking-dimension: 123
- name: classes
hidden: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Button', () => {
const $ = render('button', examples.attributes)

const $component = $('.govuk-button')
expect($component.attr('aria-controls')).toEqual('example-id')
expect($component.attr('aria-controls')).toEqual('content')
expect($component.attr('data-tracking-dimension')).toEqual('123')
})

Expand Down Expand Up @@ -123,7 +123,7 @@ describe('Button', () => {
const $ = render('button', examples['link attributes'])

const $component = $('.govuk-button')
expect($component.attr('aria-controls')).toEqual('example-id')
expect($component.attr('aria-controls')).toEqual('content')
expect($component.attr('data-tracking-dimension')).toEqual('123')
})

Expand All @@ -148,7 +148,7 @@ describe('Button', () => {
const $ = render('button', examples['input attributes'])

const $component = $('.govuk-button')
expect($component.attr('aria-controls')).toEqual('example-id')
expect($component.attr('aria-controls')).toEqual('content')
expect($component.attr('data-tracking-dimension')).toEqual('123')
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ examples:
options:
name: example-name
fieldset:
describedBy: some-id
describedBy: content
legend:
text: Which option?
items:
Expand Down Expand Up @@ -804,7 +804,7 @@ examples:
errorMessage:
text: Please select an option
fieldset:
describedBy: some-id
describedBy: content
legend:
text: What is your nationality?
hint:
Expand Down Expand Up @@ -858,7 +858,7 @@ examples:
- name: with single option set 'aria-describedby' on input, and describedBy
hidden: true
options:
describedBy: some-id
describedBy: content
name: t-and-c
errorMessage:
text: Please accept the terms and conditions
Expand All @@ -868,7 +868,7 @@ examples:
- name: with single option (and hint) set 'aria-describedby' on input, and describedBy
hidden: true
options:
describedBy: some-id
describedBy: content
name: t-and-c-with-hint
errorMessage:
text: Please accept the terms and conditions
Expand All @@ -894,7 +894,7 @@ examples:
errorMessage:
text: Please select an option
fieldset:
describedBy: some-id
describedBy: content
legend:
text: What is your nationality?
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('Checkboxes', () => {
const $ = render('checkboxes', examples['with fieldset describedBy'])

const $fieldset = $('.govuk-fieldset')
expect($fieldset.attr('aria-describedby')).toMatch('some-id')
expect($fieldset.attr('aria-describedby')).toMatch('content')
})

it('render attributes', () => {
Expand Down Expand Up @@ -404,7 +404,7 @@ describe('Checkboxes', () => {
const errorMessageId = $('.govuk-error-message').attr('id')

const describedBy = new RegExp(
`${WORD_BOUNDARY}some-id${WHITESPACE}${errorMessageId}${WORD_BOUNDARY}`
`${WORD_BOUNDARY}content${WHITESPACE}${errorMessageId}${WORD_BOUNDARY}`
)

expect($fieldset.attr('aria-describedby')).toMatch(describedBy)
Expand Down Expand Up @@ -461,7 +461,7 @@ describe('Checkboxes', () => {
const hintId = $('.govuk-hint').attr('id')

const describedBy = new RegExp(
`${WORD_BOUNDARY}some-id${WHITESPACE}${hintId}${WORD_BOUNDARY}`
`${WORD_BOUNDARY}content${WHITESPACE}${hintId}${WORD_BOUNDARY}`
)

expect($fieldset.attr('aria-describedby')).toMatch(describedBy)
Expand Down Expand Up @@ -495,7 +495,7 @@ describe('Checkboxes', () => {
const errorMessageId = $('.govuk-error-message').attr('id')

const describedByCombined = new RegExp(
`${WORD_BOUNDARY}some-id${WHITESPACE}${hintId}${WHITESPACE}${errorMessageId}${WORD_BOUNDARY}`
`${WORD_BOUNDARY}content${WHITESPACE}${hintId}${WHITESPACE}${errorMessageId}${WORD_BOUNDARY}`
)

expect($fieldset.attr('aria-describedby')).toMatch(describedByCombined)
Expand Down Expand Up @@ -548,7 +548,7 @@ describe('Checkboxes', () => {
const $ = render('checkboxes', examples[exampleName])
const $input = $('input')

expect($input.attr('aria-describedby')).toMatch('some-id t-and-c-error')
expect($input.attr('aria-describedby')).toMatch('content t-and-c-error')
})
})

Expand All @@ -573,7 +573,7 @@ describe('Checkboxes', () => {
const $input = $('input')

expect($input.attr('aria-describedby')).toMatch(
'some-id t-and-c-with-hint-error t-and-c-with-hint-item-hint'
'content t-and-c-with-hint-error t-and-c-with-hint-item-hint'
)
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ examples:
options:
id: dob-errors
fieldset:
describedBy: some-id
describedBy: content
legend:
text: What is your date of birth?
hint:
Expand All @@ -359,7 +359,7 @@ examples:
options:
id: dob-errors
fieldset:
describedBy: some-id
describedBy: content
legend:
text: What is your date of birth?
errorMessage:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe('Date input', () => {
const hintId = $('.govuk-hint').attr('id')

const describedBy = new RegExp(
`${WORD_BOUNDARY}some-id${WHITESPACE}${hintId}${WORD_BOUNDARY}`
`${WORD_BOUNDARY}content${WHITESPACE}${hintId}${WORD_BOUNDARY}`
)

expect($fieldset.attr('aria-describedby')).toMatch(describedBy)
Expand Down Expand Up @@ -246,7 +246,7 @@ describe('Date input', () => {
const $fieldset = $('.govuk-fieldset')

expect($fieldset.attr('aria-describedby')).toMatch(
'some-id dob-errors-error'
'content dob-errors-error'
)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ examples:
- name: with describedBy
hidden: true
options:
describedBy: some-id
describedBy: content
legend:
text: Which option?
- name: html as text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('fieldset', () => {
const $ = render('fieldset', examples['with describedBy'])

const $component = $('.govuk-fieldset')
expect($component.attr('aria-describedby')).toEqual('some-id')
expect($component.attr('aria-describedby')).toEqual('content')
})

it('escapes HTML in the text argument', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ examples:
name: file-upload-describedby
label:
text: Upload a file
describedBy: some-id
describedBy: content
- name: with hint and describedBy
hidden: true
options:
id: file-upload-hint-describedby
name: file-upload-hint-describedby
label:
text: Upload a file
describedBy: some-id
describedBy: content
hint:
text: Your photo may be in your Pictures, Photos, Downloads or Desktop folder. Or in an app like iPhoto.
- name: error
Expand All @@ -153,7 +153,7 @@ examples:
name: file-upload-error-describedby
label:
text: Upload a file
describedBy: some-id
describedBy: content
errorMessage:
text: Error message
- name: with error, describedBy and hint
Expand All @@ -163,7 +163,7 @@ examples:
name: file-upload-error-describedby-hint
label:
text: Upload a file
describedBy: some-id
describedBy: content
errorMessage:
text: Error message
hint:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('File upload', () => {
const $ = render('file-upload', examples['with describedBy'])

const $component = $('.govuk-file-upload')
expect($component.attr('aria-describedby')).toMatch('some-id')
expect($component.attr('aria-describedby')).toMatch('content')
})

it('renders with attributes', () => {
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('File upload', () => {
const hintId = $('.govuk-hint').attr('id')

const describedBy = new RegExp(
`${WORD_BOUNDARY}some-id${WHITESPACE}${hintId}${WORD_BOUNDARY}`
`${WORD_BOUNDARY}content${WHITESPACE}${hintId}${WORD_BOUNDARY}`
)

expect($component.attr('aria-describedby')).toMatch(describedBy)
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('File upload', () => {
const errorMessageId = $('.govuk-error-message').attr('id')

const describedBy = new RegExp(
`${WORD_BOUNDARY}some-id${WHITESPACE}${errorMessageId}${WORD_BOUNDARY}`
`${WORD_BOUNDARY}content${WHITESPACE}${errorMessageId}${WORD_BOUNDARY}`
)

expect($component.attr('aria-describedby')).toMatch(describedBy)
Expand Down Expand Up @@ -175,7 +175,7 @@ describe('File upload', () => {
})

it('associates the input as described by the hint, error message and parent fieldset', () => {
const describedById = 'some-id'
const describedById = 'content'

const $ = render(
'file-upload',
Expand Down
8 changes: 4 additions & 4 deletions packages/govuk-frontend/src/govuk/components/input/input.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ examples:
name: with-describedby
label:
text: With describedBy
describedBy: some-id
describedBy: content
- name: attributes
hidden: true
options:
Expand All @@ -368,7 +368,7 @@ examples:
name: with-hint-describedby
label:
text: With hint describedBy
describedBy: some-id
describedBy: content
hint:
text: It’s on your National Insurance card, benefit letter, payslip or P60. For example, ‘QQ 12 34 56 C’.
- name: error with describedBy
Expand All @@ -378,7 +378,7 @@ examples:
name: with-error-describedby
label:
text: With error describedBy
describedBy: some-id
describedBy: content
errorMessage:
text: Error message
- name: with error and hint
Expand All @@ -403,7 +403,7 @@ examples:
text: Error message
hint:
text: Hint
describedBy: some-id
describedBy: content
- name: inputmode
hidden: true
options:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('Input', () => {
const $ = render('input', examples['with describedBy'])

const $component = $('.govuk-input')
expect($component.attr('aria-describedby')).toMatch('some-id')
expect($component.attr('aria-describedby')).toMatch('content')
})

it('renders with attributes', () => {
Expand Down Expand Up @@ -127,7 +127,7 @@ describe('Input', () => {
const hintId = $('.govuk-hint').attr('id')

const describedBy = new RegExp(
`${WORD_BOUNDARY}some-id${WHITESPACE}${hintId}${WORD_BOUNDARY}`
`${WORD_BOUNDARY}content${WHITESPACE}${hintId}${WORD_BOUNDARY}`
)

expect($input.attr('aria-describedby')).toMatch(describedBy)
Expand Down Expand Up @@ -161,7 +161,7 @@ describe('Input', () => {
const errorMessageId = $('.govuk-error-message').attr('id')

const describedBy = new RegExp(
`${WORD_BOUNDARY}some-id${WHITESPACE}${errorMessageId}${WORD_BOUNDARY}`
`${WORD_BOUNDARY}content${WHITESPACE}${errorMessageId}${WORD_BOUNDARY}`
)

expect($input.attr('aria-describedby')).toMatch(describedBy)
Expand Down Expand Up @@ -228,7 +228,7 @@ describe('Input', () => {
const hintId = $('.govuk-hint').attr('id')

const describedByCombined = new RegExp(
`${WORD_BOUNDARY}some-id${WHITESPACE}${hintId}${WHITESPACE}${errorMessageId}${WORD_BOUNDARY}`
`${WORD_BOUNDARY}content${WHITESPACE}${hintId}${WHITESPACE}${errorMessageId}${WORD_BOUNDARY}`
)

expect($component.attr('aria-describedby')).toMatch(describedByCombined)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ examples:
- name: for
hidden: true
options:
for: '#dummy-input'
for: content
text: National Insurance number
- name: attributes
hidden: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('Label', () => {
const $ = render('label', examples.for)

const labelForAttr = $('.govuk-label').attr('for')
expect(labelForAttr).toEqual('#dummy-input')
expect(labelForAttr).toEqual('content')
})

it('can be nested inside an H1 using isPageHeading', () => {
Expand Down
Loading

0 comments on commit 3ed9d1f

Please sign in to comment.