11import '@suite-common/test-utils/globalOverrides' ;
22
33import { Translation } from '@suite/intl' ;
4- import { configureMockStore , screen } from '@suite-common/test-utils' ;
4+ import { events } from '@suite-common/analytics' ;
5+ import { configureMockStore , fireEvent , screen } from '@suite-common/test-utils' ;
56import { type NotificationEntry } from '@suite-common/toast-notifications' ;
67
78import { renderWithProviders } from 'src/support/test-utils/hooksHelper' ;
@@ -12,11 +13,21 @@ import { mockInitialAppState } from '../../../../../mocks/mockInitialAppState';
1213import { type NotificationViewProps } from '../Notifications/NotificationGroup/NotificationList/NotificationView' ;
1314
1415type TradingErrorNotification = Extract < NotificationEntry , { type : 'trading-error' } > ;
16+ type WrapNotification = Extract < NotificationEntry , { type : 'tx-wrap' | 'tx-unwrap' } > ;
17+
18+ const mockReport = jest . fn ( ) ;
1519
1620const MessageView = ( { message, messageValues } : NotificationViewProps ) => (
1721 < Translation id = { message } values = { messageValues } />
1822) ;
1923
24+ // Stands in for ToastNotificationView, the only view that wires `onCancel`.
25+ const DismissableView = ( { onCancel } : NotificationViewProps & { onCancel ?: ( ) => void } ) => (
26+ < button type = "button" onClick = { onCancel } >
27+ dismiss
28+ </ button >
29+ ) ;
30+
2031const renderTradingError = ( payload : Omit < TradingErrorNotification , 'context' | 'id' > ) => {
2132 const notification : TradingErrorNotification = { context : 'toast' , id : 0 , ...payload } ;
2233 const store = configureMockStore ( {
@@ -31,6 +42,64 @@ const renderTradingError = (payload: Omit<TradingErrorNotification, 'context' |
3142 ) ;
3243} ;
3344
45+ const renderWrapToast = ( payload : Omit < WrapNotification , 'context' | 'id' > ) => {
46+ const notification = { context : 'toast' , id : 0 , ...payload } as WrapNotification ;
47+ const store = configureMockStore ( {
48+ preloadedState : mockInitialAppState ,
49+ serializableCheck : { ignoredActions : [ ] } ,
50+ } ) ;
51+ const services = {
52+ ...extraDependenciesDesktopMock . services ,
53+ analytics : { ...extraDependenciesDesktopMock . services . analytics , report : mockReport } ,
54+ } ;
55+
56+ renderWithProviders (
57+ store ,
58+ services ,
59+ < NotificationRenderer render = { DismissableView } notification = { notification } /> ,
60+ ) ;
61+
62+ fireEvent . click ( screen . getByText ( 'dismiss' ) ) ;
63+ } ;
64+
65+ const wrapMetadata = {
66+ send : { symbol : 'eth' , displaySymbol : 'ETH' , amount : '1' } ,
67+ receive : { symbol : 'eth' , displaySymbol : 'WETH' , amount : '1' } ,
68+ } as const ;
69+
70+ const wrapToastPayload = {
71+ type : 'tx-wrap' ,
72+ metadata : wrapMetadata ,
73+ descriptor : '0xdescriptor' ,
74+ symbol : 'eth' ,
75+ txid : '0xwrap' ,
76+ formattedAmount : '1' ,
77+ } as const ;
78+
79+ describe ( 'NotificationRenderer wrap toast dismissal' , ( ) => {
80+ beforeEach ( ( ) => {
81+ jest . clearAllMocks ( ) ;
82+ } ) ;
83+
84+ it . each ( [
85+ [ 'tx-wrap' , 'yieldWrapEvent' ] ,
86+ [ 'tx-unwrap' , 'yieldUnwrapEvent' ] ,
87+ ] as const ) ( 'reports %s dismissal as sent/close' , ( type , eventKey ) => {
88+ renderWrapToast ( { ...wrapToastPayload , type } ) ;
89+
90+ expect ( mockReport ) . toHaveBeenCalledWith ( {
91+ type : events [ eventKey ] . name ,
92+ payload : { type : 'sent' , action : 'close' , networkSymbol : 'eth' } ,
93+ } ) ;
94+ } ) ;
95+
96+ it ( 'stays silent for an in-flow yield step' , ( ) => {
97+ renderWrapToast ( { ...wrapToastPayload , isYieldFlowStep : true } ) ;
98+
99+ expect ( mockReport ) . not . toHaveBeenCalled ( ) ;
100+ } ) ;
101+ } ) ;
102+
34103describe ( 'NotificationRenderer trading-error' , ( ) => {
35104 it ( 'step 1: renders the structured message when data is present, ignoring the partner message' , ( ) => {
36105 renderTradingError ( {
0 commit comments