-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5065 from alphagov/jsdom-warning-text-template-tests
Update warning text template tests to use jsdom
- Loading branch information
Showing
2 changed files
with
76 additions
and
81 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
packages/govuk-frontend/src/govuk/components/warning-text/template.jsdom.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
const { getExamples, render } = require('@govuk-frontend/lib/components') | ||
|
||
describe('Warning text', () => { | ||
let examples | ||
|
||
beforeAll(async () => { | ||
examples = await getExamples('warning-text') | ||
}) | ||
|
||
describe('default example', () => { | ||
beforeAll(() => { | ||
document.body.innerHTML = render('warning-text', examples.default) | ||
}) | ||
|
||
it('contains the text from the `text` option', () => { | ||
const $component = document.querySelector('.govuk-warning-text') | ||
|
||
expect($component).toHaveTextContent( | ||
'You can be fined up to £5,000 if you don’t register.' | ||
) | ||
}) | ||
|
||
it('includes the default assistive text', () => { | ||
const $assistiveText = document.querySelector('.govuk-visually-hidden') | ||
|
||
expect($assistiveText).toHaveTextContent('Warning') | ||
}) | ||
|
||
it('hides the icon from screen readers using the `aria-hidden` attribute', () => { | ||
const $icon = document.querySelector('.govuk-warning-text__icon') | ||
|
||
expect($icon).toHaveAttribute('aria-hidden', 'true') | ||
}) | ||
}) | ||
|
||
it('includes additional classes from the `classes` option', () => { | ||
document.body.innerHTML = render('warning-text', examples.classes) | ||
const $component = document.querySelector('.govuk-warning-text') | ||
|
||
expect($component).toHaveClass('govuk-warning-text--custom-class') | ||
}) | ||
|
||
it('includes custom assistive text based on the `iconFallbackText` option', () => { | ||
document.body.innerHTML = render( | ||
'warning-text', | ||
examples['icon fallback text only'] | ||
) | ||
const $assistiveText = document.querySelector('.govuk-visually-hidden') | ||
|
||
expect($assistiveText).toHaveTextContent('Some custom fallback text') | ||
}) | ||
|
||
it('sets any additional attributes based on the `attributes` option', () => { | ||
document.body.innerHTML = render('warning-text', examples.attributes) | ||
const $component = document.querySelector('.govuk-warning-text') | ||
|
||
expect($component).toHaveAttribute('data-test', 'attribute') | ||
expect($component).toHaveAttribute('id', 'my-warning-text') | ||
}) | ||
|
||
it('escapes HTML when using the `text` option', () => { | ||
document.body.innerHTML = render('warning-text', examples['html as text']) | ||
const $component = document.querySelector('.govuk-warning-text') | ||
|
||
expect($component).toHaveTextContent( | ||
'<span>Some custom warning text</span>' | ||
) | ||
}) | ||
|
||
it('does not escape HTML when using the `html` option', () => { | ||
document.body.innerHTML = render('warning-text', examples.html) | ||
const $component = document.querySelector('.govuk-warning-text') | ||
|
||
expect($component).toContainHTML('<span>Some custom warning text</span>') | ||
}) | ||
}) |
81 changes: 0 additions & 81 deletions
81
packages/govuk-frontend/src/govuk/components/warning-text/template.test.js
This file was deleted.
Oops, something went wrong.