accounts-frontend/packages/app/containers/AuthFlowRouteContents.test.tsx

61 lines
1.4 KiB
TypeScript
Raw Normal View History

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(() => {
2019-12-07 16:58:52 +05:30
(authFlow.handleRequest as any).restore();
});
function Component() {
return <div />;
}
it('should render component if route allowed', () => {
2019-12-10 13:17:32 +05:30
const authRequest = {
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(),
},
match: {
2019-12-10 13:17:32 +05:30
params: authRequest.params,
},
2019-12-10 13:17:32 +05:30
} as any;
2019-12-07 16:58:52 +05:30
(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', [
2019-12-10 13:17:32 +05:30
{
...authRequest,
query: expect.it('to be a', URLSearchParams),
},
expect.it('to be a function'),
expect.it('to be a function'),
]);
expect(component.exists(), 'to be true');
expect(component.props(), 'to equal', routerProps);
});
});