Skip to content

Commit a38248a

Browse files
wip
1 parent 5c84e54 commit a38248a

File tree

2 files changed

+144
-1
lines changed

2 files changed

+144
-1
lines changed

ui/components/app/alert-system/alert-modal/alert-modal.test.tsx

+144
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import * as useAlertsModule from '../../../../hooks/useAlerts';
77
import mockState from '../../../../../test/data/mock-state.json';
88
import { Alert } from '../../../../ducks/confirm-alerts/confirm-alerts';
99
import { AlertModal } from './alert-modal';
10+
import { BlockaidReason } from '../../../../../shared/constants/security-provider';
11+
import { SecurityProvider } from '../../../../../shared/constants/security-provider';
12+
import { tEn } from '../../../../../test/lib/i18n-helpers';
1013

1114
const onProcessActionMock = jest.fn();
1215

@@ -28,6 +31,16 @@ jest.mock('../contexts/alertMetricsContext', () => ({
2831
})),
2932
}));
3033

34+
jest.mock('../../../../pages/confirmations/context/confirm', () => ({
35+
useConfirmContext: jest.fn(() => ({
36+
currentConfirmation: {
37+
securityAlertResponse: {
38+
reason: '',
39+
},
40+
},
41+
})),
42+
}));
43+
3144
describe('AlertModal', () => {
3245
const OWNER_ID_MOCK = '123';
3346
const FROM_ALERT_KEY_MOCK = 'from';
@@ -292,4 +305,135 @@ describe('AlertModal', () => {
292305
);
293306
});
294307
});
308+
309+
describe('BlockaidAlertDetails', () => {
310+
const {
311+
useConfirmContext,
312+
} = require('../../../../pages/confirmations/context/confirm');
313+
314+
beforeEach(() => {
315+
jest.clearAllMocks();
316+
});
317+
318+
const blockaidAlertMock: Alert = {
319+
key: FROM_ALERT_KEY_MOCK,
320+
field: FROM_ALERT_KEY_MOCK,
321+
severity: Severity.Warning,
322+
message: ALERT_MESSAGE_MOCK,
323+
provider: SecurityProvider.Blockaid,
324+
reason: 'Reason 1',
325+
};
326+
327+
const blockaidStateMock = {
328+
...STATE_MOCK,
329+
confirmAlerts: {
330+
alerts: { [OWNER_ID_MOCK]: [blockaidAlertMock] },
331+
confirmed: {
332+
[OWNER_ID_MOCK]: {
333+
[FROM_ALERT_KEY_MOCK]: false,
334+
},
335+
},
336+
},
337+
};
338+
const blockaidMockStore = configureMockStore([])(blockaidStateMock);
339+
340+
const testCases = [
341+
{
342+
reason: BlockaidReason.rawSignatureFarming,
343+
expectedKey: 'blockaidAlertInfoDescription3',
344+
},
345+
{
346+
reason: BlockaidReason.approvalFarming,
347+
expectedKey: 'blockaidAlertInfoDescription2',
348+
},
349+
{
350+
reason: BlockaidReason.setApprovalForAll,
351+
expectedKey: 'blockaidAlertInfoDescription2',
352+
},
353+
{
354+
reason: BlockaidReason.permitFarming,
355+
expectedKey: 'blockaidAlertInfoDescription2',
356+
},
357+
{
358+
reason: BlockaidReason.transferFarming,
359+
expectedKey: 'blockaidAlertInfoDescription',
360+
},
361+
{
362+
reason: BlockaidReason.transferFromFarming,
363+
expectedKey: 'blockaidAlertInfoDescription',
364+
},
365+
{
366+
reason: BlockaidReason.rawNativeTokenTransfer,
367+
expectedKey: 'blockaidAlertInfoDescription',
368+
},
369+
{
370+
reason: BlockaidReason.seaportFarming,
371+
expectedKey: 'blockaidAlertInfoDescription4',
372+
},
373+
{
374+
reason: BlockaidReason.blurFarming,
375+
expectedKey: 'blockaidAlertInfoDescription5',
376+
},
377+
{
378+
reason: BlockaidReason.maliciousDomain,
379+
expectedKey: 'blockaidAlertInfoDescription6',
380+
},
381+
{
382+
reason: BlockaidReason.tradeOrderFarming,
383+
expectedKey: 'blockaidAlertInfoDescription7',
384+
},
385+
{
386+
reason: BlockaidReason.other,
387+
expectedKey: 'blockaidAlertInfoDescription7',
388+
},
389+
{
390+
reason: 'unknown reason',
391+
expectedKey: 'blockaidAlertInfoDescription7',
392+
},
393+
];
394+
395+
testCases.forEach(({ reason, expectedKey }) => {
396+
it(`displays correct message for ${reason}`, () => {
397+
(useConfirmContext as jest.Mock).mockImplementation(() => ({
398+
currentConfirmation: {
399+
securityAlertResponse: {
400+
reason,
401+
},
402+
},
403+
}));
404+
405+
const { getByText } = renderWithProvider(
406+
<AlertModal
407+
ownerId={OWNER_ID_MOCK}
408+
onAcknowledgeClick={onAcknowledgeClickMock}
409+
onClose={onCloseMock}
410+
alertKey={FROM_ALERT_KEY_MOCK}
411+
/>,
412+
blockaidMockStore,
413+
);
414+
415+
expect(getByText(tEn(expectedKey) as string)).toBeInTheDocument();
416+
});
417+
});
418+
419+
it('handles undefined securityAlertResponse', () => {
420+
(useConfirmContext as jest.Mock).mockImplementation(() => ({
421+
currentConfirmation: {},
422+
}));
423+
424+
const { getByText } = renderWithProvider(
425+
<AlertModal
426+
ownerId={OWNER_ID_MOCK}
427+
onAcknowledgeClick={onAcknowledgeClickMock}
428+
onClose={onCloseMock}
429+
alertKey={FROM_ALERT_KEY_MOCK}
430+
/>,
431+
blockaidMockStore,
432+
);
433+
434+
expect(
435+
getByText(tEn('blockaidAlertInfoDescription7') as string),
436+
).toBeInTheDocument();
437+
});
438+
});
295439
});

ui/components/app/alert-system/alert-modal/alert-modal.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ function BlockaidAlertDetails() {
142142
const t = useI18nContext();
143143
const { currentConfirmation } = useConfirmContext();
144144
const { securityAlertResponse } = currentConfirmation;
145-
146145
let copy;
147146
switch (securityAlertResponse?.reason) {
148147
case BlockaidReason.rawSignatureFarming:

0 commit comments

Comments
 (0)