From 884bc27ec116741941c5decde30f7f00a8e18d40 Mon Sep 17 00:00:00 2001 From: Usame Algan Date: Fri, 9 Feb 2024 12:16:26 +0100 Subject: [PATCH] fix: Add tests for ReviewStep --- .../create/steps/ReviewStep/index.test.tsx | 81 ++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/src/components/new-safe/create/steps/ReviewStep/index.test.tsx b/src/components/new-safe/create/steps/ReviewStep/index.test.tsx index 397e4bc18a..ee710ebba3 100644 --- a/src/components/new-safe/create/steps/ReviewStep/index.test.tsx +++ b/src/components/new-safe/create/steps/ReviewStep/index.test.tsx @@ -1,10 +1,13 @@ +import type { NewSafeFormData } from '@/components/new-safe/create' +import * as useChains from '@/hooks/useChains' import { type ChainInfo } from '@safe-global/safe-gateway-typescript-sdk' import { render } from '@/tests/test-utils' -import { NetworkFee } from '@/components/new-safe/create/steps/ReviewStep/index' +import ReviewStep, { NetworkFee } from '@/components/new-safe/create/steps/ReviewStep/index' import * as useWallet from '@/hooks/wallets/useWallet' import { type ConnectedWallet } from '@/hooks/wallets/useOnboard' import { ONBOARD_MPC_MODULE_LABEL } from '@/services/mpc/SocialLoginModule' +import { act, fireEvent, waitFor } from '@testing-library/react' const mockChainInfo = { chainId: '100', @@ -40,3 +43,79 @@ describe('NetworkFee', () => { ).toBeInTheDocument() }) }) + +describe('ReviewStep', () => { + beforeEach(() => { + jest.clearAllMocks() + }) + + it('should display a pay now pay later option for counterfactual safe setups', () => { + const mockData: NewSafeFormData = { + name: 'Test', + threshold: 1, + owners: [{ name: '', address: '0x1' }], + saltNonce: 0, + } + jest.spyOn(useChains, 'useHasFeature').mockReturnValue(true) + + const { getByText } = render( + , + ) + + expect(getByText('Pay now')).toBeInTheDocument() + }) + + it('should not display the network fee for counterfactual safes', () => { + const mockData: NewSafeFormData = { + name: 'Test', + threshold: 1, + owners: [{ name: '', address: '0x1' }], + saltNonce: 0, + } + jest.spyOn(useChains, 'useHasFeature').mockReturnValue(true) + + const { queryByText } = render( + , + ) + + expect(queryByText('Est. network fee')).not.toBeInTheDocument() + }) + + it('should not display the execution method for counterfactual safes', () => { + const mockData: NewSafeFormData = { + name: 'Test', + threshold: 1, + owners: [{ name: '', address: '0x1' }], + saltNonce: 0, + } + jest.spyOn(useChains, 'useHasFeature').mockReturnValue(true) + + const { queryByText } = render( + , + ) + + expect(queryByText('Execution method')).not.toBeInTheDocument() + }) + + it('should display the execution method for counterfactual safes if the user selects pay now', async () => { + const mockData: NewSafeFormData = { + name: 'Test', + threshold: 1, + owners: [{ name: '', address: '0x1' }], + saltNonce: 0, + } + jest.spyOn(useChains, 'useHasFeature').mockReturnValue(true) + + const { getByText } = render( + , + ) + + const payNow = getByText('Pay now') + + act(() => { + fireEvent.click(payNow) + }) + + expect(getByText(/Est. network fee/)).toBeInTheDocument() + }) +})