Skip to content

Commit 383ff25

Browse files
committed
use actual menu for tests
1 parent 17a8807 commit 383ff25

File tree

2 files changed

+16
-43
lines changed

2 files changed

+16
-43
lines changed

packages/compass/src/main/menu.spec.ts

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import EventEmitter, { once } from 'events';
1+
import EventEmitter from 'events';
22
import type { MenuItemConstructorOptions } from 'electron';
33
import { BrowserWindow, ipcMain, Menu, app, dialog } from 'electron';
44
import { expect } from 'chai';
@@ -654,49 +654,22 @@ describe('CompassMenu', function () {
654654
]);
655655
});
656656

657-
// TODO(COMPASS-8505): Remove skipping on linux
658-
const testIt = os.platform() === 'linux' ? it.skip : it;
659-
testIt(
660-
'does not crash when rendering menu item with an accelerator',
661-
async () => {
662-
const menu = Menu.buildFromTemplate([
663-
{
664-
label: 'Test Super',
665-
accelerator: 'Super+Ctrl+T',
666-
},
667-
{
668-
label: 'Test Meta',
669-
accelerator: 'Meta+Ctrl+T',
670-
},
671-
{
672-
label: 'Test CmdOrCtrl',
673-
accelerator: 'CmdOrCtrl+Q',
674-
},
675-
{
676-
label: 'Test Command',
677-
accelerator: 'Command+H',
678-
},
679-
{
680-
label: 'Test Command+Shift',
681-
accelerator: 'Command+Shift+H',
682-
},
683-
{
684-
label: 'Test Atl+CmdOrCtrl',
685-
accelerator: 'Alt+CmdOrCtrl+S',
686-
},
687-
{
688-
label: 'Test Shift+CmdOrCtrl',
689-
accelerator: 'Shift+CmdOrCtrl+S',
690-
},
691-
]);
692-
const menuWillClose = once(menu, 'menu-will-close');
693-
menu.popup({
694-
window: new BrowserWindow({ show: false }),
695-
});
657+
it('does not crash when rendering menu item with an accelerator', () => {
658+
const window = new BrowserWindow({ show: false });
659+
const template = CompassMenu.getTemplate(window.id);
660+
661+
// As the root menu items do not have accelerators, we test
662+
// against each item's submenu.
663+
for (const item of template) {
664+
// for TS. compass menu has submenus
665+
if (!Array.isArray(item.submenu)) {
666+
continue;
667+
}
668+
const menu = Menu.buildFromTemplate(item.submenu);
669+
menu.popup({ window });
696670
menu.closePopup();
697-
await menuWillClose;
698671
}
699-
);
672+
});
700673

701674
it('should generate a menu template without collection submenu if `showCollection` is `false`', function () {
702675
expect(

packages/compass/src/main/menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ class WindowMenuState {
523523
function removeAcceleratorFromMenu(
524524
menu?: MenuItemConstructorOptions[]
525525
): MenuItemConstructorOptions[] {
526-
if (!menu || !Array.isArray(menu)) {
526+
if (!Array.isArray(menu)) {
527527
return [];
528528
}
529529
// eslint-disable-next-line @typescript-eslint/no-unused-vars

0 commit comments

Comments
 (0)