@@ -113,30 +113,40 @@ describe("previewWindowOpenAction", () => {
113113
114114const {
115115 browserWindowConstructor,
116+ clipboardItemConstructor,
116117 createFromPath,
117118 fromId,
118119 getFocusedWebContents,
119120 mkdir,
120121 showItemInFolder,
121122 webviewSend,
122123 writeFile,
123- writeImage ,
124+ writeClipboard ,
124125} = vi . hoisted ( ( ) => ( {
125126 browserWindowConstructor : vi . fn ( ) ,
126- createFromPath : vi . fn ( ( ) : { readonly isEmpty : ( ) => boolean } => ( { isEmpty : ( ) => false } ) ) ,
127+ clipboardItemConstructor : vi . fn ( ) ,
128+ createFromPath : vi . fn ( ( ) : { readonly isEmpty : ( ) => boolean ; readonly toPNG : ( ) => Buffer } => ( {
129+ isEmpty : ( ) => false ,
130+ toPNG : ( ) => Buffer . from ( "png" ) ,
131+ } ) ) ,
127132 fromId : vi . fn < ( _id ?: number ) => Electron . WebContents | null > ( ( _id ?: number ) => null ) ,
128133 getFocusedWebContents : vi . fn ( ( ) => null ) ,
129134 mkdir : vi . fn ( ( _path : string ) => undefined ) ,
130135 showItemInFolder : vi . fn ( ) ,
131136 webviewSend : vi . fn ( ) ,
132137 writeFile : vi . fn ( ( _path : string , _data : Uint8Array ) => undefined ) ,
133- writeImage : vi . fn ( ) ,
138+ writeClipboard : vi . fn ( async ( ) => undefined ) ,
134139} ) ) ;
135140
136141vi . mock ( "electron" , ( ) => ( {
137142 BrowserWindow : browserWindowConstructor ,
143+ ClipboardItem : class {
144+ constructor ( data : Record < string , unknown > ) {
145+ clipboardItemConstructor ( data ) ;
146+ }
147+ } ,
138148 clipboard : {
139- writeImage ,
149+ write : writeClipboard ,
140150 } ,
141151 nativeImage : {
142152 createFromPath,
@@ -471,7 +481,8 @@ describe("PreviewManager", () => {
471481 mkdir . mockClear ( ) ;
472482 writeFile . mockClear ( ) ;
473483 showItemInFolder . mockClear ( ) ;
474- writeImage . mockClear ( ) ;
484+ clipboardItemConstructor . mockClear ( ) ;
485+ writeClipboard . mockClear ( ) ;
475486 createFromPath . mockClear ( ) ;
476487 webviewSend . mockClear ( ) ;
477488 } ) ;
@@ -3671,7 +3682,10 @@ describe("PreviewManager", () => {
36713682 yield * manager . copyArtifactToClipboard ( artifactPath ) ;
36723683
36733684 expect ( createFromPath ) . toHaveBeenCalledWith ( artifactPath ) ;
3674- expect ( writeImage ) . toHaveBeenCalledOnce ( ) ;
3685+ expect ( clipboardItemConstructor ) . toHaveBeenCalledWith ( {
3686+ "image/png" : expect . any ( Blob ) ,
3687+ } ) ;
3688+ expect ( writeClipboard ) . toHaveBeenCalledOnce ( ) ;
36753689 const exit = yield * Effect . exit (
36763690 manager . copyArtifactToClipboard ( "/tmp/t3/dev/settings.json" ) ,
36773691 ) ;
@@ -3685,14 +3699,29 @@ describe("PreviewManager", () => {
36853699 } ) ;
36863700 expect ( "cause" in error ) . toBe ( false ) ;
36873701
3688- createFromPath . mockReturnValueOnce ( { isEmpty : ( ) => true } ) ;
3702+ createFromPath . mockReturnValueOnce ( {
3703+ isEmpty : ( ) => true ,
3704+ toPNG : ( ) => Buffer . from ( "invalid" ) ,
3705+ } ) ;
36893706 const invalidImageExit = yield * Effect . exit ( manager . copyArtifactToClipboard ( artifactPath ) ) ;
36903707 expect ( Exit . isFailure ( invalidImageExit ) ) . toBe ( true ) ;
36913708 if ( Exit . isSuccess ( invalidImageExit ) ) return ;
36923709 expect ( Option . getOrThrow ( Cause . findErrorOption ( invalidImageExit . cause ) ) ) . toMatchObject ( {
36933710 _tag : "PreviewArtifactImageLoadError" ,
36943711 artifactPath,
36953712 } ) ;
3713+
3714+ const writeCause = new Error ( "clipboard write failed" ) ;
3715+ writeClipboard . mockRejectedValueOnce ( writeCause ) ;
3716+ const writeExit = yield * Effect . exit ( manager . copyArtifactToClipboard ( artifactPath ) ) ;
3717+ expect ( Exit . isFailure ( writeExit ) ) . toBe ( true ) ;
3718+ if ( Exit . isSuccess ( writeExit ) ) return ;
3719+ expect ( Option . getOrThrow ( Cause . findErrorOption ( writeExit . cause ) ) ) . toMatchObject ( {
3720+ _tag : "PreviewOperationError" ,
3721+ operation : "copyArtifactToClipboard.write" ,
3722+ artifactPath,
3723+ cause : writeCause ,
3724+ } ) ;
36963725 } ) ,
36973726 ) ,
36983727 ) ;
0 commit comments