2017-07-12 01:26:07 +05:30
|
|
|
import React from 'react';
|
|
|
|
import sinon from 'sinon';
|
2019-12-08 00:32:00 +05:30
|
|
|
import expect from 'app/test/unexpected';
|
2017-07-12 01:26:07 +05:30
|
|
|
import { mount } from 'enzyme';
|
|
|
|
|
2019-12-08 00:32:00 +05:30
|
|
|
import authFlow from 'app/services/authFlow';
|
2017-07-12 01:26:07 +05:30
|
|
|
|
|
|
|
import AuthFlowRouteContents from './AuthFlowRouteContents';
|
|
|
|
|
|
|
|
describe('AuthFlowRouteContents', () => {
|
2019-11-27 14:33:32 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
sinon.stub(authFlow, 'handleRequest');
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2019-12-07 16:58:52 +05:30
|
|
|
(authFlow.handleRequest as any).restore();
|
2019-11-27 14:33:32 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
(authFlow.handleRequest as any).callsArg(2);
|
2019-11-27 14:33:32 +05:30
|
|
|
|
|
|
|
const wrapper = mount(
|
|
|
|
<AuthFlowRouteContents routerProps={routerProps} component={Component} />,
|
|
|
|
);
|
|
|
|
|
|
|
|
const component = wrapper.find(Component);
|
|
|
|
|
|
|
|
expect(authFlow.handleRequest, 'to have a call satisfying', [
|
|
|
|
request,
|
|
|
|
expect.it('to be a function'),
|
|
|
|
expect.it('to be a function'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
expect(component.exists(), 'to be true');
|
|
|
|
expect(component.props(), 'to equal', routerProps);
|
|
|
|
});
|
2017-07-12 01:26:07 +05:30
|
|
|
});
|