From 18f41d21d75019bb2d9e0f6858fd4e7436489092 Mon Sep 17 00:00:00 2001 From: Vyrtsev Mikhail Date: Sat, 6 Jul 2019 19:17:35 +0300 Subject: [PATCH] add email auth ui test --- .../auth-panel__email-login-form.test.tsx | 50 +++++++++++++++++++ .../auth-panel__email-login-form.tsx | 4 +- 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 frontend/app/components/auth-panel/__email-login-form/auth-panel__email-login-form.test.tsx diff --git a/frontend/app/components/auth-panel/__email-login-form/auth-panel__email-login-form.test.tsx b/frontend/app/components/auth-panel/__email-login-form/auth-panel__email-login-form.test.tsx new file mode 100644 index 00000000..55c9926a --- /dev/null +++ b/frontend/app/components/auth-panel/__email-login-form/auth-panel__email-login-form.test.tsx @@ -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( + + ); + 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); + }); +}); diff --git a/frontend/app/components/auth-panel/__email-login-form/auth-panel__email-login-form.tsx b/frontend/app/components/auth-panel/__email-login-form/auth-panel__email-login-form.tsx index 6261998c..0a4a6661 100644 --- a/frontend/app/components/auth-panel/__email-login-form/auth-panel__email-login-form.tsx +++ b/frontend/app/components/auth-panel/__email-login-form/auth-panel__email-login-form.tsx @@ -11,14 +11,14 @@ const mapStateToProps = () => ({ sendEmailVerification: sendEmailVerificationRequest, }); -type Props = { +export type Props = { onSignIn(token: string): Promise; onSuccess?(user: User): Promise; theme: Theme; className?: string; } & ReturnType; -interface State { +export interface State { usernameValue: string; addressValue: string; tokenValue: string;