Skip to content

Commit

Permalink
Added tests to show how empty arrays behave.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mat Carey committed Nov 20, 2019
1 parent 3fb2161 commit cacdc24
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/govuk/components/date-input/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {})

Expand Down
18 changes: 18 additions & 0 deletions src/govuk/components/footer/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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'])

Expand Down
24 changes: 23 additions & 1 deletion src/govuk/components/summary-list/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand All @@ -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: [
Expand Down
14 changes: 14 additions & 0 deletions src/govuk/components/tabs/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down

0 comments on commit cacdc24

Please sign in to comment.