diff --git a/components/array-object-table/src/__snapshots__/test.js.snap b/components/array-object-table/src/__snapshots__/test.js.snap new file mode 100644 index 0000000..f482bf6 --- /dev/null +++ b/components/array-object-table/src/__snapshots__/test.js.snap @@ -0,0 +1,214 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ArrayObjectTable matches snapshot 1`] = ` +.emotion-14 { + margin-bottom: 15px; +} + +@media only screen and (min-width:641px) { + .emotion-14 { + margin-bottom: 15px; + } +} + +.emotion-12 { + display: table; + font-family: "nta",Arial,sans-serif; + width: 100%; + table-layout: fixed; + margin-bottom: 15px; +} + +@media only screen and (min-width:641px) { + .emotion-12 { + margin-bottom: 15px; + } +} + +.emotion-0 { + border-bottom: 1px solid #bfc1c3; + display: table-cell; + font-size: 14px; + padding: 15px 4px; + vertical-align: top; + font-weight: bold; + text-align: left; +} + +.emotion-0:first-child { + padding: 15px 4px 15px 0; +} + +.emotion-0:last-child { + padding: 15px 0 15px 4px; +} + +.emotion-6 { + border-bottom: 1px solid #bfc1c3; + display: table-cell; + font-size: 14px; + padding: 15px 4px; + vertical-align: top; +} + +.emotion-6:first-child { + padding: 15px 4px 15px 0; +} + +.emotion-6:last-child { + padding: 15px 0 15px 4px; +} + + + + + + + + + + + One + + + + + Two + + + + + Three + + + + + + + + + test + + + + + two + + + + + - + + + + + + + + + +`; diff --git a/components/array-object-table/src/index.js b/components/array-object-table/src/index.js index e47dc5b..b2880c0 100644 --- a/components/array-object-table/src/index.js +++ b/components/array-object-table/src/index.js @@ -73,16 +73,14 @@ ArrayObjectTable.propTypes = { key: PropTypes.string.isRequired, heading: PropTypes.string.isRequired, transform: PropTypes.func, - })), - array: PropTypes.arrayOf(PropTypes.object), + })).isRequired, + array: PropTypes.arrayOf(PropTypes.object).isRequired, hideWithNoValues: PropTypes.bool, skipEmptyRows: PropTypes.bool, title: PropTypes.node, }; ArrayObjectTable.defaultProps = { - fields: [], - array: [], hideWithNoValues: false, skipEmptyRows: false, title: null, diff --git a/components/array-object-table/src/test.js b/components/array-object-table/src/test.js index e22f2d0..b9aa6ae 100644 --- a/components/array-object-table/src/test.js +++ b/components/array-object-table/src/test.js @@ -1,75 +1,66 @@ import React from 'react'; -import { mount } from 'enzyme'; +import { mount, shallow } from 'enzyme'; -import Component from '.'; +import ArrayObjectTable from '.'; -describe('ArrayObjectTable', () => { - let fields = [ - { key: 'one', heading: 'One' }, - { key: 'two', heading: 'Two', transform: () => 'two' }, - { key: 'three', heading: 'Three' }, - ]; - let array = [ - {}, // empty record to be automatically omitted - { one: 'test', two: 'test' }, - ]; - const title = 'Heading'; - let wrapper; +const fields = [ + { key: 'one', heading: 'One' }, + { key: 'two', heading: 'Two', transform: () => 'two' }, + { key: 'three', heading: 'Three' }, +]; - it('renders with defaults', () => { - wrapper = mount(); - expect(wrapper.exists()).toBe(true); - }); +const array = [ + {}, + { one: 'test', two: 'test' }, +]; - it('renders with basic props', () => { - wrapper = mount(); - - expect(wrapper.exists()).toBe(true); - }); +const getRows = wrapper => wrapper.find('Table').prop('rows'); - it('renders a table of data based on props passed', () => { - const table = wrapper.find('Table'); - const rows = table.prop('rows'); - const titles = table.prop('titles'); - - expect(rows).toEqual([['-', 'two', '-'], ['test', 'two', '-']]); - expect(titles).toEqual(['One', 'Two', 'Three']); +describe('ArrayObjectTable', () => { + it('renders with required props', () => { + const wrapper = shallow(); + expect(wrapper.exists()).toBe(true); }); - it('skips empty rows when skipEmptyRows prop is passed', () => { - wrapper.setProps({ skipEmptyRows: true }); - const table = wrapper.find('Table'); - const rows = table.prop('rows'); + describe('renders table data', () => { + it('renders expected table heading cells ', () => { + const wrapper = mount(); + const titles = wrapper.find('Table').prop('titles'); + expect(titles).toEqual(['One', 'Two', 'Three']); + }); - expect(rows).toEqual([['test', 'two', '-']]); + it('renders expected table data cells', () => { + const wrapper = mount(); + expect(getRows(wrapper)).toEqual([['-', 'two', '-'], ['test', 'two', '-']]); + }); }); - it('optionally renders a heading for a table', () => { - wrapper.setProps({ title }); + describe('responds as expected to additional props', () => { + it('renders a table heading if provided', () => { + const wrapper = shallow(); + expect(wrapper.contains('Heading')).toBe(true); + }); - expect(wrapper.contains('Heading')).toBe(true); - }); + it('skips empty rows if skipEmptyRows is true', () => { + const wrapper = mount(); + expect(getRows(wrapper)).toEqual([['test', 'two', '-']]); + }); + + it('renders nothing if no rows are returned and hideWithNoValues is true', () => { + const emptyArray = [{}, {}, {}]; + const wrapper = shallow(); + expect(wrapper.html()).toBe(null); + }); - it('renders one tbody row when no rows are returned if hideWithNoValues is not true', () => { - fields = [ - { key: 'one', heading: 'One' }, - { key: 'two', heading: 'Two' }, - ]; - array = [ - {}, - {}, - ]; - wrapper = mount(); - const table = wrapper.find('Table'); - const rows = table.prop('rows'); - expect(rows).toEqual([['-', '-']]); - expect(wrapper.find('tbody tr').length).toBe(1); + it('renders one tbody row if no rows are returned and hideWithNoValues is not true', () => { + const emptyArray = [{}, {}, {}]; + const wrapper = mount(); + expect(wrapper.find('tbody tr').length).toBe(1); + }); }); - it('renders nothing when no rows are returned and hideWithNoValues is true', () => { - wrapper = mount(); - - expect(wrapper.html()).toBe(null); + it('matches snapshot', () => { + const wrapper = mount(); + expect(wrapper).toMatchSnapshot(); }); }); - diff --git a/components/arrow-left/src/__snapshots__/test.js.snap b/components/arrow-left/src/__snapshots__/test.js.snap index ef191a6..5d944cb 100644 --- a/components/arrow-left/src/__snapshots__/test.js.snap +++ b/components/arrow-left/src/__snapshots__/test.js.snap @@ -1,19 +1,68 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`ArrowLeft matches snapshot 1`] = ` - - - - - - + + + + Title + + + + + + Title + + + + + `; diff --git a/components/arrow-left/src/test.js b/components/arrow-left/src/test.js index 5e44abe..e0150dd 100644 --- a/components/arrow-left/src/test.js +++ b/components/arrow-left/src/test.js @@ -1,39 +1,40 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { mount, shallow } from 'enzyme'; import { createMatchers } from 'jest-emotion'; import * as emotion from 'emotion'; -import Component from '.'; +import ArrowLeft from '.'; expect.extend(createMatchers(emotion)); -describe('ArrowLeft', () => { - let wrapper; - +describe('ArrowLeft', () => { it('renders without crashing', () => { - wrapper = shallow(); + const wrapper = shallow(); + expect(wrapper.exists()).toBe(true); }); it('renders with a title', () => { - wrapper = shallow(Example title); - expect(wrapper.find('title').text()).toBe('Example title'); + const wrapper = shallow(Title); + expect(wrapper.find('title').text()).toBe('Title'); }); it('renders with a colour fill', () => { - wrapper = shallow(); + const wrapper = shallow(); expect(wrapper.find('svg[fill="red"]').length).toBe(1); }); - it('supports setting of no color', () => { - expect(wrapper).not.toHaveStyleRule('color', 'purple'); - }); - it('supports setting of color', () => { - wrapper = shallow(); + const wrapper = shallow(); expect(wrapper).toHaveStyleRule('color', 'purple'); }); + it('supports no setting of color', () => { + const wrapper = shallow(); + expect(wrapper).not.toHaveStyleRule('color', 'purple'); + }); + it('matches snapshot', () => { + const wrapper = mount(Title); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/components/arrow/src/__snapshots__/test.js.snap b/components/arrow/src/__snapshots__/test.js.snap index b78e616..71b0651 100644 --- a/components/arrow/src/__snapshots__/test.js.snap +++ b/components/arrow/src/__snapshots__/test.js.snap @@ -1,14 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Arrow matches snapshot 1`] = ` - - - + + + + `; diff --git a/components/arrow/src/test.js b/components/arrow/src/test.js index f3dd27b..2956390 100644 --- a/components/arrow/src/test.js +++ b/components/arrow/src/test.js @@ -1,21 +1,21 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { mount, shallow } from 'enzyme'; -import Component from '.'; +import Arrow from '.'; describe('Arrow', () => { - let wrapper; - it('renders without crashing', () => { - wrapper = shallow(); + const wrapper = shallow(); + expect(wrapper.exists()).toBe(true); }); it('sets fill color on polygon', () => { - wrapper = shallow(); + const wrapper = shallow(); expect(wrapper.find('polygon[fill="red"]').length).toBe(1); }); it('matches snapshot', () => { + const wrapper = mount(); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/components/compact-table-accordion-group/src/__snapshots__/test.js.snap b/components/compact-table-accordion-group/src/__snapshots__/test.js.snap index 6d848dc..3d7bbc8 100644 --- a/components/compact-table-accordion-group/src/__snapshots__/test.js.snap +++ b/components/compact-table-accordion-group/src/__snapshots__/test.js.snap @@ -61,34 +61,14 @@ exports[`CompactTableAccordionGroup matches snapshot 1`] = ` { - let wrapper; - const changeHandler = jest.fn(); - - it('renders with only required properties', () => { - wrapper = mount(); - }); - - it('renders style rules', () => { - expect(wrapper).toHaveStyleRule('font-family', '"nta",Arial,sans-serif'); + it('renders with only required props', () => { + const wrapper = shallow(); + expect(wrapper.exists()).toBe(true); }); it('renders title when passed', () => { - wrapper.setProps({ title: 'Example title' }); + const wrapper = mount(); expect( wrapper .find('Title') .childAt(0) .text(), - ).toBe('Example title'); + ).toBe('Title'); }); it('triggers onChange when open button is clicked', () => { - wrapper = mount( - + const changeHandler = jest.fn(); + const wrapper = mount( + Test - , + , ); wrapper.find('OpenButton').simulate('click'); expect(changeHandler).toHaveBeenCalledTimes(1); }); it('does not trigger onChange when title is clicked and changeOnTitleClick is false', () => { - changeHandler.mockReset(); + const changeHandler = jest.fn(); + const wrapper = mount( + + Test + , + ); wrapper.find('Title').simulate('click'); - expect(changeHandler).not.toHaveBeenCalled(); + expect(changeHandler).not.toHaveBeenCalledTimes(1); }); it('triggers onChange when title is clicked and changeOnTitleClick is true', () => { - changeHandler.mockReset(); - wrapper.setProps({ changeOnTitleClick: true }); + const changeHandler = jest.fn(); + const wrapper = mount( + + Test + , + ); wrapper.find('Title').simulate('click'); expect(changeHandler).toHaveBeenCalledTimes(1); }); - + it('matches snapshot', () => { + const changeHandler = jest.fn(); + const wrapper = mount( + + Test + , + ); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/components/count/src/__snapshots__/test.js.snap b/components/count/src/__snapshots__/test.js.snap index 68fe6e1..8dca842 100644 --- a/components/count/src/__snapshots__/test.js.snap +++ b/components/count/src/__snapshots__/test.js.snap @@ -1,9 +1,21 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Count matches snapshot 1`] = ` - - - 4 - - +.emotion-0 { + font-family: "nta",Arial,sans-serif; +} + + + + + + 6 + + + + `; diff --git a/components/count/src/test.js b/components/count/src/test.js index 30691af..31960a5 100644 --- a/components/count/src/test.js +++ b/components/count/src/test.js @@ -1,20 +1,21 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { mount, shallow } from 'enzyme'; -import Component from '.'; +import Count from '.'; describe('Count', () => { - let wrapper; - - it('renders without crashing', () => { - wrapper = shallow(); + it('renders with only required props', () => { + const wrapper = shallow(); + expect(wrapper.exists()).toBe(true); }); it('displays number passed in correctly', () => { + const wrapper = shallow(); expect(wrapper.find('span').text()).toBe('4'); }); it('matches snapshot', () => { + const wrapper = mount(); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/components/countdown-text-area/src/__snapshots__/test.js.snap b/components/countdown-text-area/src/__snapshots__/test.js.snap index 7322194..0631a75 100644 --- a/components/countdown-text-area/src/__snapshots__/test.js.snap +++ b/components/countdown-text-area/src/__snapshots__/test.js.snap @@ -1,14 +1,109 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`CountdownTextarea matches snapshot 1`] = ` - - - + > + + + + + + + + + -2 + + + + + + + `; diff --git a/components/countdown-text-area/src/test.js b/components/countdown-text-area/src/test.js index 7d97a2b..0e167d2 100644 --- a/components/countdown-text-area/src/test.js +++ b/components/countdown-text-area/src/test.js @@ -1,77 +1,81 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { mount, shallow } from 'enzyme'; import { createMatchers } from 'jest-emotion'; import * as emotion from 'emotion'; import { ERROR_COLOUR } from 'govuk-colours'; -import Component from '.'; +import CountdownTextArea from '.'; expect.extend(createMatchers(emotion)); -describe('CountdownTextarea', () => { - let wrapper; +describe('CountdownTextArea', () => { + it('renders without crashing', () => { + const wrapper = shallow(); + expect(wrapper.exists()).toBe(true); + }); describe('displays a countdown based on maxLength prop', () => { it('contains countdown', () => { - wrapper = shallow(); + const wrapper = shallow(); expect(wrapper.find('StyledCountdown').childAt(0).text()).toBe('250'); }); it('reduces countdown', () => { - wrapper.setProps({ value: 'test' }); + const wrapper = shallow(); expect(wrapper.find('StyledCountdown').childAt(0).text()).toBe('246'); }); }); describe('displays count as expected', () => { it('correctly shows 198 when 198 remaining', () => { - wrapper = shallow(); + const wrapper = shallow(); expect(wrapper.find('StyledCountdown').childAt(0).text()).toBe('198'); }); it('correctly shows -2 as count when 2 over', () => { - wrapper.setProps({ maxLength: 2 }); + const wrapper = shallow(); expect(wrapper.find('StyledCountdown').childAt(0).text()).toBe('-2'); }); }); describe('sets styles as expected', () => { it('sets color and font-weight when overflowing', () => { + const wrapper = shallow(); expect(wrapper).toHaveStyleRule('color', ERROR_COLOUR); expect(wrapper).toHaveStyleRule('font-weight', '800'); }); it('does not set color and font-weight when not overflowing', () => { - wrapper.setProps({ maxLength: 5 }); + const wrapper = shallow(); expect(wrapper).not.toHaveStyleRule('color', ERROR_COLOUR); expect(wrapper).not.toHaveStyleRule('font-weight', '800'); }); }); - - describe('maxLengths to zero when positiveOnly set', () => { - it('limits countdown value by maxLength', () => { - wrapper = shallow(); - expect(wrapper.find('StyledCountdown').childAt(0).text()).toBe('0'); - }); - }); - + describe('manages maxLength prop as expected', () => { it('sets maxLength prop if sent', () => { - wrapper = shallow(); + const wrapper = shallow(); expect(wrapper.find('StyledTextAreaField').prop('maxLength')).toBe(10); }); + it('does not set maxLength prop if not sent', () => { - wrapper.setProps({ noMaxLengthAttr: true }); + const wrapper = shallow(); expect(wrapper.find('StyledTextAreaField').prop('maxLength')).toBe(null); }); - }); - it('omits countdown field when no maxLength given', () => { - wrapper = shallow(); - expect(wrapper.find('StyledCountdown').exists()).toBe(false); + it('maxLengths to zero when positiveOnly set', () => { + const wrapper = shallow(); + expect(wrapper.find('StyledCountdown').childAt(0).text()).toBe('0'); + }); + + it('omits countdown field when no maxLength given', () => { + const wrapper = shallow(); + expect(wrapper.find('StyledCountdown').exists()).toBe(false); + }); }); it('matches snapshot', () => { + const wrapper = mount(); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/components/counter-bar/src/test.js b/components/counter-bar/src/test.js index 88c6449..4f06969 100644 --- a/components/counter-bar/src/test.js +++ b/components/counter-bar/src/test.js @@ -1,6 +1,6 @@ import React from 'react'; import { HashRouter, Link } from 'react-router-dom'; -import { mount } from 'enzyme'; +import { mount, shallow } from 'enzyme'; import { createMatchers } from 'jest-emotion'; import * as emotion from 'emotion'; import { LINK_COLOUR, WHITE } from 'govuk-colours'; @@ -10,124 +10,151 @@ import CounterBar from '.'; expect.extend(createMatchers(emotion)); describe('CounterBar', () => { - let wrapper; - - it('renders counters without an active total', () => { - wrapper = mount( - All counters - - Counter 1 - - - ); - const totalWrapper = wrapper.find('Total'); - expect(totalWrapper).not.toHaveStyleRule('background', LINK_COLOUR); - expect(totalWrapper).not.toHaveStyleRule('color', WHITE); - expect(totalWrapper).not.toHaveStyleRule('outline', `2px solid ${LINK_COLOUR}`); + it('renders without crashing', () => { + const wrapper = shallow(); + expect(wrapper.exists()).toBe(true); }); - it('renders empty counters', () => { - expect(wrapper.find('Counter').at(1).exists()).toBe(true); - }); - - it('renders counters with an active total', () => { - wrapper = mount( - All counters - - Counter 1 - - ); - const totalWrapper = wrapper.find('Total'); - expect(totalWrapper).toHaveStyleRule('background', LINK_COLOUR); - expect(totalWrapper).toHaveStyleRule('color', WHITE); - expect(totalWrapper).toHaveStyleRule('outline', `2px solid ${LINK_COLOUR}`); - }); + describe('handles counters as expected', () => { + it('renders counters without an active total', () => { + const wrapper = mount( + All counters + + Counter 1 + + + ); + const totalWrapper = wrapper.find('Total'); + expect(totalWrapper).not.toHaveStyleRule('background', LINK_COLOUR); + expect(totalWrapper).not.toHaveStyleRule('color', WHITE); + expect(totalWrapper).not.toHaveStyleRule('outline', `2px solid ${LINK_COLOUR}`); + }); - it('renders counters with disabled values', () => { - wrapper = mount( - All counters - - Counter 1 - - ); - const counterWrapper = wrapper.find('CounterWrapper').first(); - expect(counterWrapper.prop('disabled')).toBe(true); - }); - - it('renders counters with active values', () => { - wrapper = mount( - All counters - - Counter 1 - - ); - const counterWrapper = wrapper.find('Counter').first(); - expect(counterWrapper).toHaveStyleRule('background', LINK_COLOUR); - expect(counterWrapper).toHaveStyleRule('color', WHITE); - expect(counterWrapper).toHaveStyleRule('outline', `2px solid ${LINK_COLOUR}`); - }); + it('renders empty counters', () => { + const wrapper = mount( + All counters + + Counter 1 + + + ); + expect(wrapper.find('Counter').at(1).exists()).toBe(true); + }); + + it('renders counters with an active total', () => { + const wrapper = mount( + All counters + + Counter 1 + + ); + const totalWrapper = wrapper.find('Total'); + expect(totalWrapper).toHaveStyleRule('background', LINK_COLOUR); + expect(totalWrapper).toHaveStyleRule('color', WHITE); + expect(totalWrapper).toHaveStyleRule('outline', `2px solid ${LINK_COLOUR}`); + }); - it('renders custom colours on totals', () => { - wrapper = mount( - All counters - - Counter 1 - - ); - const counterWrapper = wrapper.find('ResultCount').first(); - expect(counterWrapper).toHaveStyleRule('color', 'yellow'); - expect(counterWrapper).toHaveStyleRule('background', 'pink'); - }); + it('renders counters with disabled values', () => { + const wrapper = mount( + All counters + + Counter 1 + + ); + const counterWrapper = wrapper.find('CounterWrapper').first(); + expect(counterWrapper.prop('disabled')).toBe(true); + }); - it('renders custom colours on counters', () => { - wrapper = mount( - All counters - - Counter 1 - - ); - const counterWrapper = wrapper.find('ResultCount').at(1); - expect(counterWrapper).toHaveStyleRule('background', 'blue'); - expect(counterWrapper).toHaveStyleRule('color', 'orange'); - }); + it('renders counters with active values', () => { + const wrapper = mount( + All counters + + Counter 1 + + ); + const counterWrapper = wrapper.find('Counter').first(); + expect(counterWrapper).toHaveStyleRule('background', LINK_COLOUR); + expect(counterWrapper).toHaveStyleRule('color', WHITE); + expect(counterWrapper).toHaveStyleRule('outline', `2px solid ${LINK_COLOUR}`); + }); + + it('renders custom colours on counters', () => { + const wrapper = mount( + All counters + + Counter 1 + + ); + const counterWrapper = wrapper.find('ResultCount').at(1); + expect(counterWrapper).toHaveStyleRule('background', 'blue'); + expect(counterWrapper).toHaveStyleRule('color', 'orange'); + }); - it('accepts an HTML element string for the total', () => { - wrapper = mount( - All counters - - Counter 1 - - ); - const totalWrapper = wrapper.find('Total'); - expect(totalWrapper.prop('component')).toBe('aside'); + it('accepts an HTML element string for a counter', () => { + const wrapper = mount( + All counters + + Counter 1 + + ); + const counterWrapper = wrapper.find('Counter').first(); + expect(counterWrapper.prop('component')).toBe('aside'); + }); + + it('accepts a component for a counter', () => { + const wrapper = mount( + + All counters + + Counter 1 + + + ); + const counterWrapper = wrapper.find('Counter').first(); + expect(counterWrapper.prop('component')).toBe(Link); + }); }); + + describe('handles totals as expected', () => { + it('renders custom colours on totals', () => { + const wrapper = mount( + All counters + + Counter 1 + + ); + const counterWrapper = wrapper.find('ResultCount').first(); + expect(counterWrapper).toHaveStyleRule('color', 'yellow'); + expect(counterWrapper).toHaveStyleRule('background', 'pink'); + }); - it('accepts a component for the total', () => { - wrapper = mount( - - All counters + it('accepts an HTML element string for the total', () => { + const wrapper = mount( + All counters Counter 1 - - ); - const totalWrapper = wrapper.find('Total'); - expect(totalWrapper.prop('component')).toBe(Link); - }); + ); + const totalWrapper = wrapper.find('Total'); + expect(totalWrapper.prop('component')).toBe('aside'); + }); - it('accepts an HTML element string for a counter', () => { - wrapper = mount( - All counters - - Counter 1 - - ); - const counterWrapper = wrapper.find('Counter').first(); - expect(counterWrapper.prop('component')).toBe('aside'); + it('accepts a component for the total', () => { + const wrapper = mount( + + All counters + + Counter 1 + + + ); + const totalWrapper = wrapper.find('Total'); + expect(totalWrapper.prop('component')).toBe(Link); + }); }); - it('accepts a component for a counter', () => { - wrapper = mount( + it('does not forward props when it shouldn\'t', () => { + const wrapper = mount( All counters @@ -135,17 +162,20 @@ describe('CounterBar', () => { ); - const counterWrapper = wrapper.find('Counter').first(); - expect(counterWrapper.prop('component')).toBe(Link); - }); - - it('does not forward props when it shouldn\'t', () => { const linkWrapper = wrapper.find('Counter').first().find('Link'); expect(linkWrapper.prop('active')).toBe(undefined); expect(linkWrapper.prop('empty')).toBe(undefined); }); it('matches snapshot', () => { + const wrapper = mount( + + All counters + + Counter 1 + + + ); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/components/distraction-free/src/__snapshots__/test.js.snap b/components/distraction-free/src/__snapshots__/test.js.snap index 49c8fa0..1e3a47c 100644 --- a/components/distraction-free/src/__snapshots__/test.js.snap +++ b/components/distraction-free/src/__snapshots__/test.js.snap @@ -1,28 +1,145 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`DistractionFree matches snapshot 1`] = ` - - - span { + -webkit-text-decoration: underline; + text-decoration: underline; +} + +.emotion-4 { + background-color: transparent; + border: 0; +} + +.emotion-2 { + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + width: -webkit-fit-content; + width: -moz-fit-content; + width: fit-content; + color: #ffffff; +} + +.emotion-0 { + font-family: "nta",Arial,sans-serif; + font-size: 14px; + line-height: 1.1428571429; + margin-left: 6px; +} + +@media only screen and (min-width:641px) { + .emotion-0 { + font-size: 19px; + line-height: 1.25; + } +} + +.emotion-8 { + background-color: #ffffff; + font-family: "nta",Arial,sans-serif; + height: 100%; + max-width: 1158px; + min-height: 640px; + width: 100%; +} + + + + - - Sample title - - - - - Sample text - - + + + + + + + + + + Title + + + + + + Title + + + + + + + + + + + + Text + + + + + `; diff --git a/components/distraction-free/src/test.js b/components/distraction-free/src/test.js index 234f025..3bcbaad 100644 --- a/components/distraction-free/src/test.js +++ b/components/distraction-free/src/test.js @@ -1,39 +1,44 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { mount, shallow } from 'enzyme'; import { GREY_1 } from 'govuk-colours'; import { createMatchers } from 'jest-emotion'; import * as emotion from 'emotion'; -import Component from '.'; +import DistractionFree from '.'; expect.extend(createMatchers(emotion)); describe('DistractionFree', () => { - let wrapper; - const clickHandler = jest.fn(); - it('renders without crashing', () => { - wrapper = shallow(Sample text); + const wrapper = shallow(); + expect(wrapper.exists()).toBe(true); }); it('renders children text', () => { - expect(wrapper.find('Body').childAt(0).text()).toBe('Sample text'); + const wrapper = shallow(Text); + expect(wrapper.find('Body').childAt(0).text()).toBe('Text'); }); it('renders optional arrow title', () => { - expect(wrapper.find('ArrowLeft').childAt(0).text()).toBe('Sample title'); + const wrapper = shallow(Text); + expect(wrapper.find('ArrowLeft').childAt(0).text()).toBe('Title'); }); it('renders function passed when clicked', () => { + const clickHandler = jest.fn(); + const wrapper = shallow(Text); wrapper.find('Button').simulate('click'); expect(clickHandler).toHaveBeenCalledTimes(1); }); it('renders style rules', () => { + const wrapper = shallow(); expect(wrapper.find('Background')).toHaveStyleRule('background-color', GREY_1); }); it('matches snapshot', () => { + const clickHandler = jest.fn(); + const wrapper = mount(Text); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/components/header-button/src/__snapshots__/test.js.snap b/components/header-button/src/__snapshots__/test.js.snap index bc1a63d..d83626f 100644 --- a/components/header-button/src/__snapshots__/test.js.snap +++ b/components/header-button/src/__snapshots__/test.js.snap @@ -1,7 +1,43 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`HeaderButton matches snapshot 1`] = ` - +.emotion-0 { + background: none; + border-bottom: 4px solid transparent; + border-left: none; + border-right: none; + border-top: 4px solid transparent; + display: inline-block; + font-family: "nta",Arial,sans-serif; + font-size: 18px; + font-weight: bold; + min-width: 190px; + padding: 8px; + text-align: center; + border-bottom-color: #005ea5; + border-top-color: #005ea5; + color: #005ea5; +} + +.emotion-0:focus { + background: #ffbf47; + outline: 1px solid #ffbf47; +} + +.emotion-0:hover { + border-bottom-color: #2b8cc4; + border-top-color: #2b8cc4; +} + + + + + + `; diff --git a/components/header-button/src/test.js b/components/header-button/src/test.js index 8f40cbd..9ff2327 100644 --- a/components/header-button/src/test.js +++ b/components/header-button/src/test.js @@ -1,34 +1,34 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { mount, shallow } from 'enzyme'; import { createMatchers } from 'jest-emotion'; import * as emotion from 'emotion'; import { LINK_COLOUR } from 'govuk-colours'; -import Component from '.'; +import HeaderButton from '.'; expect.extend(createMatchers(emotion)); describe('HeaderButton', () => { - let wrapper; - - it('renders with no properties', () => { - wrapper = shallow(); + it('renders without crashing', () => { + const wrapper = shallow(); + expect(wrapper.exists()).toBe(true); }); it('applies styles on active prop', () => { - wrapper = shallow().find('Button'); + const wrapper = shallow().find('Button'); expect(wrapper).toHaveStyleRule('border-bottom-color', LINK_COLOUR); expect(wrapper).toHaveStyleRule('border-top-color', LINK_COLOUR); expect(wrapper).toHaveStyleRule('color', LINK_COLOUR); }); it('applies styles on disabled prop', () => { - wrapper = shallow().find('Button'); + const wrapper = shallow().find('Button'); expect(wrapper).toHaveStyleRule('opacity', '0.35'); // Can't see a way of testing pseudo-selectors here... }); it('matches snapshot', () => { + const wrapper = mount(); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/components/keyline/src/__snapshots__/test.js.snap b/components/keyline/src/__snapshots__/test.js.snap index 0c40598..cef2560 100644 --- a/components/keyline/src/__snapshots__/test.js.snap +++ b/components/keyline/src/__snapshots__/test.js.snap @@ -13,8 +13,8 @@ exports[`Keyline matches snapshot 1`] = ` .emotion-0 { border: 0; - border-bottom: 1px solid red; - display: block; + border-bottom: 1px solid blue; + display: inline-block; font-family: "nta",Arial,sans-serif; margin-bottom: 15px; } @@ -26,15 +26,18 @@ exports[`Keyline matches snapshot 1`] = ` } { - let wrapper; - - it('renders with no props', () => { - wrapper = mount(); - expect(wrapper).toHaveStyleRule('border-bottom', `1px solid ${GREY_1}`); + it('renders without crashing', () => { + const wrapper = shallow(); + expect(wrapper.exists()).toBe(true); }); it('renders children', () => { - wrapper = mount(Sample text); + const wrapper = mount(Sample text); expect(wrapper.find('KeylineWrapper').childAt(0).text()).toBe('Sample text'); }); - - it('renders as inlineBlock', () => { - wrapper = mount(); + + it('renders as inlineBlock in response to prop', () => { + const wrapper = mount(); expect(wrapper).toHaveStyleRule('display', 'inline-block'); }); - it('renders with borderColor', () => { - wrapper = mount(); + it('renders with borderColor in response to prop', () => { + const wrapper = mount(); expect(wrapper).toHaveStyleRule('border-bottom', '1px solid red'); }); it('matches snapshot', () => { + const wrapper = mount(); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/components/object-table/src/__snapshots__/test.js.snap b/components/object-table/src/__snapshots__/test.js.snap new file mode 100644 index 0000000..dfd1d7b --- /dev/null +++ b/components/object-table/src/__snapshots__/test.js.snap @@ -0,0 +1,206 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ObjectTable matches snapshot 1`] = ` +.emotion-10 { + margin-bottom: 15px; +} + +@media only screen and (min-width:641px) { + .emotion-10 { + margin-bottom: 15px; + } +} + +.emotion-8 { + display: table; + font-family: "nta",Arial,sans-serif; + width: 100%; + table-layout: fixed; + margin-bottom: 15px; +} + +@media only screen and (min-width:641px) { + .emotion-8 { + margin-bottom: 15px; + } +} + +.emotion-0 { + border-bottom: 1px solid #bfc1c3; + display: table-cell; + font-size: 14px; + padding: 15px 4px; + vertical-align: top; + font-weight: bold; + text-align: left; + width: 25%; +} + +.emotion-0:first-child { + padding: 15px 4px 15px 0; +} + +.emotion-0:last-child { + padding: 15px 0 15px 4px; +} + +.emotion-2 { + border-bottom: 1px solid #bfc1c3; + display: table-cell; + font-size: 14px; + padding: 15px 4px; + vertical-align: top; +} + +.emotion-2:first-child { + padding: 15px 4px 15px 0; +} + +.emotion-2:last-child { + padding: 15px 0 15px 4px; +} + + + + + + + + + + + One + + + + + test + + + + + + + Two + + + + + two + + + + + + + + + +`; diff --git a/components/object-table/src/test.js b/components/object-table/src/test.js index 2599dbe..9dccf06 100644 --- a/components/object-table/src/test.js +++ b/components/object-table/src/test.js @@ -1,62 +1,55 @@ import React from 'react'; -import { mount } from 'enzyme'; +import { mount, shallow } from 'enzyme'; -import Component from '.'; +import ObjectTable from '.'; + +const fields = [ + { key: 'one', heading: 'One' }, + { key: 'two', heading: 'Two', transform: () => 'two' }, +]; + +const object = { one: 'test', two: 'test' }; describe('ObjectTable', () => { - let fields = [ - { key: 'one', heading: 'One' }, - { key: 'two', heading: 'Two', transform: () => 'two' }, - ]; - let object = { one: 'test', two: 'test' }; - const title = 'Heading'; - let wrapper; - - it('renders with defaults', () => { - wrapper = mount(); + it('renders without crashing', () => { + const wrapper = shallow(); expect(wrapper.exists()).toBe(true); }); - - it('renders a table of data based on params', () => { - wrapper = mount(); - const table = wrapper.find('Table'); - const rows = table.prop('rows'); - expect(rows).toEqual([['One', 'test'], ['Two', 'two']]); - }); - - it('optionally renders a heading for a table', () => { - fields = [ - { key: 'one', heading: 'One' }, - { key: 'two', heading: 'Two', transform: () => 'two' }, - ]; - object = { one: 'test', two: 'test' }; - wrapper = mount(); - expect(wrapper.contains('Heading')).toBe(true); + describe('renders table data', () => { + it('renders expected table data cells', () => { + const wrapper = mount(); + expect(wrapper.find('Table').prop('rows')).toEqual([['One', 'test'], ['Two', 'two']]); + }); + + it('omits rows in table for null values', () => { + const fieldsWithTransform = [ + { key: 'one', heading: 'one' }, + { key: 'two', heading: 'two', transform: () => null }, + { key: 'three', heading: 'three'}, + ]; + const objectWithNull = { one: 'test', two: 'test', three: null }; + const wrapper = mount(); + expect(wrapper.find('tr').length).toBe(1); + }); + + it('renders nothing when rows have no values and hideWithNoValues is true', () => { + const objectWithNoValues = {}; + const wrapper = mount(); + expect(wrapper.html()).toBe(null); + }); }); - it('omits rows in table for null values', () => { - fields = [ - { key: 'one', heading: 'one' }, - { key: 'two', heading: 'two', transform: () => null }, - { key: 'three', heading: 'three'}, - ]; - object = { one: 'test', two: 'test', three: null }; - wrapper = mount(); - const rows = wrapper.find('tr'); - - expect(rows.length).toBe(1); + describe('responds as expected to additional props', () => { + it('optionally renders a heading for a table', () => { + const wrapper = shallow(); + expect(wrapper.contains('Heading')).toBe(true); + }); }); - it('renders nothing when rows have no values and hideWithNoValues is true', () => { - fields = [ - { key: 'one', heading: 'one' }, - { key: 'two', heading: 'two', transform: () => null }, - { key: 'three', heading: 'three'}, - ]; - object = {}; - wrapper = mount(); - expect(wrapper.html()).toBe(null); + it('matches snapshot', () => { + const wrapper = mount(); + expect(wrapper).toMatchSnapshot(); }); }); diff --git a/components/open-button/src/__snapshots__/test.js.snap b/components/open-button/src/__snapshots__/test.js.snap index 6f6e0de..8c4b78a 100644 --- a/components/open-button/src/__snapshots__/test.js.snap +++ b/components/open-button/src/__snapshots__/test.js.snap @@ -1,12 +1,54 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`OpenButton matches snapshot 1`] = ` - - - + + + + + + + + + + `; diff --git a/components/open-button/src/test.js b/components/open-button/src/test.js index f4f3daf..da9d15c 100644 --- a/components/open-button/src/test.js +++ b/components/open-button/src/test.js @@ -1,33 +1,34 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { mount, shallow } from 'enzyme'; import { createMatchers } from 'jest-emotion'; import * as emotion from 'emotion'; -import Component from '.'; +import OpenButton from '.'; expect.extend(createMatchers(emotion)); describe('OpenButton', () => { - let wrapper; + it('renders without crashing', () => { + const wrapper = shallow(); + expect(wrapper.exists()).toBe(true); + }); - it('renders with no props', () => { - wrapper = shallow(); + it('styles in response to open prop', () => { + const wrapper = shallow(); expect(wrapper.find('RotatingButton')).toHaveStyleRule('border', 'none'); - }); - - it('renders with open prop', () => { - wrapper = shallow(); + wrapper.setProps({ open: true }); expect(wrapper.find('RotatingButton')).toHaveStyleRule('transform', 'rotate(0deg)'); }); it('calls onChange event when clicked', () => { const handleClick = jest.fn(); - wrapper = shallow(); - wrapper.simulate('click'); + shallow().simulate('click'); expect(handleClick).toHaveBeenCalledWith({open: true}); }); it('matches snapshot', () => { + const handleClick = jest.fn(); + const wrapper = mount(); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/components/remove-button/src/__snapshots__/test.js.snap b/components/remove-button/src/__snapshots__/test.js.snap index 5cdd07e..0548745 100644 --- a/components/remove-button/src/__snapshots__/test.js.snap +++ b/components/remove-button/src/__snapshots__/test.js.snap @@ -1,7 +1,31 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`RemoveButton matches snapshot 1`] = ` - - X - +.emotion-0 { + background-color: #0C60A2; + border: 0; + color: #fff; + font-family: "nta",Arial,sans-serif; + font-size: 11px; + font-weight: 400; + height: 20px; + line-height: normal; + margin: 0 12px; + padding: 0; + width: 20px; +} + +.emotion-0:first-child { + margin: 0; +} + + + + + X + + + `; diff --git a/components/remove-button/src/test.js b/components/remove-button/src/test.js index 7e21130..1333a5c 100644 --- a/components/remove-button/src/test.js +++ b/components/remove-button/src/test.js @@ -1,21 +1,20 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { mount, shallow } from 'enzyme'; import { createMatchers } from 'jest-emotion'; import * as emotion from 'emotion'; -import Component from '.'; +import RemoveButton from '.'; expect.extend(createMatchers(emotion)); describe('RemoveButton', () => { - let wrapper; - - it('renders with expected style rule', () => { - wrapper = shallow(); - expect(wrapper).toHaveStyleRule('font-size', '11px'); + it('renders without crashing', () => { + const wrapper = shallow(); + expect(wrapper.exists()).toBe(true); }); it('matches snapshot', () => { + const wrapper = mount(); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/components/result-count-title/src/__snapshots__/test.js.snap b/components/result-count-title/src/__snapshots__/test.js.snap index 34354d9..3394b82 100644 --- a/components/result-count-title/src/__snapshots__/test.js.snap +++ b/components/result-count-title/src/__snapshots__/test.js.snap @@ -1,15 +1,64 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`ResultCountTitle matches snapshot 1`] = ` - - - 000 - - - Sample title - - +.emotion-4 { + display: inline-block; + white-space: nowrap; + text-overflow: ellipsis; +} + +.emotion-0 { + background: #6f777b; + color: #ffffff; + display: inline-block; + font-family: "nta",Arial,sans-serif; + font-size: 15px; + line-height: 1.25; + min-height: 20px; + min-width: 20px; + padding: 1px 4px; + text-align: center; +} + +.emotion-2 { + display: inline-block; + font-family: "nta",Arial,sans-serif; + font-size: 15px; + line-height: 1.25; + margin-left: 10px; +} + + + + + + + + 000 + + + + + + Title + + + + + `; diff --git a/components/result-count-title/src/test.js b/components/result-count-title/src/test.js index b8d3f77..fcbc8b5 100644 --- a/components/result-count-title/src/test.js +++ b/components/result-count-title/src/test.js @@ -1,29 +1,30 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { mount, shallow } from 'enzyme'; import { createMatchers } from 'jest-emotion'; import * as emotion from 'emotion'; -import Component from '.'; +import ResultCountTitle from '.'; expect.extend(createMatchers(emotion)); describe('ResultCountTitle', () => { - let wrapper; - - it('renders with expected style rule', () => { - wrapper = shallow(Sample title); - expect(wrapper).toHaveStyleRule('display', 'inline-block'); + it('renders without crashing', () => { + const wrapper = shallow(); + expect(wrapper.exists()).toBe(true); }); it('renders with count', () => { + const wrapper = shallow(); expect(wrapper.find('ResultCount').childAt(0).text()).toBe('000'); }); it('renders with title', () => { - expect(wrapper.find('Title').childAt(0).text()).toBe('Sample title'); + const wrapper = shallow(Title); + expect(wrapper.find('Title').childAt(0).text()).toBe('Title'); }); it('matches snapshot', () => { + const wrapper = mount(Title); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/components/result-count/src/test.js b/components/result-count/src/test.js index f26b526..08f156d 100644 --- a/components/result-count/src/test.js +++ b/components/result-count/src/test.js @@ -2,35 +2,36 @@ import React from 'react'; import { mount, shallow } from 'enzyme'; import { createMatchers } from 'jest-emotion'; import * as emotion from 'emotion'; -import { GREY_1, WHITE } from 'govuk-colours'; -import Component from '.'; +import ResultCount from '.'; expect.extend(createMatchers(emotion)); describe('ResultCount', () => { - let wrapper; - - it('renders with expected style rule', () => { - wrapper = shallow(); - expect(wrapper).toHaveStyleRule('line-height', '1.25'); + it('renders without crashing', () => { + const wrapper = shallow(); + expect(wrapper.exists()).toBe(true); }); it('renders with count', () => { - wrapper = shallow(000); + const wrapper = shallow(000); expect(wrapper.childAt(0).text()).toBe('000'); }); - it('applies style rules according to props', () => { - expect(wrapper).toHaveStyleRule('color', WHITE); - expect(wrapper).toHaveStyleRule('background', GREY_1); - wrapper = shallow(000); - expect(wrapper).toHaveStyleRule('color', 'blue'); - expect(wrapper).toHaveStyleRule('background', 'yellow'); + describe('applies styles in response to props', () => { + it('sets color from prop', () => { + const wrapper = shallow(000); + expect(wrapper).toHaveStyleRule('color', 'blue'); + }); + + it('sets background from prop', () => { + const wrapper = shallow(000); + expect(wrapper).toHaveStyleRule('background', 'yellow'); + }); }); it('matches snapshot', () => { - wrapper = mount(0); + const wrapper = mount(0); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/components/spinner/src/__snapshots__/test.js.snap b/components/spinner/src/__snapshots__/test.js.snap index 8f053ff..7d00aa8 100644 --- a/components/spinner/src/__snapshots__/test.js.snap +++ b/components/spinner/src/__snapshots__/test.js.snap @@ -1,12 +1,25 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Spinner matches snapshot 1`] = ` - - - + + + + + + `; diff --git a/components/spinner/src/test.js b/components/spinner/src/test.js index 4f8e5b2..137d075 100644 --- a/components/spinner/src/test.js +++ b/components/spinner/src/test.js @@ -1,27 +1,27 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { mount, shallow } from 'enzyme'; import { createMatchers } from 'jest-emotion'; import * as emotion from 'emotion'; -import Component from '.'; +import Spinner from '.'; expect.extend(createMatchers(emotion)); describe('Spinner', () => { - let wrapper; - - it('renders with expected style rule', () => { - wrapper = shallow(); - expect(wrapper).toHaveStyleRule('display', 'inline-block'); - expect(wrapper).toHaveStyleRule('opacity', '0'); + it('renders without crashing', () => { + const wrapper = shallow(); + expect(wrapper.exists()).toBe(true); }); - it('applies opacity according to prop', () => { - wrapper = shallow(); + it('styles correctly in response to prop', () => { + const wrapper = shallow(); + expect(wrapper).toHaveStyleRule('opacity', '0'); + wrapper.setProps({ visible: true }); expect(wrapper).toHaveStyleRule('opacity', '1'); }); it('matches snapshot', () => { + const wrapper = mount(); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/components/table-accordion-group/src/__snapshots__/test.js.snap b/components/table-accordion-group/src/__snapshots__/test.js.snap index 2a89e02..f6a5dd8 100644 --- a/components/table-accordion-group/src/__snapshots__/test.js.snap +++ b/components/table-accordion-group/src/__snapshots__/test.js.snap @@ -58,34 +58,14 @@ exports[`TableAccordionGroup matches snapshot 1`] = ` { - let wrapper; - const changeHandler = jest.fn(); - it('renders with only required properties', () => { - wrapper = mount(Test); - }); - - it('renders style rules', () => { - expect(wrapper).toHaveStyleRule('font-family', NTA_LIGHT.replace(/\s/g, '')); + const wrapper = shallow(Test); + expect(wrapper.exists()).toBe(true); }); it('renders title when passed', () => { - wrapper.setProps({ title: 'Example title' }); + const wrapper = mount(Test); expect( wrapper .find('Title') .childAt(0) .text(), - ).toBe('Example title'); + ).toBe('Title'); }); it('triggers onChange when OpenButton is clicked', () => { - wrapper = mount( - + const changeHandler = jest.fn(); + const wrapper = mount( + Test - , + , ); wrapper.find('OpenButton').simulate('click'); expect(changeHandler).toHaveBeenCalledTimes(1); }); it('does not trigger onChange when title is clicked and changeOnTitleClick is not true', () => { - changeHandler.mockReset(); + const changeHandler = jest.fn(); + const wrapper = mount( + + Test + , + ); wrapper.find('Title').simulate('click'); expect(changeHandler).not.toHaveBeenCalled(); }); it('triggers onChange when title is clicked and changeOnTitleClick is true', () => { - changeHandler.mockReset(); - wrapper.setProps({ changeOnTitleClick: true }); + const changeHandler = jest.fn(); + const wrapper = mount( + + Test + , + ); wrapper.find('Title').simulate('click'); expect(changeHandler).toHaveBeenCalledTimes(1); }); it('matches snapshot', () => { + const changeHandler = jest.fn(); + const wrapper = mount( + + Test + , + ); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/components/table-of-contents/src/__snapshots__/test.js.snap b/components/table-of-contents/src/__snapshots__/test.js.snap new file mode 100644 index 0000000..a91fa47 --- /dev/null +++ b/components/table-of-contents/src/__snapshots__/test.js.snap @@ -0,0 +1,41 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`TableOfContents matches snapshot 1`] = ` + + + + + Section text here + + + + + id + : + Title + + +`; diff --git a/components/table-of-contents/src/test.js b/components/table-of-contents/src/test.js index 9ef29f2..f709643 100644 --- a/components/table-of-contents/src/test.js +++ b/components/table-of-contents/src/test.js @@ -2,30 +2,31 @@ import React from 'react'; import PropTypes from 'prop-types'; import { mount } from 'enzyme'; -import TOC from '.'; +import TableOfContents from '.'; const renderIndex = ({ contents }) => contents.map(({ id, title }) => {id}: {title}); describe('TableOfContents', () => { it('renders without crashing', () => { - mount( - Section text here - { renderIndex } - ); + const wrapper = mount( + Section text here + { renderIndex } + ); + expect(wrapper.exists()).toBe(true); }); it('can remove a section', () => { - const TestContainer = ({ showSection }) => - Section text here + const TestContainer = ({ showSection }) => + Section text here { showSection && - Optional section here + Optional section here } { showSection && - Duplicate section here + Duplicate section here } - { renderIndex } - ; + { renderIndex } + ; TestContainer.propTypes = { showSection: PropTypes.bool, }; @@ -39,4 +40,12 @@ describe('TableOfContents', () => { expect(wrapper.find('#index-optional').length).toBe(0); }); + + it('matches snapshot', () => { + const wrapper = mount( + Section text here + { renderIndex } + ); + expect(wrapper).toMatchSnapshot(); + }); }); diff --git a/components/table/src/__snapshots__/test.js.snap b/components/table/src/__snapshots__/test.js.snap index a5ed377..eee2bfb 100644 --- a/components/table/src/__snapshots__/test.js.snap +++ b/components/table/src/__snapshots__/test.js.snap @@ -1,35 +1,33 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Table matches snapshot 1`] = ` -.emotion-10 { +.emotion-34 { margin-bottom: 15px; } @media only screen and (min-width:641px) { - .emotion-10 { + .emotion-34 { margin-bottom: 15px; } } -.emotion-0 { +.emotion-10 { border-bottom: 1px solid #bfc1c3; display: table-cell; font-size: 14px; padding: 15px 4px; vertical-align: top; - font-weight: bold; - text-align: left; } -.emotion-0:first-child { +.emotion-10:first-child { padding: 15px 4px 15px 0; } -.emotion-0:last-child { +.emotion-10:last-child { padding: 15px 0 15px 4px; } -.emotion-2 { +.emotion-0 { border-bottom: 1px solid #bfc1c3; display: table-cell; font-size: 14px; @@ -37,18 +35,17 @@ exports[`Table matches snapshot 1`] = ` vertical-align: top; font-weight: bold; text-align: left; - width: 25%; } -.emotion-2:first-child { +.emotion-0:first-child { padding: 15px 4px 15px 0; } -.emotion-2:last-child { +.emotion-0:last-child { padding: 15px 0 15px 4px; } -.emotion-8 { +.emotion-32 { display: table; font-family: "nta",Arial,sans-serif; width: 100%; @@ -57,7 +54,7 @@ exports[`Table matches snapshot 1`] = ` } @media only screen and (min-width:641px) { - .emotion-8 { + .emotion-32 { margin-bottom: 15px; } } @@ -83,24 +80,36 @@ exports[`Table matches snapshot 1`] = ` rows={ Array [ Array [ + "Content 1-1", + "Content 1-2", + "Content 1-3", "Content 1-4", ], Array [ + "Content 2-1", + "Content 2-2", + "Content 2-3", "Content 2-4", ], Array [ + "Content 3-1", + "Content 3-2", + "Content 3-3", "Content 3-4", ], ] } titles={ Array [ + "Heading 1", + "Heading 2", + "Heading 3", "Heading 4", ] } > + + Heading 1 + + + + + Heading 2 + + + + + Heading 3 + + + - Content 1-4 + Content 1-1 + + + Content 1-2 + + + + + Content 1-3 + + + + + Content 1-4 + + - Content 2-4 + Content 2-1 + + + Content 2-2 + + + + + Content 2-3 + + + + + Content 2-4 + + - Content 3-4 + Content 3-1 + + + Content 3-2 + + + + + Content 3-3 + + + + + Content 3-4 + + diff --git a/components/table/src/index.js b/components/table/src/index.js index d43bc45..8ed467f 100644 --- a/components/table/src/index.js +++ b/components/table/src/index.js @@ -197,6 +197,7 @@ Table.defaultProps = { nameByRow: false, names: [], rowIncludesHeading: false, + titles: null, }; export default withWhiteSpace({ marginBottom: 3 })(Table); diff --git a/components/table/src/test.js b/components/table/src/test.js index 63ccda4..e566d5e 100644 --- a/components/table/src/test.js +++ b/components/table/src/test.js @@ -1,41 +1,40 @@ import React from 'react'; -import { mount } from 'enzyme'; +import { mount, shallow } from 'enzyme'; import { createMatchers } from 'jest-emotion'; import * as emotion from 'emotion'; -import Component from '.'; +import Table from '.'; expect.extend(createMatchers(emotion)); +const titles = ['Heading 1', 'Heading 2', 'Heading 3', 'Heading 4']; +const rows = [ + ['Content 1-1', 'Content 1-2', 'Content 1-3', 'Content 1-4'], + ['Content 2-1', 'Content 2-2', 'Content 2-3', 'Content 2-4'], + ['Content 3-1', 'Content 3-2', 'Content 3-3', 'Content 3-4'], +]; +const columnTableNames = ['one', 'two', 'three', ['i', 'am', 'named', 'individually']]; +const rowTableNamesWithTitles = ['heading', 'one', ['i', 'am', 'named', 'individually'], 'three']; +const rowTableNames = ['one', ['i', 'am', 'named', 'individually'], 'three']; + describe('Table', () => { - const titles = ['Heading 1', 'Heading 2', 'Heading 3', 'Heading 4']; - const rows = [ - ['Content 1-1', 'Content 1-2', 'Content 1-3', 'Content 1-4'], - ['Content 2-1', 'Content 2-2', 'Content 2-3', 'Content 2-4'], - ['Content 3-1', 'Content 3-2', 'Content 3-3', 'Content 3-4'], - ]; + it('renders with only required props', () => { + const wrapper = shallow(); + expect(wrapper.exists()).toBe(true); + }); - const columnTableNames = ['one', 'two', 'three', ['i', 'am', 'named', 'individually']]; - const rowTableNamesWithTitles = ['heading', 'one', ['i', 'am', 'named', 'individually'], 'three']; - const rowTableNames = ['one', ['i', 'am', 'named', 'individually'], 'three']; - - let wrapper; - - it('renders as a table', () => { - wrapper = mount(); - expect(wrapper).toHaveStyleRule('display', 'table'); + it('renders rows from prop', () => { + const wrapper = mount(); + expect(wrapper.find('tr')).toHaveLength(3); }); it('renders titles from prop', () => { + const wrapper = mount(); expect(wrapper.find('TableHeading')).toHaveLength(4); }); - it('renders rows from prop', () => { - expect(wrapper.find('tr')).toHaveLength(4); - }); - it('names each cell according to its column', () => { - wrapper.setProps({name: 'name', names: columnTableNames}); + const wrapper = mount(); const th = wrapper.find('TableHeading').at(2); expect(th.prop('name')).toBe('three'); const td = wrapper.find('TableData').at(2); @@ -43,13 +42,26 @@ describe('Table', () => { }); it('renders rows with header column', () => { - wrapper.setProps({rowIncludesHeading: true, nameByRow: true}); + const wrapper = mount(); expect(wrapper.find('TableHeading')).toHaveLength(7); }); it('names each cell according to its row, no titles', () => { - wrapper.setProps({ titles: undefined, names: rowTableNames }); - + const wrapper = mount(); + let th = wrapper.find('TableHeading').at(0); expect(th.prop('name')).toBe('one'); @@ -76,8 +88,15 @@ describe('Table', () => { }); it('names each cell according to its row, with titles', () => { - wrapper.setProps({ titles, names: rowTableNamesWithTitles }); - + const wrapper = mount(); + let th = wrapper.find('TableHeading').at(3); expect(th.prop('name')).toBe('heading'); @@ -107,6 +126,14 @@ describe('Table', () => { }); it('sets th width according to rowHeading prop', () => { + const wrapper = mount(); expect(wrapper.find('TableHeading').at(3)).not.toHaveStyleRule('width'); const t = titles.slice(-1); const r = rows.map(row => row.slice(-1)); @@ -115,12 +142,29 @@ describe('Table', () => { }); it('sets table-layout according to flexibleColumns prop', () => { + const wrapper = mount(); expect(wrapper).toHaveStyleRule('table-layout', 'fixed'); wrapper.setProps({flexibleColumns: true}); expect(wrapper).toHaveStyleRule('table-layout', 'auto'); }); - + it('matches snapshot', () => { + const wrapper = mount(); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/components/title-result-count/src/__snapshots__/test.js.snap b/components/title-result-count/src/__snapshots__/test.js.snap index af8355e..0fd7ba5 100644 --- a/components/title-result-count/src/__snapshots__/test.js.snap +++ b/components/title-result-count/src/__snapshots__/test.js.snap @@ -1,15 +1,64 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`TitleResultCount matches snapshot 1`] = ` - - - Sample title - - - 3 - - +.emotion-4 { + display: inline-block; + white-space: nowrap; + text-overflow: ellipsis; +} + +.emotion-0 { + display: inline-block; + font-family: "nta",Arial,sans-serif; + font-size: 15px; + line-height: 1.25; + margin-right: 10px; +} + +.emotion-2 { + background: #6f777b; + color: #ffffff; + display: inline-block; + font-family: "nta",Arial,sans-serif; + font-size: 15px; + line-height: 1.25; + min-height: 20px; + min-width: 20px; + padding: 1px 4px; + text-align: center; +} + + + + + + + Title + + + + + + 3 + + + + + + `; diff --git a/components/title-result-count/src/test.js b/components/title-result-count/src/test.js index 2a62ae3..e536721 100644 --- a/components/title-result-count/src/test.js +++ b/components/title-result-count/src/test.js @@ -1,34 +1,30 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { mount, shallow } from 'enzyme'; import { createMatchers } from 'jest-emotion'; import * as emotion from 'emotion'; -import Component from '.'; +import TitleResultCount from '.'; expect.extend(createMatchers(emotion)); describe('TitleResultCount', () => { - let wrapper; - - it('renders with no properties', () => { - wrapper = shallow(Sample title); - }); - - it('renders style rules', () => { - expect(wrapper).toHaveStyleRule('display', 'inline-block'); + it('renders without crashing', () => { + const wrapper = shallow(); + expect(wrapper.exists()).toBe(true); }); - it('renders title', () => { + it('renders a title', () => { + const wrapper = shallow(Title); expect( wrapper .find('Title') .childAt(0) .text(), - ).toBe('Sample title'); + ).toBe('Title'); }); it('renders with a count', () => { - wrapper.setProps({ count: 3 }); + const wrapper = shallow(); expect( wrapper .find('ResultCount') @@ -36,8 +32,9 @@ describe('TitleResultCount', () => { .text(), ).toBe('3'); }); - + it('matches snapshot', () => { + const wrapper = mount(Title); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/yarn.lock b/yarn.lock index f570bc6..2cc94cd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1741,7 +1741,7 @@ ajv-keywords@^3.1.0: version "3.2.0" resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.2.0.tgz#e86b819c602cf8821ad637413698f1dec021847a" -ajv@^5.0.0, ajv@^5.1.0, ajv@^5.2.3, ajv@^5.3.0: +ajv@^5.0.0, ajv@^5.2.3, ajv@^5.3.0: version "5.5.2" resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.5.2.tgz#73b5eeca3fab653e3d3f9422b341ad42205dc965" dependencies: @@ -2078,7 +2078,7 @@ aws-sign2@~0.7.0: version "0.7.0" resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.7.0.tgz#b46e890934a9591f2d2f6f86d7e6a9f1b3fe76a8" -aws4@^1.6.0: +aws4@^1.8.0: version "1.8.0" resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f" @@ -3885,7 +3885,7 @@ columnify@^1.5.4: strip-ansi "^3.0.0" wcwidth "^1.0.0" -combined-stream@1.0.6, combined-stream@~1.0.5: +combined-stream@1.0.6, combined-stream@~1.0.6: version "1.0.6" resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.6.tgz#723e7df6e801ac5613113a7e445a9b69cb632818" dependencies: @@ -5557,7 +5557,7 @@ extend-shallow@^3.0.0, extend-shallow@^3.0.2: assign-symbols "^1.0.0" is-extendable "^1.0.1" -extend@~3.0.1: +extend@~3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.2.tgz#f8b1136b4071fbd8eb140aff858b1019ec2915fa" @@ -5857,7 +5857,7 @@ forever-agent@~0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91" -form-data@~2.3.1: +form-data@~2.3.2: version "2.3.2" resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.2.tgz#4970498be604c20c005d4f5c23aecd21d6b49099" dependencies: @@ -6416,11 +6416,11 @@ har-schema@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-2.0.0.tgz#a94c2224ebcac04782a0d9035521f24735b7ec92" -har-validator@~5.0.3: - version "5.0.3" - resolved "https://registry.yarnpkg.com/har-validator/-/har-validator-5.0.3.tgz#ba402c266194f15956ef15e0fcf242993f6a7dfd" +har-validator@~5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/har-validator/-/har-validator-5.1.0.tgz#44657f5688a22cfd4b72486e81b3a3fb11742c29" dependencies: - ajv "^5.1.0" + ajv "^5.3.0" har-schema "^2.0.0" has-ansi@^2.0.0: @@ -8622,7 +8622,7 @@ mime-db@~1.35.0: version "1.35.0" resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.35.0.tgz#0569d657466491283709663ad379a99b90d9ab47" -mime-types@^2.1.12, mime-types@~2.1.17, mime-types@~2.1.18: +mime-types@^2.1.12, mime-types@~2.1.18, mime-types@~2.1.19: version "2.1.19" resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.19.tgz#71e464537a7ef81c15f2db9d97e913fc0ff606f0" dependencies: @@ -8698,8 +8698,8 @@ minimist@~0.0.1, minimist@~0.0.8: resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf" minipass@^2.2.1, minipass@^2.3.3: - version "2.3.3" - resolved "https://registry.yarnpkg.com/minipass/-/minipass-2.3.3.tgz#a7dcc8b7b833f5d368759cce544dccb55f50f233" + version "2.3.4" + resolved "https://registry.yarnpkg.com/minipass/-/minipass-2.3.4.tgz#4768d7605ed6194d6d576169b9e12ef71e9d9957" dependencies: safe-buffer "^5.1.2" yallist "^3.0.0" @@ -9060,8 +9060,8 @@ normalize.css@^8.0.0: resolved "https://registry.yarnpkg.com/normalize.css/-/normalize.css-8.0.0.tgz#14ac5e461612538a4ce9be90a7da23f86e718493" npm-bundled@^1.0.1: - version "1.0.4" - resolved "https://registry.yarnpkg.com/npm-bundled/-/npm-bundled-1.0.4.tgz#81ee67cb61f13f6f2dabe6728283ee35a5821829" + version "1.0.5" + resolved "https://registry.yarnpkg.com/npm-bundled/-/npm-bundled-1.0.5.tgz#3c1732b7ba936b3a10325aef616467c0ccbcc979" npm-packlist@^1.1.6: version "1.1.11" @@ -9114,9 +9114,9 @@ nwsapi@^2.0.7: version "2.0.8" resolved "https://registry.yarnpkg.com/nwsapi/-/nwsapi-2.0.8.tgz#e3603579b7e162b3dbedae4fb24e46f771d8fa24" -oauth-sign@~0.8.2: - version "0.8.2" - resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.8.2.tgz#46a6ab7f0aead8deae9ec0565780b7d4efeb9d43" +oauth-sign@~0.9.0: + version "0.9.0" + resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.9.0.tgz#47a7b016baa68b5fa0ecf3dee08a85c679ac6455" object-assign@^3.0.0: version "3.0.0" @@ -10151,7 +10151,7 @@ qs@6.5.1: version "6.5.1" resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8" -qs@^6.5.1, qs@~6.5.1: +qs@^6.5.1, qs@~6.5.2: version "6.5.2" resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36" @@ -10869,29 +10869,29 @@ request-promise-native@^1.0.5: tough-cookie ">=2.3.3" request@^2.65.0, request@^2.87.0: - version "2.87.0" - resolved "https://registry.yarnpkg.com/request/-/request-2.87.0.tgz#32f00235cd08d482b4d0d68db93a829c0ed5756e" + version "2.88.0" + resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef" dependencies: aws-sign2 "~0.7.0" - aws4 "^1.6.0" + aws4 "^1.8.0" caseless "~0.12.0" - combined-stream "~1.0.5" - extend "~3.0.1" + combined-stream "~1.0.6" + extend "~3.0.2" forever-agent "~0.6.1" - form-data "~2.3.1" - har-validator "~5.0.3" + form-data "~2.3.2" + har-validator "~5.1.0" http-signature "~1.2.0" is-typedarray "~1.0.0" isstream "~0.1.2" json-stringify-safe "~5.0.1" - mime-types "~2.1.17" - oauth-sign "~0.8.2" + mime-types "~2.1.19" + oauth-sign "~0.9.0" performance-now "^2.1.0" - qs "~6.5.1" - safe-buffer "^5.1.1" - tough-cookie "~2.3.3" + qs "~6.5.2" + safe-buffer "^5.1.2" + tough-cookie "~2.4.3" tunnel-agent "^0.6.0" - uuid "^3.1.0" + uuid "^3.3.2" require-directory@^2.1.1: version "2.1.1" @@ -11949,19 +11949,13 @@ touch@^1.0.0: dependencies: nopt "~1.0.10" -tough-cookie@>=2.3.3, tough-cookie@^2.3.4: +tough-cookie@>=2.3.3, tough-cookie@^2.3.4, tough-cookie@~2.4.3: version "2.4.3" resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.4.3.tgz#53f36da3f47783b0925afa06ff9f3b165280f781" dependencies: psl "^1.1.24" punycode "^1.4.1" -tough-cookie@~2.3.3: - version "2.3.4" - resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.4.tgz#ec60cee38ac675063ffc97a5c18970578ee83655" - dependencies: - punycode "^1.4.1" - tr46@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/tr46/-/tr46-1.0.1.tgz#a8b13fd6bfd2489519674ccde55ba3693b706d09" @@ -12277,7 +12271,7 @@ uuid@^2.0.1: version "2.0.3" resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a" -uuid@^3.0.1, uuid@^3.1.0, uuid@^3.2.1: +uuid@^3.0.1, uuid@^3.2.1, uuid@^3.3.2: version "3.3.2" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"