2017-07-12 01:26:07 +05:30
|
|
|
import React from 'react';
|
|
|
|
import sinon from 'sinon';
|
2020-05-21 23:38:47 +05:30
|
|
|
import uxpect from 'app/test/unexpected';
|
|
|
|
import { render, screen } from '@testing-library/react';
|
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', () => {
|
2020-05-24 04:38:24 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
sinon.stub(authFlow, 'handleRequest');
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
(authFlow.handleRequest as any).restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
let componentProps: { [key: string]: any };
|
|
|
|
|
|
|
|
function Component(props: { [key: string]: any }) {
|
|
|
|
componentProps = props;
|
|
|
|
|
|
|
|
return <div data-testid="test-component" />;
|
|
|
|
}
|
|
|
|
|
|
|
|
it('should render component if route allowed', () => {
|
|
|
|
const authRequest = {
|
|
|
|
path: '/path',
|
|
|
|
params: { foo: 1 },
|
|
|
|
query: new URLSearchParams(),
|
|
|
|
};
|
|
|
|
|
|
|
|
const routerProps: any = {
|
|
|
|
location: {
|
|
|
|
pathname: authRequest.path,
|
|
|
|
search: '',
|
|
|
|
query: new URLSearchParams(),
|
|
|
|
},
|
|
|
|
match: {
|
|
|
|
params: authRequest.params,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
(authFlow.handleRequest as any).callsArg(2);
|
|
|
|
|
2024-12-14 17:46:29 +05:30
|
|
|
render(<AuthFlowRouteContents component={Component} {...routerProps} />);
|
2020-05-24 04:38:24 +05:30
|
|
|
|
|
|
|
const component = screen.getByTestId('test-component');
|
|
|
|
|
|
|
|
uxpect(authFlow.handleRequest, 'to have a call satisfying', [
|
|
|
|
{
|
|
|
|
...authRequest,
|
|
|
|
query: uxpect.it('to be a', URLSearchParams),
|
|
|
|
},
|
|
|
|
uxpect.it('to be a function'),
|
|
|
|
uxpect.it('to be a function'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
expect(component).toBeInTheDocument();
|
|
|
|
uxpect(componentProps, 'to equal', routerProps);
|
|
|
|
});
|
2017-07-12 01:26:07 +05:30
|
|
|
});
|