-
Notifications
You must be signed in to change notification settings - Fork 340
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 #500 from alphagov/panel-component-tests
Add Panel component tests
- Loading branch information
Showing
4 changed files
with
83 additions
and
31 deletions.
There are no files selected for viewing
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
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
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
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,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 <strong>not</strong> 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<br><strong>HDJ2123F</strong>') | ||
}) | ||
|
||
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') | ||
}) | ||
}) |