Skip to content

Commit

Permalink
fix: unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistevam committed Mar 3, 2025
1 parent c269ffc commit 76b1cd2
Showing 1 changed file with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { renderHook } from '@testing-library/react-hooks';
import useConfirmationAlerts from './useConfirmationAlerts';
import useBlockaidAlerts from './alerts/useBlockaidAlerts';
import useDomainMismatchAlerts from './alerts/signatures/useDomainMismatchAlerts';
import { Alert, Severity } from '../types/alerts';
import { renderHookWithProvider } from '../../../../util/test/renderWithProvider';
import { siweSignatureConfirmationState } from '../../../../util/test/confirm-data-helpers';

jest.mock('./alerts/useBlockaidAlerts');
jest.mock('./alerts/signatures/useDomainMismatchAlerts');

describe('useConfirmationAlerts', () => {
const ALERT_MESSAGE_MOCK = 'This is a test alert message.';
Expand All @@ -17,20 +20,49 @@ describe('useConfirmationAlerts', () => {
alertDetails: ALERT_DETAILS_MOCK,
}
];
const mockDomainMisMatchAlerts: Alert[] = [
{
key: 'domainMismatchAlert',
title: 'Test Domain Mismatch Alert',
message: ALERT_MESSAGE_MOCK,
severity: Severity.Danger,
alertDetails: ALERT_DETAILS_MOCK,
}
];

beforeEach(() => {
jest.clearAllMocks();
(useBlockaidAlerts as jest.Mock).mockReturnValue(mockBlockaidAlerts);
(useDomainMismatchAlerts as jest.Mock).mockReturnValue(mockDomainMisMatchAlerts);
});

it('returns empty array if no alerts', () => {
(useBlockaidAlerts as jest.Mock).mockReturnValue([]);
const { result } = renderHook(() => useConfirmationAlerts());
(useDomainMismatchAlerts as jest.Mock).mockReturnValue([]);
const { result } = renderHookWithProvider(() => useConfirmationAlerts());
expect(result.current).toEqual([]);
});

it('returns blockaid alerts', () => {
const { result } = renderHook(() => useConfirmationAlerts());
(useDomainMismatchAlerts as jest.Mock).mockReturnValue([]);
const { result } = renderHookWithProvider(() => useConfirmationAlerts(), {
state: siweSignatureConfirmationState,
});
expect(result.current).toEqual(mockBlockaidAlerts);
});

it('returns domain mismatch alerts', () => {
(useBlockaidAlerts as jest.Mock).mockReturnValue([]);
const { result } = renderHookWithProvider(() => useConfirmationAlerts(), {
state: siweSignatureConfirmationState,
});
expect(result.current).toEqual(mockDomainMisMatchAlerts);
});

it('returns combined alerts when both blockaid and domain mismatch alerts are present', () => {
const { result } = renderHookWithProvider(() => useConfirmationAlerts(), {
state: siweSignatureConfirmationState,
});
expect(result.current).toEqual([...mockBlockaidAlerts, ...mockDomainMisMatchAlerts]);
});
});

0 comments on commit 76b1cd2

Please sign in to comment.