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', () => {
|
2019-12-10 13:17:32 +05:30
|
|
|
const authRequest = {
|
2019-11-27 14:33:32 +05:30
|
|
|
path: '/path',
|
|
|
|
params: { foo: 1 },
|
|
|
|
query: new URLSearchParams(),
|
|
|
|
};
|
|
|
|
|
|
|
|
const routerProps = {
|
|
|
|
location: {
|
2019-12-10 13:17:32 +05:30
|
|
|
pathname: authRequest.path,
|
|
|
|
search: '',
|
|
|
|
query: new URLSearchParams(),
|
2019-11-27 14:33:32 +05:30
|
|
|
},
|
|
|
|
match: {
|
2019-12-10 13:17:32 +05:30
|
|
|
params: authRequest.params,
|
2019-11-27 14:33:32 +05:30
|
|
|
},
|
2019-12-10 13:17:32 +05:30
|
|
|
} as any;
|
2019-11-27 14:33:32 +05:30
|
|
|
|
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', [
|
2019-12-10 13:17:32 +05:30
|
|
|
{
|
|
|
|
...authRequest,
|
|
|
|
query: expect.it('to be a', URLSearchParams),
|
|
|
|
},
|
2019-11-27 14:33:32 +05:30
|
|
|
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
|
|
|
});
|