Fix Profile component not rendered on initial / request

This commit is contained in:
SleepWalker 2017-07-11 22:56:07 +03:00
parent 622f02ebee
commit b18844906f
5 changed files with 65 additions and 4 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -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 (
<div />
);
}
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(<AuthFlowRouteContents
routerProps={routerProps}
component={Component}
/>);
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);
});
});

View File

@ -42,6 +42,7 @@ class ProfilePage extends Component {
<Route path="/profile/change-password" component={ChangePasswordPage} />
<Route path="/profile/change-username" component={ChangeUsernamePage} />
<Route path="/profile/change-email/:step?/:code?" component={ChangeEmailPage} />
<Route path="/profile" component={Profile} />
<Route path="/" exact component={Profile} />
<Redirect to="/404" />
</Switch>

View File

@ -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)