@@ -7,6 +7,9 @@ import * as useAlertsModule from '../../../../hooks/useAlerts';
7
7
import mockState from '../../../../../test/data/mock-state.json' ;
8
8
import { Alert } from '../../../../ducks/confirm-alerts/confirm-alerts' ;
9
9
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' ;
10
13
11
14
const onProcessActionMock = jest . fn ( ) ;
12
15
@@ -28,6 +31,16 @@ jest.mock('../contexts/alertMetricsContext', () => ({
28
31
} ) ) ,
29
32
} ) ) ;
30
33
34
+ jest . mock ( '../../../../pages/confirmations/context/confirm' , ( ) => ( {
35
+ useConfirmContext : jest . fn ( ( ) => ( {
36
+ currentConfirmation : {
37
+ securityAlertResponse : {
38
+ reason : '' ,
39
+ } ,
40
+ } ,
41
+ } ) ) ,
42
+ } ) ) ;
43
+
31
44
describe ( 'AlertModal' , ( ) => {
32
45
const OWNER_ID_MOCK = '123' ;
33
46
const FROM_ALERT_KEY_MOCK = 'from' ;
@@ -292,4 +305,135 @@ describe('AlertModal', () => {
292
305
) ;
293
306
} ) ;
294
307
} ) ;
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
+ } ) ;
295
439
} ) ;
0 commit comments