@@ -6,13 +6,23 @@ import { vi } from "vite-plus/test";
66
77import type * as Electron from "electron" ;
88
9+ const { focusedWebContents, ownerWindow } = vi . hoisted ( ( ) => ( {
10+ focusedWebContents : vi . fn ( ) ,
11+ ownerWindow : vi . fn ( ) ,
12+ } ) ) ;
13+ vi . mock ( "electron" , ( ) => ( {
14+ webContents : { getFocusedWebContents : focusedWebContents } ,
15+ BrowserWindow : { fromWebContents : ownerWindow } ,
16+ } ) ) ;
17+
918import * as DesktopBackendManager from "../../backend/DesktopBackendManager.ts" ;
1019import * as DesktopBackendPool from "../../backend/DesktopBackendPool.ts" ;
1120import * as ElectronDialog from "../../electron/ElectronDialog.ts" ;
1221import * as ElectronWindow from "../../electron/ElectronWindow.ts" ;
1322import {
1423 getLocalEnvironmentBootstraps ,
1524 getWindowFullscreenState ,
25+ pasteAsText ,
1626 pickProjectFavicon ,
1727} from "./window.ts" ;
1828
@@ -153,6 +163,50 @@ describe("getWindowFullscreenState", () => {
153163 } ) ;
154164} ) ;
155165
166+ describe ( "pasteAsText" , ( ) => {
167+ it . effect (
168+ "pastes into the focused guest only after the main renderer acknowledges the menu action" ,
169+ ( ) => {
170+ const paste = vi . fn ( ) ;
171+ const mainPaste = vi . fn ( ) ;
172+ const window = {
173+ webContents : { id : 42 , paste : mainPaste } ,
174+ isDestroyed : ( ) => false ,
175+ } as unknown as Electron . BrowserWindow ;
176+ focusedWebContents . mockReturnValue ( { paste, isDestroyed : ( ) => false } ) ;
177+ ownerWindow . mockReturnValue ( window ) ;
178+
179+ return Effect . gen ( function * ( ) {
180+ yield * pasteAsText . handler ( undefined , { sender : { id : 42 } } ) ;
181+ assert . equal ( paste . mock . calls . length , 1 ) ;
182+ assert . equal ( mainPaste . mock . calls . length , 0 ) ;
183+
184+ yield * pasteAsText . handler ( undefined , { sender : { id : 99 } } ) ;
185+ assert . equal ( paste . mock . calls . length , 1 ) ;
186+ ownerWindow . mockReturnValue ( { } ) ; // A focused PiP/other BrowserWindow.
187+ yield * pasteAsText . handler ( undefined , { sender : { id : 42 } } ) ;
188+ assert . equal ( paste . mock . calls . length , 1 ) ;
189+ ownerWindow . mockReturnValue ( null ) ; // Detached contents.
190+ yield * pasteAsText . handler ( undefined , { sender : { id : 42 } } ) ;
191+ assert . equal ( paste . mock . calls . length , 1 ) ;
192+ ownerWindow . mockReturnValue ( window ) ;
193+ focusedWebContents . mockReturnValue ( { paste, isDestroyed : ( ) => true } ) ;
194+ yield * pasteAsText . handler ( undefined , { sender : { id : 42 } } ) ;
195+ assert . equal ( paste . mock . calls . length , 1 ) ;
196+ focusedWebContents . mockReturnValue ( null ) ;
197+ yield * pasteAsText . handler ( undefined , { sender : { id : 42 } } ) ;
198+ assert . equal ( paste . mock . calls . length , 1 ) ;
199+ } ) . pipe (
200+ Effect . provide (
201+ Layer . mock ( ElectronWindow . ElectronWindow ) ( {
202+ main : Effect . succeed ( Option . some ( window ) ) ,
203+ } ) ,
204+ ) ,
205+ ) ;
206+ } ,
207+ ) ;
208+ } ) ;
209+
156210describe ( "pickProjectFavicon" , ( ) => {
157211 it . effect ( "opens a single-image picker from the project directory" , ( ) =>
158212 Effect . gen ( function * ( ) {
0 commit comments