Skip to content

Commit

Permalink
Add html/text parameter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
querkmachine committed Jul 25, 2022
1 parent 0ceed6d commit b2b3272
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 12 deletions.
23 changes: 19 additions & 4 deletions src/govuk/components/footer/footer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ params:
- name: html
type: string
required: false
description: If `text` is set, this is not required. If `html` is provided, the `text` option will be ignored. If neither are provided, the text for the Open Government Licence is used.
description: If `text` is set, this is not required. If `html` is provided, the `text` option will be ignored. If neither are provided, the text for the Open Government Licence is used. The content licence is inside a `<span>` element, so you can only add [phrasing content](https://html.spec.whatwg.org/#phrasing-content) to it.
- name: copyright
type: object
required: false
Expand All @@ -92,7 +92,7 @@ params:
- name: html
type: string
required: false
description: If `text` is set, this is not required. If `html` is provided, the `text` option will be ignored. If neither are provided, Crown copyright is used.
description: If `text` is set, this is not required. If `html` is provided, the `text` option will be ignored. If neither are provided, Crown copyright is used. The copyright notice is inside an `<a>` element, so you can only add non-interactive [phrasing content](https://html.spec.whatwg.org/#phrasing-content) to it.
- name: containerClasses
type: string
required: false
Expand Down Expand Up @@ -143,13 +143,21 @@ examples:
data:
{}

- name: with custom content licence and copyright notice
- name: with custom HTML content licence and copyright notice
description: Open Government Licence and Crown copyright notice translated into Welsh
data:
contentLicence:
html: 'Mae’r holl gynnwys ar gael dan <a class="govuk-footer__link" href="https://www.nationalarchives.gov.uk/doc/open-government-licence-cymraeg/version/3/" rel="license">Drwydded y Llywodraeth Agored v3.0</a>, ac eithrio lle nodir yn wahanol'
copyright:
text: © Hawlfraint y Goron
html: '<span>Hawlfraint y Goron</span>'

- name: with custom text content licence and copyright notice
description: Open Government Licence and Crown copyright notice translated into Welsh
data:
contentLicence:
text: 'Mae’r holl gynnwys ar gael dan Drwydded y Llywodraeth Agored v3.0, ac eithrio lle nodir yn wahanol'
copyright:
text: '© Hawlfraint y Goron'

- name: with meta
description: Secondary navigation with meta information relating to the site
Expand Down Expand Up @@ -412,6 +420,13 @@ examples:
hidden: true
data:
containerClasses: app-width-container
- name: with HTML passed as text content
hidden: true
data:
contentLicence:
text: 'Mae’r holl gynnwys ar gael dan <a class="govuk-footer__link" href="https://www.nationalarchives.gov.uk/doc/open-government-licence-cymraeg/version/3/" rel="license">Drwydded y Llywodraeth Agored v3.0</a>, ac eithrio lle nodir yn wahanol'
copyright:
text: '<span>Hawlfraint y Goron</span>'
- name: with empty meta
hidden: true
data:
Expand Down
44 changes: 36 additions & 8 deletions src/govuk/components/footer/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,28 @@ describe('footer', () => {
const $ = render('footer', examples.default)

const $licenceMessage = $('.govuk-footer__licence-description')
expect($licenceMessage.text().trim()).toContain('Open Government Licence v3.0')
expect($licenceMessage.text()).toContain('Open Government Licence v3.0')
})

it('can be customised', () => {
const $ = render('footer', examples['with custom content licence and copyright notice'])
it('can be customised with `text` parameter', () => {
const $ = render('footer', examples['with custom text content licence and copyright notice'])

const $licenceMessage = $('.govuk-footer__licence-description')
expect($licenceMessage.text().trim()).toContain('Drwydded y Llywodraeth Agored v3.0')
expect($licenceMessage.text()).toContain('Drwydded y Llywodraeth Agored v3.0')
})

it('can be customised with `html` parameter', () => {
const $ = render('footer', examples['with custom HTML content licence and copyright notice'])

const $licenceMessage = $('.govuk-footer__licence-description')
expect($licenceMessage.html()).toContain('<a class="govuk-footer__link" href="https://www.nationalarchives.gov.uk/doc/open-government-licence-cymraeg/version/3/" rel="license">Drwydded y Llywodraeth Agored v3.0</a>')
})

it('escapes HTML in the `text` parameter', () => {
const $ = render('footer', examples['with HTML passed as text content'])

const $licenceMessage = $('.govuk-footer__licence-description')
expect($licenceMessage.html()).toContain('&lt;a class=&quot;govuk-footer__link&quot; href=&quot;https://www.nationalarchives.gov.uk/doc/open-government-licence-cymraeg/version/3/&quot; rel=&quot;license&quot;&gt;Drwydded y Llywodraeth Agored v3.0&lt;/a&gt;')
})
})

Expand All @@ -229,14 +243,28 @@ describe('footer', () => {
const $ = render('footer', examples.default)

const $copyrightMessage = $('.govuk-footer__copyright-logo')
expect($copyrightMessage.text().trim()).toContain('© Crown copyright')
expect($copyrightMessage.text()).toContain('© Crown copyright')
})

it('can be customised with `text` parameter', () => {
const $ = render('footer', examples['with custom text content licence and copyright notice'])

const $copyrightMessage = $('.govuk-footer__copyright-logo')
expect($copyrightMessage.text()).toContain('© Hawlfraint y Goron')
})

it('can be customised with `html` parameter', () => {
const $ = render('footer', examples['with custom HTML content licence and copyright notice'])

const $copyrightMessage = $('.govuk-footer__copyright-logo')
expect($copyrightMessage.html()).toContain('<span>Hawlfraint y Goron</span>')
})

it('can be customised', () => {
const $ = render('footer', examples['with custom content licence and copyright notice'])
it('escapes HTML in the `text` parameter', () => {
const $ = render('footer', examples['with HTML passed as text content'])

const $copyrightMessage = $('.govuk-footer__copyright-logo')
expect($copyrightMessage.text().trim()).toContain('© Hawlfraint y Goron')
expect($copyrightMessage.html()).toContain('&lt;span&gt;Hawlfraint y Goron&lt;/span&gt;')
})
})
})

0 comments on commit b2b3272

Please sign in to comment.