add email auth ui test

This commit is contained in:
Vyrtsev Mikhail
2019-07-06 13:58:58 -05:00
committed by Umputun
parent 3d62302bf0
commit 18f41d21d7
2 changed files with 52 additions and 2 deletions
@@ -0,0 +1,50 @@
/** @jsx h */
import { h } from 'preact';
import { mount } from 'enzyme';
import { EmailLoginForm, Props, State } from './auth-panel__email-login-form';
import { User } from '@app/common/types';
import { sleep } from '@app/utils/sleep';
describe('EmailLoginForm', () => {
it('works', async () => {
const testUser = ({} as any) as User;
const sendEmailVerification = jest.fn(async () => {});
const onSignIn = jest.fn(async () => testUser);
const onSuccess = jest.fn(async () => {});
const el = mount<Props, State>(
<EmailLoginForm
sendEmailVerification={sendEmailVerification}
onSignIn={onSignIn}
onSuccess={onSuccess}
theme="light"
/>
);
await new Promise(resolve =>
el.setState(
{
usernameValue: 'someone',
addressValue: 'someone@example.com',
} as State,
resolve
)
);
el.find('form').simulate('submit');
await sleep(100);
expect(sendEmailVerification).toBeCalledWith('someone', 'someone@example.com');
expect(el.state().verificationSent).toBe(true);
await new Promise(resolve =>
el.setState(
{
tokenValue: 'abcd',
} as State,
resolve
)
);
el.find('form').simulate('submit');
await sleep(100);
expect(onSignIn).toBeCalledWith('abcd');
expect(onSuccess).toBeCalledWith(testUser);
});
});
@@ -11,14 +11,14 @@ const mapStateToProps = () => ({
sendEmailVerification: sendEmailVerificationRequest,
});
type Props = {
export type Props = {
onSignIn(token: string): Promise<User | null>;
onSuccess?(user: User): Promise<void>;
theme: Theme;
className?: string;
} & ReturnType<typeof mapStateToProps>;
interface State {
export interface State {
usernameValue: string;
addressValue: string;
tokenValue: string;