From e4629f2a5fd26a1d8eaefd04042eaeb5563ec30c Mon Sep 17 00:00:00 2001 From: simeng-li Date: Mon, 8 Aug 2022 11:55:36 +0800 Subject: [PATCH] fix(ui): fix ui test fix ui test --- .../PasscodeValidation/index.test.tsx | 6 ++-- .../SecondarySocialSignIn/index.test.tsx | 10 ++++--- .../containers/UsernameSignin/index.test.tsx | 30 ++++++++++++++----- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/packages/ui/src/containers/PasscodeValidation/index.test.tsx b/packages/ui/src/containers/PasscodeValidation/index.test.tsx index ceee9685f..9502d77a0 100644 --- a/packages/ui/src/containers/PasscodeValidation/index.test.tsx +++ b/packages/ui/src/containers/PasscodeValidation/index.test.tsx @@ -22,14 +22,14 @@ describe('', () => { }); it('render counter', () => { - const { queryByText } = renderWithPageContext( + const { queryByText, debug } = renderWithPageContext( ); expect(queryByText('description.resend_after_seconds')).not.toBeNull(); act(() => { - jest.runAllTimers(); + jest.advanceTimersByTime(1e3 * 60); }); expect(queryByText('description.resend_passcode')).not.toBeNull(); @@ -40,7 +40,7 @@ describe('', () => { ); act(() => { - jest.runAllTimers(); + jest.advanceTimersByTime(1e3 * 60); }); const resendButton = getByText('description.resend_passcode'); diff --git a/packages/ui/src/containers/SocialSignIn/SecondarySocialSignIn/index.test.tsx b/packages/ui/src/containers/SocialSignIn/SecondarySocialSignIn/index.test.tsx index 1e2a91e80..b36a98832 100644 --- a/packages/ui/src/containers/SocialSignIn/SecondarySocialSignIn/index.test.tsx +++ b/packages/ui/src/containers/SocialSignIn/SecondarySocialSignIn/index.test.tsx @@ -1,4 +1,4 @@ -import { fireEvent, waitFor } from '@testing-library/react'; +import { fireEvent, waitFor, act } from '@testing-library/react'; import { MemoryRouter } from 'react-router-dom'; import renderWithPageContext from '@/__mocks__/RenderWithPageContext'; @@ -112,12 +112,14 @@ describe('SecondarySocialSignIn', () => { const socialButton = container.querySelector('button'); if (socialButton) { - await waitFor(() => { + act(() => { fireEvent.click(socialButton); }); - expect(invokeSocialSignInSpy).toBeCalled(); - expect(logtoNativeSdk?.getPostMessage).toBeCalled(); + void waitFor(() => { + expect(invokeSocialSignInSpy).toBeCalled(); + expect(logtoNativeSdk?.getPostMessage).toBeCalled(); + }); } }); }); diff --git a/packages/ui/src/containers/UsernameSignin/index.test.tsx b/packages/ui/src/containers/UsernameSignin/index.test.tsx index 718ee45ee..458e46878 100644 --- a/packages/ui/src/containers/UsernameSignin/index.test.tsx +++ b/packages/ui/src/containers/UsernameSignin/index.test.tsx @@ -1,4 +1,5 @@ import { fireEvent, waitFor } from '@testing-library/react'; +import { act } from 'react-dom/test-utils'; import renderWithPageContext from '@/__mocks__/RenderWithPageContext'; import SettingsProvider from '@/__mocks__/RenderWithPageContext/SettingsProvider'; @@ -87,11 +88,13 @@ describe('', () => { fireEvent.change(passwordInput, { target: { value: 'password' } }); } - await waitFor(() => { + await act(async () => { fireEvent.click(submitButton); - }); - expect(signInBasic).toBeCalledWith('username', 'password', undefined); + await waitFor(() => { + expect(termsOfUseConfirmModalPromiseMock).toBeCalled(); + }); + }); }); test('should show terms detail modal', async () => { @@ -115,11 +118,15 @@ describe('', () => { fireEvent.change(passwordInput, { target: { value: 'password' } }); } - await waitFor(() => { + act(() => { fireEvent.click(submitButton); }); - expect(termsOfUseIframeModalPromiseMock).toBeCalledWith(); + expect(signInBasic).not.toBeCalled(); + + await waitFor(() => { + expect(termsOfUseIframeModalPromiseMock).toBeCalled(); + }); }); test('submit form', async () => { @@ -142,12 +149,19 @@ describe('', () => { } const termsButton = getByText('description.agree_with_terms'); - fireEvent.click(termsButton); - await waitFor(() => { + act(() => { + fireEvent.click(termsButton); + }); + + act(() => { fireEvent.click(submitButton); }); - expect(signInBasic).toBeCalledWith('username', 'password', undefined); + act(() => { + void waitFor(() => { + expect(signInBasic).toBeCalledWith('username', 'password', undefined); + }); + }); }); });