Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Panel component tests #500

Merged
merged 4 commits into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Internal:
- Add tests for input component (PR [#478](https://github.com/alphagov/govuk-frontend/pull/478))
- Add tests for date-input component (PR [#495](https://github.com/alphagov/govuk-frontend/pull/495))
- Add tests for textarea component (PR [#497](https://github.com/alphagov/govuk-frontend/pull/497))
- Add tests for panel component (PR [#500](https://github.com/alphagov/govuk-frontend/pull/500))

## 0.0.22-alpha (Breaking release)

Expand Down
27 changes: 2 additions & 25 deletions src/components/panel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,15 @@ More information about when to use panel can be found on [GOV.UK Design System](
Application complete
</h2>
<div class="govuk-c-panel__body">
Your reference number<br><strong>HDJ2123F</strong>
Your reference number: HDJ2123F
</div>
</div>

#### Macro

{{ govukPanel({
"titleText": "Application complete",
"html": "Your reference number<br><strong>HDJ2123F</strong>"
}) }}

### Panel--no-reference-number

[Preview the panel--no-reference-number example](http://govuk-frontend-review.herokuapp.com/components/panel/no-reference-number/preview)

#### Markup

<div class="govuk-c-panel govuk-c-panel--confirmation extra-dummy-class">
<h2 class="govuk-c-panel__title">
Application complete
</h2>
<div class="govuk-c-panel__body">
Thank you for your application
</div>
</div>

#### Macro

{{ govukPanel({
"classes": "extra-dummy-class",
"titleText": "Application complete",
"text": "Thank you for your application"
"text": "Your reference number: HDJ2123F"
}) }}

## Dependencies
Expand Down
7 changes: 1 addition & 6 deletions src/components/panel/panel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@ examples:
- name: default
data:
titleText: Application complete
html: Your reference number<br><strong>HDJ2123F</strong>
- name: no-reference-number
data:
classes: extra-dummy-class
titleText: Application complete
text: Thank you for your application
text: 'Your reference number: HDJ2123F'
79 changes: 79 additions & 0 deletions src/components/panel/template.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* globals describe, it, expect */

const { render, getExamples } = require('../../../lib/jest-helpers')

const examples = getExamples('panel')

describe('Panel', () => {
it('renders title text', () => {
const $ = render('panel', examples.default)
const panelTitle = $('.govuk-c-panel__title').text().trim()

expect(panelTitle).toEqual('Application complete')
})

it('allows title text to be passed whilst escaping HTML entities', () => {
const $ = render('panel', {
titleText: 'Application <strong>not</strong> complete'
})

const panelTitle = $('.govuk-c-panel__title').html().trim()
expect(panelTitle).toEqual('Application &lt;strong&gt;not&lt;/strong&gt; complete')
})

it('allows title HTML to be passed un-escaped', () => {
const $ = render('panel', {
titleHtml: 'Application <strong>not</strong> complete'
})

const panelTitle = $('.govuk-c-panel__title').html().trim()
expect(panelTitle).toEqual('Application <strong>not</strong> complete')
})

it('renders body text', () => {
const $ = render('panel', examples.default)
const panelBodyText = $('.govuk-c-panel__body').text().trim()

expect(panelBodyText).toEqual('Your reference number: HDJ2123F')
})

it('allows body text to be passed whilst escaping HTML entities', () => {
const $ = render('panel', {
text: 'Your reference number<br><strong>HDJ2123F</strong>'
})

const panelBodyText = $('.govuk-c-panel__body').html().trim()
expect(panelBodyText).toEqual('Your reference number&lt;br&gt;&lt;strong&gt;HDJ2123F&lt;/strong&gt;')
})

it('allows body HTML to be passed un-escaped', () => {
const $ = render('panel', {
html: 'Your reference number<br><strong>HDJ2123F</strong>'
})

const panelBodyText = $('.govuk-c-panel__body').html().trim()
expect(panelBodyText).toEqual('Your reference number<br><strong>HDJ2123F</strong>')
})

it('allows additional classes to be added to the component', () => {
const $ = render('panel', {
classes: 'extra-class one-more-class'
})

const $component = $('.govuk-c-panel')
expect($component.hasClass('extra-class one-more-class')).toBeTruthy()
})

it('allows additional attributes to be added to the component', () => {
const $ = render('panel', {
attributes: {
'first-attribute': 'true',
'second-attribute': 'false'
}
})

const $component = $('.govuk-c-panel')
expect($component.attr('first-attribute')).toEqual('true')
expect($component.attr('second-attribute')).toEqual('false')
})
})