From 04229bacadd0f5b3965ab1e02c266d08355be0c2 Mon Sep 17 00:00:00 2001 From: Matthew Walsh Date: Fri, 14 Jun 2024 10:24:21 +0100 Subject: [PATCH] Fix unit tests and E2E tests --- .../transactions/useNoGasPriceAlerts.ts | 2 +- .../hooks/useConfirmationAlerts.test.ts | 61 ++----------------- 2 files changed, 6 insertions(+), 57 deletions(-) diff --git a/ui/pages/confirmations/hooks/alerts/transactions/useNoGasPriceAlerts.ts b/ui/pages/confirmations/hooks/alerts/transactions/useNoGasPriceAlerts.ts index 1dd0f1b1a6f1..a402a554c7c4 100644 --- a/ui/pages/confirmations/hooks/alerts/transactions/useNoGasPriceAlerts.ts +++ b/ui/pages/confirmations/hooks/alerts/transactions/useNoGasPriceAlerts.ts @@ -23,7 +23,7 @@ export function useNoGasPriceAlerts(): Alert[] { | undefined; const isNotCustomGasPrice = - currentConfirmation && + currentConfirmation?.userFeeLevel && currentConfirmation.userFeeLevel !== UserFeeLevel.CUSTOM && !txParamsAreDappSuggested(currentConfirmation); diff --git a/ui/pages/confirmations/hooks/useConfirmationAlerts.test.ts b/ui/pages/confirmations/hooks/useConfirmationAlerts.test.ts index cd3e54d466af..2d7e2abc7e0d 100644 --- a/ui/pages/confirmations/hooks/useConfirmationAlerts.test.ts +++ b/ui/pages/confirmations/hooks/useConfirmationAlerts.test.ts @@ -1,61 +1,10 @@ -import { renderHook } from '@testing-library/react-hooks'; -import useBlockaidAlerts from './alerts/useBlockaidAlerts'; +import { renderHookWithProvider } from '../../../../test/lib/render-helpers'; +import mockState from '../../../../test/data/mock-state.json'; import useConfirmationAlerts from './useConfirmationAlerts'; -jest.mock('./alerts/useBlockaidAlerts', () => jest.fn()); - -jest.mock('./alerts/transactions/useGasEstimateFailedAlerts', () => ({ - useGasEstimateFailedAlerts: () => [], -})); - -jest.mock('./alerts/transactions/useGasFeeLowAlerts', () => ({ - useGasFeeLowAlerts: () => [], -})); - -jest.mock('./alerts/transactions/useGasTooLowAlerts', () => ({ - useGasTooLowAlerts: () => [], -})); - -jest.mock('./alerts/transactions/useInsufficientBalanceAlerts', () => ({ - useInsufficientBalanceAlerts: () => [], -})); - -jest.mock('./alerts/transactions/useNoGasPriceAlerts', () => ({ - useNoGasPriceAlerts: () => [], -})); - -jest.mock('./alerts/transactions/usePaymasterAlerts', () => ({ - usePaymasterAlerts: () => [], -})); - -jest.mock('./alerts/transactions/usePendingTransactionAlerts', () => ({ - usePendingTransactionAlerts: () => [], -})); - -jest.mock('./alerts/transactions/useSigningOrSubmittingAlerts', () => ({ - useSigningOrSubmittingAlerts: () => [], -})); - describe('useConfirmationAlerts', () => { - describe('useBlockaidAlerts', () => { - it('returns an array of alerts', () => { - const personalSignAlerts = [ - { key: '1', message: 'Alert 1' }, - { key: '2', message: 'Alert 2' }, - ]; - (useBlockaidAlerts as jest.Mock).mockReturnValue(personalSignAlerts); - - const { result } = renderHook(() => useConfirmationAlerts()); - - expect(result.current).toEqual(personalSignAlerts); - }); - - it('returns an empty array when there are no alerts', () => { - (useBlockaidAlerts as jest.Mock).mockReturnValue([]); - - const { result } = renderHook(() => useConfirmationAlerts()); - - expect(result.current).toEqual([]); - }); + it('returns empty array if no alerts', () => { + const { result } = renderHookWithProvider(useConfirmationAlerts, mockState); + expect(result.current).toEqual([]); }); });