@@ -33,6 +33,7 @@ const bridge = vi.hoisted(() => ({
3333 previewSnapShotConfig : vi . fn ( ) ,
3434 applySnapShotConfig : vi . fn ( ) ,
3535 setupSnapShot : vi . fn ( ) ,
36+ requestSnapShotPermissions : vi . fn ( ) . mockResolvedValue ( undefined ) ,
3637 onMenuAction : vi . fn ( ) ,
3738 onSnapShotEvent : vi . fn ( ( ) => ( ) => undefined ) ,
3839} ) ) ;
@@ -337,3 +338,79 @@ it("keeps setup errors in the wizard and does not toast them after closing it",
337338 expect ( wizard ( renderWithEffects ( ) ) ) . toBeNull ( ) ;
338339 expect ( toastManager . add ) . not . toHaveBeenCalled ( ) ;
339340} ) ;
341+
342+ it . each ( [ false , true ] ) (
343+ "resumes macOS permission setup after restart and clears it on close, completed=%s" ,
344+ async ( completed ) => {
345+ const { readSnapShotSetupResume } = await import ( "../../lib/snapShotSetupResume" ) ;
346+ const values = new Map < string , string > ( ) ;
347+ Object . assign ( window , {
348+ localStorage : {
349+ getItem : ( key : string ) => values . get ( key ) ?? null ,
350+ setItem : ( key : string , value : string ) => values . set ( key , value ) ,
351+ removeItem : ( key : string ) => values . delete ( key ) ,
352+ } ,
353+ } ) ;
354+ settingsStore . current = { ...settingsStore . current , snapShotEnabled : false } ;
355+ state = {
356+ mode : "direct" ,
357+ shortcut : DEFAULT_CLIENT_SETTINGS . snapShotShortcut ,
358+ shortcutRegistered : false ,
359+ shortcutMessage : null ,
360+ message : null ,
361+ macPermissions : { screenRecording : false , accessibility : false } ,
362+ } ;
363+ const tree = await mount ( ) ;
364+ const toggle = visitElements (
365+ tree ,
366+ ( element ) => element . props [ "aria-label" ] === "Enable snapshots" ,
367+ ) ;
368+ ( toggle ! . props . onCheckedChange as ( checked : boolean ) => void ) ( true ) ;
369+ await finish ( bridge . getSnapShotState . mock . results [ 1 ] ! . value ) ;
370+ bridge . setupSnapShot . mockImplementationOnce ( async ( ) => {
371+ expect ( readSnapShotSetupResume ( ) ) . toEqual ( { wasEnabled : false } ) ;
372+ } ) ;
373+ await ( wizard ( render ( ) ) ! . props . onAction as ( action : string ) => Promise < void > ) (
374+ "allow-screen-recording" ,
375+ ) ;
376+
377+ hooks . reset ( ) ;
378+ effects . length = 0 ;
379+ bridge . getSnapShotState . mockClear ( ) ;
380+ state = { ...state , macPermissions : { screenRecording : true , accessibility : true } } ;
381+ const resumed = wizard ( await mount ( ) ) ;
382+ expect ( resumed ) . not . toBeNull ( ) ;
383+ expect ( resumed ! . props . initialStep ) . toBe ( "access" ) ;
384+ expect ( resumed ! . props . wasEnabled ) . toBe ( false ) ;
385+ await ( resumed ! . props . onClose as ( completed : boolean ) => Promise < void > ) ( completed ) ;
386+ expect ( wizard ( render ( ) ) ) . toBeNull ( ) ;
387+ expect ( readSnapShotSetupResume ( ) ) . toBeNull ( ) ;
388+ } ,
389+ ) ;
390+
391+ it ( "requires a successful macOS test capture before enabling and allows retry" , async ( ) => {
392+ settingsStore . current = { ...DEFAULT_CLIENT_SETTINGS , snapShotEnabled : false } ;
393+ state = {
394+ mode : "direct" ,
395+ shortcut : DEFAULT_CLIENT_SETTINGS . snapShotShortcut ,
396+ shortcutRegistered : false ,
397+ shortcutMessage : null ,
398+ message : null ,
399+ macPermissions : { screenRecording : true , accessibility : true } ,
400+ } ;
401+ const tree = await mount ( ) ;
402+ const toggle = visitElements (
403+ tree ,
404+ ( element ) => element . props [ "aria-label" ] === "Enable snapshots" ,
405+ ) ;
406+ ( toggle ! . props . onCheckedChange as ( checked : boolean ) => void ) ( true ) ;
407+ await finish ( bridge . getSnapShotState . mock . results [ 1 ] ! . value ) ;
408+ bridge . setupSnapShot . mockRejectedValueOnce ( new Error ( "Capture was denied" ) ) ;
409+ const enable = ( ) => ( wizard ( render ( ) ) ! . props . onEnable as ( ) => Promise < boolean > ) ( ) ;
410+ expect ( await enable ( ) ) . toBe ( false ) ;
411+ expect ( wizard ( render ( ) ) ! . props . error ) . toBe ( "Capture was denied" ) ;
412+ expect ( settingsStore . current . snapShotEnabled ) . toBe ( false ) ;
413+ expect ( await enable ( ) ) . toBe ( true ) ;
414+ expect ( bridge . setupSnapShot . mock . calls ) . toEqual ( [ [ "test-mac-capture" ] , [ "test-mac-capture" ] ] ) ;
415+ expect ( settingsStore . current . snapShotEnabled ) . toBe ( true ) ;
416+ } ) ;
0 commit comments