mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-28 16:00:24 +05:30
Fix Profile component not rendered on initial / request
This commit is contained in:
parent
622f02ebee
commit
b18844906f
@ -5,8 +5,7 @@ import { Route } from 'react-router-dom';
|
|||||||
import AuthFlowRouteContents from './AuthFlowRouteContents';
|
import AuthFlowRouteContents from './AuthFlowRouteContents';
|
||||||
|
|
||||||
export default function AuthFlowRoute(props: {
|
export default function AuthFlowRoute(props: {
|
||||||
component: any,
|
component: any
|
||||||
routerProps: Object
|
|
||||||
}) {
|
}) {
|
||||||
const {component: Component, ...routeProps} = props;
|
const {component: Component, ...routeProps} = props;
|
||||||
|
|
||||||
|
@ -21,8 +21,8 @@ export default class AuthFlowRouteContents extends Component {
|
|||||||
_isMounted = false;
|
_isMounted = false;
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.handleProps(this.props);
|
|
||||||
this._isMounted = true;
|
this._isMounted = true;
|
||||||
|
this.handleProps(this.props);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps: ComponentProps) {
|
componentWillReceiveProps(nextProps: ComponentProps) {
|
||||||
|
61
src/containers/AuthFlowRouteContents.test.js
Normal file
61
src/containers/AuthFlowRouteContents.test.js
Normal 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);
|
||||||
|
});
|
||||||
|
});
|
@ -42,6 +42,7 @@ class ProfilePage extends Component {
|
|||||||
<Route path="/profile/change-password" component={ChangePasswordPage} />
|
<Route path="/profile/change-password" component={ChangePasswordPage} />
|
||||||
<Route path="/profile/change-username" component={ChangeUsernamePage} />
|
<Route path="/profile/change-username" component={ChangeUsernamePage} />
|
||||||
<Route path="/profile/change-email/:step?/:code?" component={ChangeEmailPage} />
|
<Route path="/profile/change-email/:step?/:code?" component={ChangeEmailPage} />
|
||||||
|
<Route path="/profile" component={Profile} />
|
||||||
<Route path="/" exact component={Profile} />
|
<Route path="/" exact component={Profile} />
|
||||||
<Redirect to="/404" />
|
<Redirect to="/404" />
|
||||||
</Switch>
|
</Switch>
|
||||||
|
@ -123,7 +123,7 @@ export default class AuthFlow {
|
|||||||
* @param {object} request
|
* @param {object} request
|
||||||
* @param {string} request.path
|
* @param {string} request.path
|
||||||
* @param {object} request.params
|
* @param {object} request.params
|
||||||
* @param {object} request.query
|
* @param {URLSearchParams} request.query
|
||||||
* @param {function} replace
|
* @param {function} replace
|
||||||
* @param {function} [callback = function() {}] - an optional callback function to be called, when state will be stabilized
|
* @param {function} [callback = function() {}] - an optional callback function to be called, when state will be stabilized
|
||||||
* (state's enter function's promise resolved)
|
* (state's enter function's promise resolved)
|
||||||
|
Loading…
Reference in New Issue
Block a user