From 7d02f972d894479abc7ed8108cfb51440e953d72 Mon Sep 17 00:00:00 2001 From: Hendrik Volschenk Date: Thu, 23 Nov 2017 00:30:25 +0200 Subject: [PATCH] fix: add unit tests --- src/cell.test.jsx | 40 ++++++++++++++++++++++++++++++++++++++++ src/grid.test.jsx | 29 +++++++++++++++++++++++++++++ src/row.test.jsx | 28 ++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 src/cell.test.jsx create mode 100644 src/grid.test.jsx create mode 100644 src/row.test.jsx diff --git a/src/cell.test.jsx b/src/cell.test.jsx new file mode 100644 index 0000000..f0de2f6 --- /dev/null +++ b/src/cell.test.jsx @@ -0,0 +1,40 @@ +import { shallow } from 'enzyme'; +import React from 'react'; + +import Cell from './cell'; + +test('Cell > Adds default classNames', () => { + const wrapper = shallow(, { disableLifecycleMethods: true }); + const expected = 'mdc-layout-grid__cell'; + + const actual = wrapper.props().className; + + expect(actual).toBe(expected); +}); + +test('Cell > Adds all classNames based on props', () => { + const ALIGN = 'bottom'; + const CLASS_NAME = 'CLASS_NAME'; + const COLUMNS = 12; + const DESKTOP = 12; + const PHONE = 4; + const TABLET = 8; + const wrapper = shallow( + , + { disableLifecycleMethods: true }, + ); + const expected = `mdc-layout-grid__cell ${CLASS_NAME} mdc-layout-grid__cell--align-${ALIGN} ` + + `mdc-layout-grid__cell--span-${COLUMNS} mdc-layout-grid__cell--span-${DESKTOP}-desktop ` + + `mdc-layout-grid__cell--span-${PHONE}-phone mdc-layout-grid__cell--span-${TABLET}-tablet`; + + const actual = wrapper.props().className; + + expect(actual).toBe(expected); +}); diff --git a/src/grid.test.jsx b/src/grid.test.jsx new file mode 100644 index 0000000..a59f064 --- /dev/null +++ b/src/grid.test.jsx @@ -0,0 +1,29 @@ +import { shallow } from 'enzyme'; +import React from 'react'; + +import Grid from './grid'; + +const CHILDREN =

CHILDREN

; + +test('Grid > Adds the default classNames', () => { + const wrapper = shallow({CHILDREN}, { disableLifecycleMethods: true }); + const expected = 'mdc-layout-grid'; + + const actual = wrapper.props().className; + + expect(actual).toBe(expected); +}); + +test('Grid > Adds all classNames based on props', () => { + const ALIGN = 'left'; + const CLASS_NAME = 'CLASS_NAME'; + const wrapper = shallow( + {CHILDREN}, + { disableLifecycleMethods: true }, + ); + const expected = `mdc-layout-grid mdc-layout-grid--align-${ALIGN} ${CLASS_NAME}`; + + const actual = wrapper.props().className; + + expect(actual).toBe(expected); +}); diff --git a/src/row.test.jsx b/src/row.test.jsx new file mode 100644 index 0000000..7459fe3 --- /dev/null +++ b/src/row.test.jsx @@ -0,0 +1,28 @@ +import { shallow } from 'enzyme'; +import React from 'react'; + +import Row from './row'; + +const CHILDREN =

CHILDREN

; + +test('Row > Adds the default classNames', () => { + const wrapper = shallow({CHILDREN}, { disableLifecycleMethods: true }); + const expected = 'mdc-layout-grid__inner'; + + const actual = wrapper.props().className; + + expect(actual).toBe(expected); +}); + +test('Row > Adds all classNames based on props', () => { + const CLASS_NAME = 'CLASS_NAME'; + const wrapper = shallow( + {CHILDREN}, + { disableLifecycleMethods: true }, + ); + const expected = `mdc-layout-grid__inner ${CLASS_NAME}`; + + const actual = wrapper.props().className; + + expect(actual).toBe(expected); +});