From 3c7b72ba7f1af26dda86d6709a0f9d17e0686416 Mon Sep 17 00:00:00 2001 From: mkrause Date: Fri, 2 Jun 2017 18:03:13 +0200 Subject: [PATCH] (#221) Add tests. --- .../__snapshots__/Routes.test.jsx.snap | 2 +- .../components/header/components/Header.jsx | 2 +- .../header/components/Header.test.jsx | 13 ++- .../__snapshots__/Header.test.jsx.snap | 12 ++- .../profile/components/ProfileWidget.jsx | 6 +- .../profile/components/ProfileWidget.test.jsx | 20 ++++ .../__snapshots__/ProfileWidget.test.jsx.snap | 98 +++++++++++++++++++ 7 files changed, 143 insertions(+), 10 deletions(-) create mode 100644 src/client/components/profile/components/ProfileWidget.test.jsx create mode 100644 src/client/components/profile/components/__snapshots__/ProfileWidget.test.jsx.snap diff --git a/src/client/components/app/components/__snapshots__/Routes.test.jsx.snap b/src/client/components/app/components/__snapshots__/Routes.test.jsx.snap index 09129d0..944f51e 100644 --- a/src/client/components/app/components/__snapshots__/Routes.test.jsx.snap +++ b/src/client/components/app/components/__snapshots__/Routes.test.jsx.snap @@ -2,7 +2,7 @@ exports[` renders correctly 1`] = `
-
+ ( LoginButton.propTypes = { onLogin: PropTypes.func.isRequired } -const DumbHeader = ({ hasAuth, history }) => ( +export const DumbHeader = ({ hasAuth, history }) => ( {hasAuth diff --git a/src/client/components/header/components/Header.test.jsx b/src/client/components/header/components/Header.test.jsx index 598aa73..57efbf2 100644 --- a/src/client/components/header/components/Header.test.jsx +++ b/src/client/components/header/components/Header.test.jsx @@ -1,11 +1,16 @@ import React from 'react' import { shallow } from 'enzyme' import { shallowToJson } from 'enzyme-to-json' -import Header from './Header' +import { DumbHeader } from './Header' -describe('
', () => { - it('renders correctly', () => { - const wrapper = shallow(
) +describe('', () => { + it('renders with login button when we are not authenticated', () => { + const wrapper = shallow() + expect(shallowToJson(wrapper)).toMatchSnapshot() + }) + + it('renders with a profile widget when we are authenticated', () => { + const wrapper = shallow() expect(shallowToJson(wrapper)).toMatchSnapshot() }) }) diff --git a/src/client/components/header/components/__snapshots__/Header.test.jsx.snap b/src/client/components/header/components/__snapshots__/Header.test.jsx.snap index 91a32ab..ff54379 100644 --- a/src/client/components/header/components/__snapshots__/Header.test.jsx.snap +++ b/src/client/components/header/components/__snapshots__/Header.test.jsx.snap @@ -1,7 +1,17 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`
renders correctly 1`] = ` +exports[` renders with a profile widget when we are authenticated 1`] = ` + + +`; + +exports[` renders with login button when we are not authenticated 1`] = ` + + + `; diff --git a/src/client/components/profile/components/ProfileWidget.jsx b/src/client/components/profile/components/ProfileWidget.jsx index d0c1f79..054f26e 100644 --- a/src/client/components/profile/components/ProfileWidget.jsx +++ b/src/client/components/profile/components/ProfileWidget.jsx @@ -32,7 +32,7 @@ const ProfileWidgetContent = styled.div` } ` -class ProfileWidget extends React.Component { +export class DumbProfileWidget extends React.Component { componentWillMount() { this.props.fetchProfile() } @@ -77,11 +77,11 @@ class ProfileWidget extends React.Component { } } -ProfileWidget.propTypes = { +DumbProfileWidget.propTypes = { history: PropTypes.object.isRequired, profile: PropTypes.object.isRequired, fetchProfile: PropTypes.func.isRequired, logout: PropTypes.func.isRequired } -export default connect(mapStateToProps, mapStateToDispatch)(withRouter(ProfileWidget)) +export default connect(mapStateToProps, mapStateToDispatch)(withRouter(DumbProfileWidget)) diff --git a/src/client/components/profile/components/ProfileWidget.test.jsx b/src/client/components/profile/components/ProfileWidget.test.jsx new file mode 100644 index 0000000..2e7593a --- /dev/null +++ b/src/client/components/profile/components/ProfileWidget.test.jsx @@ -0,0 +1,20 @@ +import React from 'react' +import { shallow } from 'enzyme' +import { shallowToJson } from 'enzyme-to-json' +import { DumbProfileWidget } from './ProfileWidget' + +describe('', () => { + it('renders correctly', () => { + const wrapper = shallow( + {}} + logout={() => {}} + /> + ) + expect(shallowToJson(wrapper)).toMatchSnapshot() + }) +}) diff --git a/src/client/components/profile/components/__snapshots__/ProfileWidget.test.jsx.snap b/src/client/components/profile/components/__snapshots__/ProfileWidget.test.jsx.snap new file mode 100644 index 0000000..5ccd36c --- /dev/null +++ b/src/client/components/profile/components/__snapshots__/ProfileWidget.test.jsx.snap @@ -0,0 +1,98 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` renders correctly 1`] = ` + + + + + John Doe + + + +
+ } + multiple={false} + onItemTouchTap={[Function]} + onKeyboardFocus={[Function]} + onMouseDown={[Function]} + onMouseEnter={[Function]} + onMouseLeave={[Function]} + onMouseUp={[Function]} + onRequestChange={[Function]} + onTouchTap={[Function]} + open={null} + targetOrigin={ + Object { + "horizontal": "right", + "vertical": "top", + } + } + touchTapCloseDelay={200} + useLayerForClickAway={false} +> + } + onTouchTap={[Function]} + primaryText="Instellingen" + targetOrigin={ + Object { + "horizontal": "left", + "vertical": "top", + } + } + /> + } + onTouchTap={[Function]} + primaryText="Uitloggen" + targetOrigin={ + Object { + "horizontal": "left", + "vertical": "top", + } + } + /> + +`;