From 3a01f7e74f2c2fe752ae7406d19a34150a2d6ea5 Mon Sep 17 00:00:00 2001 From: lubega-deriv Date: Wed, 13 Dec 2023 17:56:35 +0800 Subject: [PATCH 1/2] chore: withdrawal verification sent unit test --- .../WithdrawalVerificationSent.tsx | 11 ++-- .../WithdrawalVerificationSent.spec.tsx | 57 +++++++++++++++++++ 2 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 packages/wallets/src/features/cashier/modules/WithdrawalVerification/WithdrawalVerificationSent/__tests__/WithdrawalVerificationSent.spec.tsx diff --git a/packages/wallets/src/features/cashier/modules/WithdrawalVerification/WithdrawalVerificationSent/WithdrawalVerificationSent.tsx b/packages/wallets/src/features/cashier/modules/WithdrawalVerification/WithdrawalVerificationSent/WithdrawalVerificationSent.tsx index 824fd74e8331..6b62a690fba7 100644 --- a/packages/wallets/src/features/cashier/modules/WithdrawalVerification/WithdrawalVerificationSent/WithdrawalVerificationSent.tsx +++ b/packages/wallets/src/features/cashier/modules/WithdrawalVerification/WithdrawalVerificationSent/WithdrawalVerificationSent.tsx @@ -16,7 +16,10 @@ const WithdrawalVerificationSent: React.FC = ({ counter, sendEmail }) => +
} @@ -36,18 +39,18 @@ const WithdrawalVerificationSent: React.FC = ({ counter, sendEmail }) => ) : undefined } - title='We’ve sent you an email.' + title="We've sent you an email." />
{showResend && ( ( {`Resend email${counter ? ` in ${counter}s` : ''}`} )} - title='Didn’t receive the email?' + title="Didn't receive the email?" /> )}
diff --git a/packages/wallets/src/features/cashier/modules/WithdrawalVerification/WithdrawalVerificationSent/__tests__/WithdrawalVerificationSent.spec.tsx b/packages/wallets/src/features/cashier/modules/WithdrawalVerification/WithdrawalVerificationSent/__tests__/WithdrawalVerificationSent.spec.tsx new file mode 100644 index 000000000000..0863e393dd6b --- /dev/null +++ b/packages/wallets/src/features/cashier/modules/WithdrawalVerification/WithdrawalVerificationSent/__tests__/WithdrawalVerificationSent.spec.tsx @@ -0,0 +1,57 @@ +import React from 'react'; +import { fireEvent, render, screen, waitFor } from '@testing-library/react'; +import WithdrawalVerificationSent from '../WithdrawalVerificationSent'; + +describe('WithdrawalVerificationSent', () => { + jest.useFakeTimers(); + + test('should render component correctly', () => { + render(); + + expect(screen.getByText("We've sent you an email.")).toBeInTheDocument(); + + expect( + screen.getByText('Please check your email for the verification link to complete the process.') + ).toBeInTheDocument(); + + const emailSentIcon = screen.getByTestId('dt_withdrawal_verification_sent_icon'); + expect(emailSentIcon).toBeInTheDocument(); + + expect(screen.getByRole('button', { name: "Didn't receive the email?" })).toBeInTheDocument(); + }); + + test('should call sendEmail function and toggle showResend on button click', async () => { + const sendEmailMock = jest.fn(); + render(); + + fireEvent.click(screen.getByRole('button', { name: "Didn't receive the email?" })); + + expect(sendEmailMock).toHaveBeenCalledTimes(1); + + await waitFor(() => { + expect( + screen.getByText("Check your spam or junk folder. If it's not there, try resending the email.") + ).toBeInTheDocument(); + expect(screen.getByRole('button', { name: /Resend email/ })).toBeInTheDocument(); + }); + }); + + test('should call sendEmail function again on Resend button click after counter ends', async () => { + const sendEmailMock = jest.fn(); + render(); + + fireEvent.click(screen.getByRole('button', { name: "Didn't receive the email?" })); + + expect(sendEmailMock).toHaveBeenCalledTimes(1); + + jest.advanceTimersByTime(10000); + + await waitFor(() => { + expect(screen.getByRole('button', { name: /Resend email/ })).toBeInTheDocument(); + fireEvent.click(screen.getByRole('button', { name: /Resend email/ })); + expect(sendEmailMock).toHaveBeenCalledTimes(1); + }); + + jest.useRealTimers(); + }); +}); From 659c7f8c3793f4a4dfc4cf0122c7d54707edcc25 Mon Sep 17 00:00:00 2001 From: lubega-deriv Date: Wed, 13 Dec 2023 19:34:40 +0800 Subject: [PATCH 2/2] fix: applied comments --- .../__tests__/WithdrawalVerificationSent.spec.tsx | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/wallets/src/features/cashier/modules/WithdrawalVerification/WithdrawalVerificationSent/__tests__/WithdrawalVerificationSent.spec.tsx b/packages/wallets/src/features/cashier/modules/WithdrawalVerification/WithdrawalVerificationSent/__tests__/WithdrawalVerificationSent.spec.tsx index 0863e393dd6b..a60f633be327 100644 --- a/packages/wallets/src/features/cashier/modules/WithdrawalVerification/WithdrawalVerificationSent/__tests__/WithdrawalVerificationSent.spec.tsx +++ b/packages/wallets/src/features/cashier/modules/WithdrawalVerification/WithdrawalVerificationSent/__tests__/WithdrawalVerificationSent.spec.tsx @@ -3,8 +3,6 @@ import { fireEvent, render, screen, waitFor } from '@testing-library/react'; import WithdrawalVerificationSent from '../WithdrawalVerificationSent'; describe('WithdrawalVerificationSent', () => { - jest.useFakeTimers(); - test('should render component correctly', () => { render(); @@ -20,7 +18,7 @@ describe('WithdrawalVerificationSent', () => { expect(screen.getByRole('button', { name: "Didn't receive the email?" })).toBeInTheDocument(); }); - test('should call sendEmail function and toggle showResend on button click', async () => { + test('should call sendEmail prop and show resend email button', async () => { const sendEmailMock = jest.fn(); render(); @@ -44,14 +42,10 @@ describe('WithdrawalVerificationSent', () => { expect(sendEmailMock).toHaveBeenCalledTimes(1); - jest.advanceTimersByTime(10000); - await waitFor(() => { expect(screen.getByRole('button', { name: /Resend email/ })).toBeInTheDocument(); fireEvent.click(screen.getByRole('button', { name: /Resend email/ })); expect(sendEmailMock).toHaveBeenCalledTimes(1); }); - - jest.useRealTimers(); }); });