diff --git a/src/containers/AuthFlowRoute.js b/src/containers/AuthFlowRoute.js index addb404..f2d9727 100644 --- a/src/containers/AuthFlowRoute.js +++ b/src/containers/AuthFlowRoute.js @@ -5,8 +5,7 @@ import { Route } from 'react-router-dom'; import AuthFlowRouteContents from './AuthFlowRouteContents'; export default function AuthFlowRoute(props: { - component: any, - routerProps: Object + component: any }) { const {component: Component, ...routeProps} = props; diff --git a/src/containers/AuthFlowRouteContents.js b/src/containers/AuthFlowRouteContents.js index 69637a7..dce35b5 100644 --- a/src/containers/AuthFlowRouteContents.js +++ b/src/containers/AuthFlowRouteContents.js @@ -21,8 +21,8 @@ export default class AuthFlowRouteContents extends Component { _isMounted = false; componentDidMount() { - this.handleProps(this.props); this._isMounted = true; + this.handleProps(this.props); } componentWillReceiveProps(nextProps: ComponentProps) { diff --git a/src/containers/AuthFlowRouteContents.test.js b/src/containers/AuthFlowRouteContents.test.js new file mode 100644 index 0000000..e3d19f1 --- /dev/null +++ b/src/containers/AuthFlowRouteContents.test.js @@ -0,0 +1,61 @@ +import React from 'react'; + +import sinon from 'sinon'; +import expect from 'unexpected'; +import { mount } from 'enzyme'; + +import authFlow from 'services/authFlow'; + +import AuthFlowRouteContents from './AuthFlowRouteContents'; + +describe('AuthFlowRouteContents', () => { + beforeEach(() => { + sinon.stub(authFlow, 'handleRequest'); + }); + + afterEach(() => { + authFlow.handleRequest.restore(); + }); + + function Component() { + return ( +
+ ); + } + + it('should render component if route allowed', () => { + const request = { + path: '/path', + params: {foo: 1}, + query: new URLSearchParams() + }; + + const routerProps = { + location: { + pathname: request.path, + query: request.query + }, + match: { + params: request.params, + } + }; + + authFlow.handleRequest.callsArg(2); + + const wrapper = mount(