From 30971903817f5fc29df4def0bd5b47321d8d49a6 Mon Sep 17 00:00:00 2001 From: Jani Kraner Date: Mon, 5 Feb 2018 16:16:28 +0000 Subject: [PATCH 1/4] Add panel component macro tests --- src/components/panel/template.test.js | 79 +++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/components/panel/template.test.js diff --git a/src/components/panel/template.test.js b/src/components/panel/template.test.js new file mode 100644 index 0000000000..9ef412c30c --- /dev/null +++ b/src/components/panel/template.test.js @@ -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 not 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 not complete' + }) + + const panelTitle = $('.govuk-c-panel__title').html().trim() + expect(panelTitle).toEqual('Application not 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
HDJ2123F' + }) + + 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
HDJ2123F' + }) + + const panelBodyText = $('.govuk-c-panel__body').html().trim() + expect(panelBodyText).toEqual('Your reference number
HDJ2123F') + }) + + 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') + }) +}) From 2837780ccf3fcd4a969d6ad79ad077c7826b8d0f Mon Sep 17 00:00:00 2001 From: Jani Kraner Date: Mon, 5 Feb 2018 16:16:58 +0000 Subject: [PATCH 2/4] Remove redundant variant from YAML --- src/components/panel/panel.yaml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/components/panel/panel.yaml b/src/components/panel/panel.yaml index 31bb19ef92..d6240b427e 100644 --- a/src/components/panel/panel.yaml +++ b/src/components/panel/panel.yaml @@ -2,9 +2,4 @@ examples: - name: default data: titleText: Application complete - html: Your reference number
HDJ2123F -- name: no-reference-number - data: - classes: extra-dummy-class - titleText: Application complete - text: Thank you for your application + text: 'Your reference number: HDJ2123F' From 1c3e673f53806261604013ab4f4d586b0a557099 Mon Sep 17 00:00:00 2001 From: Jani Kraner Date: Mon, 5 Feb 2018 16:22:23 +0000 Subject: [PATCH 3/4] Document tests in CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1aa7633f61..ca6cc65663 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) From 3f2ae0ff0d81276533b1267760d16cecf673d034 Mon Sep 17 00:00:00 2001 From: Jani Kraner Date: Mon, 5 Feb 2018 16:33:01 +0000 Subject: [PATCH 4/4] Update panel README.md --- src/components/panel/README.md | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/src/components/panel/README.md b/src/components/panel/README.md index b3705ebe1d..f29cbe4075 100644 --- a/src/components/panel/README.md +++ b/src/components/panel/README.md @@ -21,7 +21,7 @@ More information about when to use panel can be found on [GOV.UK Design System]( Application complete
- Your reference number
HDJ2123F + Your reference number: HDJ2123F
@@ -29,30 +29,7 @@ More information about when to use panel can be found on [GOV.UK Design System]( {{ govukPanel({ "titleText": "Application complete", - "html": "Your reference number
HDJ2123F" - }) }} - -### Panel--no-reference-number - -[Preview the panel--no-reference-number example](http://govuk-frontend-review.herokuapp.com/components/panel/no-reference-number/preview) - -#### Markup - -
-

- Application complete -

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