From cacdc24f9bc43c94558d5960a48a9525ed0e02d2 Mon Sep 17 00:00:00 2001 From: Mat Carey Date: Wed, 20 Nov 2019 15:07:37 +0000 Subject: [PATCH] Added tests to show how empty arrays behave. --- .../components/date-input/template.test.js | 9 +++++++ src/govuk/components/footer/template.test.js | 18 ++++++++++++++ .../components/summary-list/template.test.js | 24 ++++++++++++++++++- src/govuk/components/tabs/template.test.js | 14 +++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/govuk/components/date-input/template.test.js b/src/govuk/components/date-input/template.test.js index a0b74b24d9..e62094af50 100644 --- a/src/govuk/components/date-input/template.test.js +++ b/src/govuk/components/date-input/template.test.js @@ -69,6 +69,15 @@ describe('Date input', () => { expect($items.length).toEqual(3) }) + it('renders defaults when an empty item array is provided', () => { + const $ = render('date-input', { + items: [] + }) + + const $items = $('.govuk-date-input__item') + expect($items.length).toEqual(3) + }) + it('renders with default items', () => { const $ = render('date-input', {}) diff --git a/src/govuk/components/footer/template.test.js b/src/govuk/components/footer/template.test.js index 45a01427fd..1da94e3aff 100644 --- a/src/govuk/components/footer/template.test.js +++ b/src/govuk/components/footer/template.test.js @@ -24,6 +24,15 @@ describe('footer', () => { expect($component.attr('role')).toEqual('contentinfo') }) + it('no items displayed when no item array is provided', () => { + const $ = render('footer', { + navigation: [] + }) + + const $component = $('.govuk-footer') + expect($component.find('.govuk-footer__navigation').length).toEqual(0) + }) + it('renders attributes correctly', () => { const $ = render('footer', { attributes: { @@ -83,6 +92,15 @@ describe('footer', () => { expect($heading.text()).toEqual('Support links') }) + it('doesn\'t render footer link list when no items are provided', () => { + const $ = render('footer', { + meta: { items: [] } + }) + + const $component = $('.govuk-footer') + expect($component.find('.govuk-footer__inline-list').length).toEqual(0) + }) + it('renders links', () => { const $ = render('footer', examples['with meta']) diff --git a/src/govuk/components/summary-list/template.test.js b/src/govuk/components/summary-list/template.test.js index b6758b2d34..dc411e8a62 100644 --- a/src/govuk/components/summary-list/template.test.js +++ b/src/govuk/components/summary-list/template.test.js @@ -383,7 +383,7 @@ describe('Data list', () => { expect($action.hasClass('govuk-link--no-visited-state')).toBeTruthy() }) - it('skips the action column when none are provided', async () => { + it('skips the action column when array is provided', async () => { const $ = render('summary-list', { rows: [ { @@ -402,6 +402,28 @@ describe('Data list', () => { expect($action.length).toEqual(0) }) + it('skips the action column no items are in the array provided', async () => { + const $ = render('summary-list', { + rows: [ + { + key: { + text: 'Name' + }, + value: { + text: 'Firstname Lastname' + }, + actions: { + items: [] + } + } + ] + }) + + const $component = $('.govuk-summary-list') + const $action = $component.find('.govuk-summary-list__actions') + + expect($action.length).toEqual(0) + }) it('adds dummy action columns when only some rows have actions', async () => { const $ = render('summary-list', { rows: [ diff --git a/src/govuk/components/tabs/template.test.js b/src/govuk/components/tabs/template.test.js index 230499baf5..a7667dca13 100644 --- a/src/govuk/components/tabs/template.test.js +++ b/src/govuk/components/tabs/template.test.js @@ -57,6 +57,20 @@ describe('Tabs', () => { }) describe('items', () => { + it('doesn\'t render a list if items is not defined', () => { + const $ = render('tabs', {}) + + const $component = $('.govuk-tabs') + expect($component.find('.govuk-tabs__list').length).toEqual(0) + }) + + it('doesn\'t render a list if items is empty', () => { + const $ = render('tabs', { items: [] }) + + const $component = $('.govuk-tabs') + expect($component.find('.govuk-tabs__list').length).toEqual(0) + }) + it('render a matching tab and panel using item id', () => { const $ = render('tabs', { items: [