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(); + + const component = wrapper.find(Component); + + expect(authFlow.handleRequest, 'to have a call satisfying', [ + request, + function() {}, + function() {} + ]); + + expect(component.exists(), 'to be true'); + expect(component.props(), 'to equal', routerProps); + }); +}); diff --git a/src/pages/profile/ProfilePage.js b/src/pages/profile/ProfilePage.js index 5977f13..c187c70 100644 --- a/src/pages/profile/ProfilePage.js +++ b/src/pages/profile/ProfilePage.js @@ -42,6 +42,7 @@ class ProfilePage extends Component { + diff --git a/src/services/authFlow/AuthFlow.js b/src/services/authFlow/AuthFlow.js index 07acd8e..554261d 100644 --- a/src/services/authFlow/AuthFlow.js +++ b/src/services/authFlow/AuthFlow.js @@ -123,7 +123,7 @@ export default class AuthFlow { * @param {object} request * @param {string} request.path * @param {object} request.params - * @param {object} request.query + * @param {URLSearchParams} request.query * @param {function} replace * @param {function} [callback = function() {}] - an optional callback function to be called, when state will be stabilized * (state's enter function's promise resolved)