@@ -4,7 +4,12 @@ import * as Deferred from "effect/Deferred";
44import * as Effect from "effect/Effect" ;
55import * as Layer from "effect/Layer" ;
66
7- import type * as Electron from "electron" ;
7+ import * as Electron from "electron" ;
8+ import { vi } from "vite-plus/test" ;
9+
10+ vi . mock ( "electron" , ( ) => ( {
11+ webContents : { getAllWebContents : vi . fn ( ( ) => [ ] ) } ,
12+ } ) ) ;
813
914import * as ElectronApp from "../electron/ElectronApp.ts" ;
1015import * as ElectronDialog from "../electron/ElectronDialog.ts" ;
@@ -227,10 +232,32 @@ describe("DesktopApplicationMenu", () => {
227232 items . find ( ( item ) => item . role === "windowMenu" && item . submenu === undefined ) ,
228233 platform ,
229234 ) ;
230- assert . isUndefined (
231- items . find ( ( item ) => item . accelerator ?. toLowerCase ( ) . endsWith ( "+w" ) ) ,
232- platform ,
233- ) ;
235+ const closeTools = items . find ( ( item ) => item . accelerator === "CmdOrCtrl+W" ) ;
236+ assert . equal ( closeTools ?. label , "Close Developer Tools" , platform ) ;
237+ assert . isFunction ( closeTools ?. click ) ;
238+ const appContents = {
239+ isDestroyed : ( ) => false ,
240+ isDevToolsFocused : ( ) => false ,
241+ closeDevTools : vi . fn ( ) ,
242+ } ;
243+ const inspectedContents = {
244+ ...appContents ,
245+ isDevToolsFocused : ( ) => true ,
246+ closeDevTools : vi . fn ( ) ,
247+ } ;
248+ using allContents = vi
249+ . spyOn ( Electron . webContents , "getAllWebContents" )
250+ . mockReturnValue ( [
251+ appContents as unknown as Electron . WebContents ,
252+ inspectedContents as unknown as Electron . WebContents ,
253+ ] ) ;
254+ closeTools ?. click ?.( { } as Electron . MenuItem , undefined , { } as KeyboardEvent ) ;
255+ assert . equal ( inspectedContents . closeDevTools . mock . calls . length , 1 ) ;
256+ assert . equal ( appContents . closeDevTools . mock . calls . length , 0 ) ;
257+
258+ allContents . mockReturnValue ( [ appContents as unknown as Electron . WebContents ] ) ;
259+ closeTools ?. click ?.( { } as Electron . MenuItem , undefined , { } as KeyboardEvent ) ;
260+ assert . equal ( appContents . closeDevTools . mock . calls . length , 0 ) ;
234261 }
235262 } ) ,
236263 ) ;
0 commit comments