Skip to content

Commit

Permalink
(#221) Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrause committed Jun 2, 2017
1 parent b7377f0 commit 3c7b72b
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`<Routes /> renders correctly 1`] = `
<div>
<Header />
<Connect(withRouter()) />
<Switch>
<Route
component={[Function]}
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/header/components/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const LoginButton = ({ onLogin }) => (

LoginButton.propTypes = { onLogin: PropTypes.func.isRequired }

const DumbHeader = ({ hasAuth, history }) => (
export const DumbHeader = ({ hasAuth, history }) => (
<Wrapper>
<Logo />
{hasAuth
Expand Down
13 changes: 9 additions & 4 deletions src/client/components/header/components/Header.test.jsx
Original file line number Diff line number Diff line change
@@ -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('<Header />', () => {
it('renders correctly', () => {
const wrapper = shallow(<Header />)
describe('<DumbHeader />', () => {
it('renders with login button when we are not authenticated', () => {
const wrapper = shallow(<DumbHeader hasAuth={false} history={{}} />)
expect(shallowToJson(wrapper)).toMatchSnapshot()
})

it('renders with a profile widget when we are authenticated', () => {
const wrapper = shallow(<DumbHeader hasAuth history={{}} />)
expect(shallowToJson(wrapper)).toMatchSnapshot()
})
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<Header /> renders correctly 1`] = `
exports[`<DumbHeader /> renders with a profile widget when we are authenticated 1`] = `
<styled.header>
<Logo />
<Connect(withRouter(DumbProfileWidget)) />
</styled.header>
`;

exports[`<DumbHeader /> renders with login button when we are not authenticated 1`] = `
<styled.header>
<Logo />
<LoginButton
onLogin={[Function]}
/>
</styled.header>
`;
6 changes: 3 additions & 3 deletions src/client/components/profile/components/ProfileWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const ProfileWidgetContent = styled.div`
}
`

class ProfileWidget extends React.Component {
export class DumbProfileWidget extends React.Component {
componentWillMount() {
this.props.fetchProfile()
}
Expand Down Expand Up @@ -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))
20 changes: 20 additions & 0 deletions src/client/components/profile/components/ProfileWidget.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react'
import { shallow } from 'enzyme'
import { shallowToJson } from 'enzyme-to-json'
import { DumbProfileWidget } from './ProfileWidget'

describe('<DumbProfileWidget />', () => {
it('renders correctly', () => {
const wrapper = shallow(
<DumbProfileWidget
history={{}}
profile={{
name: 'John Doe'
}}
fetchProfile={() => {}}
logout={() => {}}
/>
)
expect(shallowToJson(wrapper)).toMatchSnapshot()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<DumbProfileWidget /> renders correctly 1`] = `
<IconMenu
anchorOrigin={
Object {
"horizontal": "right",
"vertical": "bottom",
}
}
animated={true}
iconButtonElement={
<div>
<styled.div>
<Avatar
size={35}
src="http://i.pravatar.cc/150?u=a042581f4e290267014f"
/>
<styled.span>
John Doe
</styled.span>
<HardwareKeyboardArrowDown
color="#FFFFFF"
style={
Object {
"marginLeft": "2px",
"marginTop": "2px",
}
}
/>
</styled.div>
</div>
}
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}
>
<MenuItem
anchorOrigin={
Object {
"horizontal": "right",
"vertical": "top",
}
}
checked={false}
desktop={false}
disabled={false}
focusState="none"
insetChildren={false}
leftIcon={<ActionSettings />}
onTouchTap={[Function]}
primaryText="Instellingen"
targetOrigin={
Object {
"horizontal": "left",
"vertical": "top",
}
}
/>
<MenuItem
anchorOrigin={
Object {
"horizontal": "right",
"vertical": "top",
}
}
checked={false}
desktop={false}
disabled={false}
focusState="none"
insetChildren={false}
leftIcon={<ActionExitToApp />}
onTouchTap={[Function]}
primaryText="Uitloggen"
targetOrigin={
Object {
"horizontal": "left",
"vertical": "top",
}
}
/>
</IconMenu>
`;

0 comments on commit 3c7b72b

Please sign in to comment.