@@ -268,6 +268,48 @@ describe("Collection view random rom", () => {
268268 expect ( push ) . toHaveBeenCalledWith ( { name : "rom" , params : { rom : 7 } } ) ;
269269 } ) ;
270270
271+ // Issue #4114: leaving for a route that is not another gallery leaves
272+ // `currentCollection` set, so the id check alone cannot tell that the user
273+ // walked away.
274+ it ( "drops a pick that lands after the user left the gallery" , async ( ) => {
275+ let resolvePick : ( value : { data : SimpleRom } ) => void = ( ) => { } ;
276+ getRandomRom . mockReturnValueOnce (
277+ new Promise ( ( resolve ) => {
278+ resolvePick = resolve ;
279+ } ) ,
280+ ) ;
281+
282+ const wrapper = await mountView ( ) ;
283+ await wrapper . get ( "button.random" ) . trigger ( "click" ) ;
284+
285+ wrapper . unmount ( ) ;
286+
287+ resolvePick ( { data : rom ( 42 ) } ) ;
288+ await flushPromises ( ) ;
289+
290+ expect ( push ) . not . toHaveBeenCalled ( ) ;
291+ } ) ;
292+
293+ it ( "stays quiet when a pick fails after the user left the gallery" , async ( ) => {
294+ let failPick : ( reason : Error ) => void = ( ) => { } ;
295+ getRandomRom . mockReturnValueOnce (
296+ new Promise ( ( _resolve , reject ) => {
297+ failPick = reject ;
298+ } ) ,
299+ ) ;
300+
301+ const wrapper = await mountView ( ) ;
302+ await wrapper . get ( "button.random" ) . trigger ( "click" ) ;
303+
304+ wrapper . unmount ( ) ;
305+
306+ failPick ( new Error ( "boom" ) ) ;
307+ await flushPromises ( ) ;
308+
309+ expect ( snackbarError ) . not . toHaveBeenCalled ( ) ;
310+ expect ( push ) . not . toHaveBeenCalled ( ) ;
311+ } ) ;
312+
271313 it ( "ignores a click while a pick is in flight" , async ( ) => {
272314 let resolvePick : ( value : { data : SimpleRom } ) => void = ( ) => { } ;
273315 getRandomRom . mockReturnValue (
0 commit comments