@@ -2,7 +2,7 @@ import { assert, describe, it } from "@effect/vitest";
22import * as Effect from "effect/Effect" ;
33import * as Option from "effect/Option" ;
44import type * as Electron from "electron" ;
5- import { beforeEach , vi } from "vite-plus/test" ;
5+ import { afterEach , beforeEach , vi } from "vite-plus/test" ;
66
77const { buildFromTemplateMock, createFromNamedImageMock, setApplicationMenuMock } = vi . hoisted (
88 ( ) => ( {
@@ -24,13 +24,21 @@ vi.mock("electron", () => ({
2424
2525import * as ElectronMenu from "./ElectronMenu.ts" ;
2626
27+ const originalPlatformDescriptor = Object . getOwnPropertyDescriptor ( process , "platform" ) ;
28+
2729describe ( "ElectronMenu" , ( ) => {
2830 beforeEach ( ( ) => {
2931 buildFromTemplateMock . mockReset ( ) ;
3032 createFromNamedImageMock . mockReset ( ) ;
3133 setApplicationMenuMock . mockReset ( ) ;
3234 } ) ;
3335
36+ afterEach ( ( ) => {
37+ if ( originalPlatformDescriptor ) {
38+ Object . defineProperty ( process , "platform" , originalPlatformDescriptor ) ;
39+ }
40+ } ) ;
41+
3442 it . effect ( "returns none without building a menu when there are no valid items" , ( ) =>
3543 Effect . gen ( function * ( ) {
3644 const electronMenu = yield * ElectronMenu . ElectronMenu ;
@@ -116,4 +124,39 @@ describe("ElectronMenu", () => {
116124 assert . equal ( popupMock . mock . calls . length , 1 ) ;
117125 } ) . pipe ( Effect . provide ( ElectronMenu . layer ) ) ,
118126 ) ;
127+
128+ it . effect ( "uses template images for destructive macOS context menu icons" , ( ) =>
129+ Effect . gen ( function * ( ) {
130+ Object . defineProperty ( process , "platform" , {
131+ configurable : true ,
132+ value : "darwin" ,
133+ } ) ;
134+
135+ const resizedIcon = {
136+ isEmpty : vi . fn ( ( ) => false ) ,
137+ setTemplateImage : vi . fn ( ( _template : boolean ) => undefined ) ,
138+ } ;
139+ const sourceIcon = {
140+ resize : vi . fn ( ( _size : { width : number ; height : number } ) => resizedIcon ) ,
141+ } ;
142+ createFromNamedImageMock . mockReturnValue ( sourceIcon ) ;
143+ buildFromTemplateMock . mockImplementation ( ( ) => ( {
144+ popup : ( options : Electron . PopupOptions ) => {
145+ options . callback ?.( ) ;
146+ } ,
147+ } ) ) ;
148+
149+ const electronMenu = yield * ElectronMenu . ElectronMenu ;
150+ yield * electronMenu . showContextMenu ( {
151+ window : { } as Electron . BrowserWindow ,
152+ items : [ { id : "delete" , label : "Remove project" , destructive : true } ] ,
153+ position : Option . none ( ) ,
154+ } ) ;
155+
156+ assert . equal ( createFromNamedImageMock . mock . calls [ 0 ] ?. [ 0 ] , "trash" ) ;
157+ assert . deepEqual ( sourceIcon . resize . mock . calls [ 0 ] ?. [ 0 ] , { width : 12 , height : 12 } ) ;
158+ assert . deepEqual ( resizedIcon . setTemplateImage . mock . calls [ 0 ] , [ true ] ) ;
159+ assert . strictEqual ( buildFromTemplateMock . mock . calls [ 0 ] ?. [ 0 ] [ 0 ] ?. icon , resizedIcon ) ;
160+ } ) . pipe ( Effect . provide ( ElectronMenu . layer ) ) ,
161+ ) ;
119162} ) ;
0 commit comments