4
4
getIsolationScope ,
5
5
getReportDialogEndpoint ,
6
6
inboundFiltersIntegration ,
7
+ lastEventId ,
7
8
} from '@sentry/core' ;
8
9
import * as utils from '@sentry/utils' ;
9
10
@@ -94,7 +95,7 @@ describe('SentryBrowser', () => {
94
95
getCurrentScope ( ) . setUser ( EX_USER ) ;
95
96
setCurrentClient ( client ) ;
96
97
97
- showReportDialog ( { eventId : 'foobar' } ) ;
98
+ showReportDialog ( ) ;
98
99
99
100
expect ( getReportDialogEndpoint ) . toHaveBeenCalledTimes ( 1 ) ;
100
101
expect ( getReportDialogEndpoint ) . toHaveBeenCalledWith (
@@ -103,12 +104,37 @@ describe('SentryBrowser', () => {
103
104
) ;
104
105
} ) ;
105
106
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
+
106
132
it ( 'prioritizes options user over scope user' , ( ) => {
107
133
getCurrentScope ( ) . setUser ( EX_USER ) ;
108
134
setCurrentClient ( client ) ;
109
135
110
136
const DIALOG_OPTION_USER = { email :
'[email protected] ' } ;
111
- showReportDialog ( { eventId : 'foobar' , user : DIALOG_OPTION_USER } ) ;
137
+ showReportDialog ( { user : DIALOG_OPTION_USER } ) ;
112
138
113
139
expect ( getReportDialogEndpoint ) . toHaveBeenCalledTimes ( 1 ) ;
114
140
expect ( getReportDialogEndpoint ) . toHaveBeenCalledWith (
@@ -142,7 +168,7 @@ describe('SentryBrowser', () => {
142
168
it ( 'should call `onClose` when receiving `__sentry_reportdialog_closed__` MessageEvent' , async ( ) => {
143
169
const onClose = jest . fn ( ) ;
144
170
145
- showReportDialog ( { eventId : 'foobar' , onClose } ) ;
171
+ showReportDialog ( { onClose } ) ;
146
172
147
173
await waitForPostMessage ( '__sentry_reportdialog_closed__' ) ;
148
174
expect ( onClose ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -157,7 +183,7 @@ describe('SentryBrowser', () => {
157
183
throw new Error ( ) ;
158
184
} ) ;
159
185
160
- showReportDialog ( { eventId : 'foobar' , onClose } ) ;
186
+ showReportDialog ( { onClose } ) ;
161
187
162
188
await waitForPostMessage ( '__sentry_reportdialog_closed__' ) ;
163
189
expect ( onClose ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -170,7 +196,7 @@ describe('SentryBrowser', () => {
170
196
it ( 'should not call `onClose` for other MessageEvents' , async ( ) => {
171
197
const onClose = jest . fn ( ) ;
172
198
173
- showReportDialog ( { eventId : 'foobar' , onClose } ) ;
199
+ showReportDialog ( { onClose } ) ;
174
200
175
201
await waitForPostMessage ( 'some_message' ) ;
176
202
expect ( onClose ) . not . toHaveBeenCalled ( ) ;
0 commit comments