Skip to content

Commit 8cdfaae

Browse files
committed
test(desktop): cover Folder Access from a utility window in the Electron e2e
1 parent ba25f86 commit 8cdfaae

2 files changed

Lines changed: 50 additions & 12 deletions

File tree

‎apps/desktop/e2e/local-files.spec.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,55 @@ createRoot(document.getElementById('settings')).render(
267267
await expect(prompt.getByRole('button', { name: "Don't allow", exact: true })).toBeVisible()
268268
return { prompt, result }
269269
}
270+
await test.step('File → Folder Access opens over a focused utility window', async () => {
271+
if (!app) throw new Error('Desktop app is not running')
272+
const serverShown = app.waitForEvent('window', { timeout: 10_000 })
273+
await app.evaluate(({ Menu }) => {
274+
const item = Menu.getApplicationMenu()
275+
?.items.flatMap((entry) => entry.submenu?.items ?? [])
276+
.find((entry) => entry.label === 'Server…')
277+
if (!item) throw new Error('Server menu item missing')
278+
item.click()
279+
})
280+
await expect(await serverShown).toHaveTitle('Sim - Server')
281+
await expect
282+
.poll(() =>
283+
app?.evaluate(({ BrowserWindow }) =>
284+
BrowserWindow.getAllWindows().some(
285+
(win) => win.webContents.getURL().endsWith('server.html') && win.isVisible()
286+
)
287+
)
288+
)
289+
.toBe(true)
290+
const accessMenu = await app.evaluate(({ BrowserWindow, Menu }) => {
291+
const utility = BrowserWindow.getAllWindows().find((win) =>
292+
win.webContents.getURL().endsWith('server.html')
293+
)
294+
if (!utility) throw new Error('Server window missing')
295+
const item = Menu.getApplicationMenu()
296+
?.items.flatMap((entry) => entry.submenu?.items ?? [])
297+
.find((entry) => entry.label === 'Folder Access…')
298+
if (!item) throw new Error('Folder Access menu item missing')
299+
const popup = Menu.prototype.popup
300+
let shown: { anchoredToUtility: boolean; items: string[] } | undefined
301+
Menu.prototype.popup = function (this: Electron.Menu, options) {
302+
shown = {
303+
anchoredToUtility: options?.window === utility,
304+
items: this.items.map((entry) => entry.label),
305+
}
306+
}
307+
try {
308+
item.click(undefined, utility)
309+
} finally {
310+
Menu.prototype.popup = popup
311+
}
312+
utility.close()
313+
return shown
314+
})
315+
expect(accessMenu?.anchoredToUtility).toBe(true)
316+
expect(accessMenu?.items).toContain('Add Folder…')
317+
})
318+
270319
await test.step('Stop cancels only its own request while chats share a folder prompt', async () => {
271320
const sharedFolder = join(root, 'Shared')
272321
mkdirSync(sharedFolder)

‎apps/desktop/src/main/menu.test.ts‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { describe, expect, it, vi } from 'vitest'
22

33
vi.mock('electron', () => import('@/test/electron-mock'))
44

5-
import { BrowserWindow, type MenuItemConstructorOptions } from 'electron'
5+
import type { MenuItemConstructorOptions } from 'electron'
66
import type { ConfigStore } from '@/main/config'
77
import { buildMenuTemplate, type MenuDeps } from '@/main/menu'
88

@@ -45,15 +45,4 @@ describe('buildMenuTemplate', () => {
4545
const view = submenu(buildMenuTemplate(makeDeps()), 'View')
4646
expect(view.some((item) => item.role === 'toggleDevTools')).toBe(false)
4747
})
48-
49-
it('anchors Folder Access to a focused utility window instead of dropping the action', () => {
50-
const deps = makeDeps()
51-
const utilityWindow = new BrowserWindow()
52-
vi.mocked(deps.isMainWindow).mockReturnValue(false)
53-
const folderAccess = submenu(buildMenuTemplate(deps), 'File').find(
54-
(item) => item.label === 'Folder Access…'
55-
)
56-
folderAccess?.click?.({} as never, utilityWindow, {} as never)
57-
expect(deps.openFolderAccess).toHaveBeenCalledWith(utilityWindow)
58-
})
5948
})

0 commit comments

Comments
 (0)