Skip to content
Snippets Groups Projects
Commit f03f6ceb authored by Jure's avatar Jure
Browse files

Merge branch 'authenticated-children' into 'master'

Only render AuthenticatedComponent children if authenticated

See merge request !116
parents d6424dd9 0c4db3ac
No related branches found
No related tags found
1 merge request!116Only render AuthenticatedComponent children if authenticated
Pipeline #2774 passed with stage
in 1 minute and 34 seconds
......@@ -23,7 +23,7 @@ export class AuthenticatedComponent extends React.Component {
}
render() {
return this.props.children
return this.props.isAuthenticated ? this.props.children : null
}
}
......
......@@ -26,6 +26,7 @@ describe('<AuthenticatedComponent/>', () => {
const wrapper = makeWrapper({ pushState })
wrapper.instance().checkAuth({ isFetching: true })
expect(wrapper.find('button').length).toBe(0)
expect(pushState).not.toHaveBeenCalled()
})
......@@ -46,4 +47,11 @@ describe('<AuthenticatedComponent/>', () => {
wrapper.setProps({ isAuthenticated: false })
expect(pushState).toHaveBeenCalledWith('/login?next=blah')
})
it('renders children components when authenticated', async () => {
const pushState = jest.fn()
const wrapper = makeWrapper({ pushState, location: { pathname: 'blah' }, isFetching: false, isAuthenticated: true })
expect(wrapper.find('button').length).toBe(1)
})
})
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment