mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-29 00:10:54 +05:30
58 lines
1.3 KiB
TypeScript
58 lines
1.3 KiB
TypeScript
import React from 'react';
|
|
import sinon from 'sinon';
|
|
import expect from 'app/test/unexpected';
|
|
import { mount } from 'enzyme';
|
|
|
|
import authFlow from 'app/services/authFlow';
|
|
|
|
import AuthFlowRouteContents from './AuthFlowRouteContents';
|
|
|
|
describe('AuthFlowRouteContents', () => {
|
|
beforeEach(() => {
|
|
sinon.stub(authFlow, 'handleRequest');
|
|
});
|
|
|
|
afterEach(() => {
|
|
(authFlow.handleRequest as any).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 as any).callsArg(2);
|
|
|
|
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);
|
|
});
|
|
});
|