44 getIsolationScope ,
55 getReportDialogEndpoint ,
66 inboundFiltersIntegration ,
7+ lastEventId ,
78} from '@sentry/core' ;
89import * as utils from '@sentry/utils' ;
910
@@ -94,7 +95,7 @@ describe('SentryBrowser', () => {
9495 getCurrentScope ( ) . setUser ( EX_USER ) ;
9596 setCurrentClient ( client ) ;
9697
97- showReportDialog ( { eventId : 'foobar' } ) ;
98+ showReportDialog ( ) ;
9899
99100 expect ( getReportDialogEndpoint ) . toHaveBeenCalledTimes ( 1 ) ;
100101 expect ( getReportDialogEndpoint ) . toHaveBeenCalledWith (
@@ -103,12 +104,37 @@ describe('SentryBrowser', () => {
103104 ) ;
104105 } ) ;
105106
107+ it ( 'uses `lastEventId` from isolation scope' , async ( ) => {
108+ setCurrentClient ( client ) ;
109+ const eventId = captureException ( new Error ( 'Some error' ) ) ;
110+ await flush ( 2000 ) ;
111+
112+ showReportDialog ( ) ;
113+
114+ expect ( eventId ) . toEqual ( lastEventId ( ) ) ;
115+ expect ( getReportDialogEndpoint ) . toHaveBeenCalledTimes ( 1 ) ;
116+ expect ( getReportDialogEndpoint ) . toHaveBeenCalledWith ( expect . any ( Object ) , expect . objectContaining ( { eventId } ) ) ;
117+ } ) ;
118+
119+ it ( 'uses the passed in `eventId` over `lastEventId`' , async ( ) => {
120+ setCurrentClient ( client ) ;
121+ captureException ( new Error ( 'Some error' ) ) ;
122+ await flush ( 2000 ) ;
123+
124+ showReportDialog ( { eventId : 'foobar' } ) ;
125+ expect ( getReportDialogEndpoint ) . toHaveBeenCalledTimes ( 1 ) ;
126+ expect ( getReportDialogEndpoint ) . toHaveBeenCalledWith (
127+ expect . any ( Object ) ,
128+ expect . objectContaining ( { eventId : 'foobar' } ) ,
129+ ) ;
130+ } ) ;
131+
106132 it ( 'prioritizes options user over scope user' , ( ) => {
107133 getCurrentScope ( ) . setUser ( EX_USER ) ;
108134 setCurrentClient ( client ) ;
109135
110136 const DIALOG_OPTION_USER = { email : 'option@example.com' } ;
111- showReportDialog ( { eventId : 'foobar' , user : DIALOG_OPTION_USER } ) ;
137+ showReportDialog ( { user : DIALOG_OPTION_USER } ) ;
112138
113139 expect ( getReportDialogEndpoint ) . toHaveBeenCalledTimes ( 1 ) ;
114140 expect ( getReportDialogEndpoint ) . toHaveBeenCalledWith (
@@ -142,7 +168,7 @@ describe('SentryBrowser', () => {
142168 it ( 'should call `onClose` when receiving `__sentry_reportdialog_closed__` MessageEvent' , async ( ) => {
143169 const onClose = jest . fn ( ) ;
144170
145- showReportDialog ( { eventId : 'foobar' , onClose } ) ;
171+ showReportDialog ( { onClose } ) ;
146172
147173 await waitForPostMessage ( '__sentry_reportdialog_closed__' ) ;
148174 expect ( onClose ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -157,7 +183,7 @@ describe('SentryBrowser', () => {
157183 throw new Error ( ) ;
158184 } ) ;
159185
160- showReportDialog ( { eventId : 'foobar' , onClose } ) ;
186+ showReportDialog ( { onClose } ) ;
161187
162188 await waitForPostMessage ( '__sentry_reportdialog_closed__' ) ;
163189 expect ( onClose ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -170,7 +196,7 @@ describe('SentryBrowser', () => {
170196 it ( 'should not call `onClose` for other MessageEvents' , async ( ) => {
171197 const onClose = jest . fn ( ) ;
172198
173- showReportDialog ( { eventId : 'foobar' , onClose } ) ;
199+ showReportDialog ( { onClose } ) ;
174200
175201 await waitForPostMessage ( 'some_message' ) ;
176202 expect ( onClose ) . not . toHaveBeenCalled ( ) ;
0 commit comments