2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2018 Signal Messenger, LLC
|
2022-01-11 17:28:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
|
|
|
import { stub } from 'sinon';
|
|
|
|
import type { MenuItemConstructorOptions } from 'electron';
|
|
|
|
|
2022-06-08 22:00:32 +00:00
|
|
|
import type { CreateTemplateOptionsType } from '../../../app/menu';
|
2022-01-11 17:28:04 +00:00
|
|
|
import { createTemplate } from '../../../app/menu';
|
|
|
|
import { load as loadLocale } from '../../../app/locale';
|
2022-06-08 22:00:32 +00:00
|
|
|
import type { MenuListType } from '../../types/menu';
|
2023-07-31 16:23:19 +00:00
|
|
|
import { HourCyclePreference } from '../../types/I18N';
|
2022-01-11 17:28:04 +00:00
|
|
|
|
|
|
|
const forceUpdate = stub();
|
2023-02-27 22:34:43 +00:00
|
|
|
const openArtCreator = stub();
|
2022-01-11 17:28:04 +00:00
|
|
|
const openContactUs = stub();
|
|
|
|
const openForums = stub();
|
|
|
|
const openJoinTheBeta = stub();
|
|
|
|
const openReleaseNotes = stub();
|
|
|
|
const openSupportPage = stub();
|
|
|
|
const setupAsNewDevice = stub();
|
|
|
|
const setupAsStandalone = stub();
|
|
|
|
const showAbout = stub();
|
|
|
|
const showDebugLog = stub();
|
|
|
|
const showKeyboardShortcuts = stub();
|
|
|
|
const showSettings = stub();
|
|
|
|
const showWindow = stub();
|
2023-12-22 20:27:49 +00:00
|
|
|
const zoomIn = stub();
|
|
|
|
const zoomOut = stub();
|
|
|
|
const zoomReset = stub();
|
2022-01-11 17:28:04 +00:00
|
|
|
|
|
|
|
const getExpectedEditMenu = (
|
|
|
|
includeSpeech: boolean
|
|
|
|
): MenuItemConstructorOptions => ({
|
|
|
|
label: '&Edit',
|
|
|
|
submenu: [
|
|
|
|
{ label: 'Undo', role: 'undo' },
|
|
|
|
{ label: 'Redo', role: 'redo' },
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ label: 'Cut', role: 'cut' },
|
|
|
|
{ label: 'Copy', role: 'copy' },
|
|
|
|
{ label: 'Paste', role: 'paste' },
|
|
|
|
{ label: 'Paste and Match Style', role: 'pasteAndMatchStyle' },
|
|
|
|
{ label: 'Delete', role: 'delete' },
|
|
|
|
{ label: 'Select All', role: 'selectAll' },
|
|
|
|
...(includeSpeech
|
|
|
|
? ([
|
|
|
|
{ type: 'separator' },
|
|
|
|
{
|
|
|
|
label: 'Speech',
|
|
|
|
submenu: [
|
|
|
|
{ label: 'Start speaking', role: 'startSpeaking' },
|
|
|
|
{ label: 'Stop speaking', role: 'stopSpeaking' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
] as MenuListType)
|
|
|
|
: []),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
2022-06-08 22:00:32 +00:00
|
|
|
const getExpectedViewMenu = (): MenuItemConstructorOptions => ({
|
2022-01-11 17:28:04 +00:00
|
|
|
label: '&View',
|
|
|
|
submenu: [
|
2023-12-22 20:27:49 +00:00
|
|
|
{ accelerator: 'CmdOrCtrl+0', label: 'Actual Size', click: zoomReset },
|
|
|
|
{ accelerator: 'CmdOrCtrl+=', label: 'Zoom In', click: zoomIn },
|
|
|
|
{ accelerator: 'CmdOrCtrl+-', label: 'Zoom Out', click: zoomOut },
|
2022-01-11 17:28:04 +00:00
|
|
|
{ type: 'separator' },
|
|
|
|
{ label: 'Toggle Full Screen', role: 'togglefullscreen' },
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ label: 'Debug Log', click: showDebugLog },
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ label: 'Toggle Developer Tools', role: 'toggleDevTools' },
|
|
|
|
{ label: 'Force Update', click: forceUpdate },
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
const getExpectedHelpMenu = (
|
|
|
|
includeAbout: boolean
|
|
|
|
): MenuItemConstructorOptions => ({
|
|
|
|
label: '&Help',
|
|
|
|
role: 'help',
|
|
|
|
submenu: [
|
|
|
|
{
|
|
|
|
label: 'Show Keyboard Shortcuts',
|
|
|
|
accelerator: 'CmdOrCtrl+/',
|
|
|
|
click: showKeyboardShortcuts,
|
|
|
|
},
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ label: 'Contact Us', click: openContactUs },
|
|
|
|
{ label: 'Go to Release Notes', click: openReleaseNotes },
|
|
|
|
{ label: 'Go to Forums', click: openForums },
|
|
|
|
{ label: 'Go to Support Page', click: openSupportPage },
|
|
|
|
{ label: 'Join the Beta', click: openJoinTheBeta },
|
|
|
|
...(includeAbout
|
|
|
|
? ([
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ label: 'About Signal Desktop', click: showAbout },
|
|
|
|
] as MenuListType)
|
|
|
|
: []),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
const EXPECTED_MACOS: MenuListType = [
|
|
|
|
{
|
|
|
|
label: 'Signal Desktop',
|
|
|
|
submenu: [
|
|
|
|
{ label: 'About Signal Desktop', click: showAbout },
|
|
|
|
{ type: 'separator' },
|
|
|
|
{
|
|
|
|
label: 'Preferences…',
|
|
|
|
accelerator: 'CommandOrControl+,',
|
|
|
|
click: showSettings,
|
|
|
|
},
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ label: 'Services', role: 'services' },
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ label: 'Hide', role: 'hide' },
|
|
|
|
{ label: 'Hide Others', role: 'hideOthers' },
|
|
|
|
{ label: 'Show All', role: 'unhide' },
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ label: 'Quit Signal', role: 'quit' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '&File',
|
|
|
|
submenu: [
|
2023-03-16 00:59:30 +00:00
|
|
|
{ label: 'Create/upload sticker pack', click: openArtCreator },
|
2022-01-11 17:28:04 +00:00
|
|
|
{ type: 'separator' },
|
|
|
|
{ accelerator: 'CmdOrCtrl+W', label: 'Close Window', role: 'close' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
getExpectedEditMenu(true),
|
2022-06-08 22:00:32 +00:00
|
|
|
getExpectedViewMenu(),
|
2022-01-11 17:28:04 +00:00
|
|
|
{
|
|
|
|
label: '&Window',
|
|
|
|
role: 'window',
|
|
|
|
submenu: [
|
|
|
|
{ label: 'Minimize', accelerator: 'CmdOrCtrl+M', role: 'minimize' },
|
|
|
|
{ label: 'Zoom', role: 'zoom' },
|
|
|
|
{ label: 'Show', accelerator: 'CmdOrCtrl+Shift+0', click: showWindow },
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ label: 'Bring All to Front', role: 'front' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
getExpectedHelpMenu(false),
|
|
|
|
];
|
|
|
|
|
|
|
|
const EXPECTED_WINDOWS: MenuListType = [
|
|
|
|
{
|
|
|
|
label: '&File',
|
|
|
|
submenu: [
|
2023-03-16 00:59:30 +00:00
|
|
|
{ label: 'Create/upload sticker pack', click: openArtCreator },
|
2022-01-11 17:28:04 +00:00
|
|
|
{
|
|
|
|
label: 'Preferences…',
|
|
|
|
accelerator: 'CommandOrControl+,',
|
|
|
|
click: showSettings,
|
|
|
|
},
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ label: 'Quit Signal', role: 'quit' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
getExpectedEditMenu(false),
|
2022-06-08 22:00:32 +00:00
|
|
|
getExpectedViewMenu(),
|
2022-01-11 17:28:04 +00:00
|
|
|
{
|
|
|
|
label: '&Window',
|
|
|
|
role: 'window',
|
|
|
|
submenu: [{ label: 'Minimize', role: 'minimize' }],
|
|
|
|
},
|
|
|
|
getExpectedHelpMenu(true),
|
|
|
|
];
|
|
|
|
|
|
|
|
const EXPECTED_LINUX: MenuListType = EXPECTED_WINDOWS.map(menuItem => {
|
|
|
|
if (menuItem.label === '&View' && Array.isArray(menuItem.submenu)) {
|
|
|
|
return {
|
|
|
|
...menuItem,
|
|
|
|
submenu: menuItem.submenu.filter(
|
|
|
|
submenuItem => submenuItem.label !== 'Force Update'
|
|
|
|
),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return menuItem;
|
|
|
|
});
|
|
|
|
|
|
|
|
const PLATFORMS = [
|
|
|
|
{
|
|
|
|
label: 'macOS',
|
|
|
|
platform: 'darwin',
|
|
|
|
expectedDefault: EXPECTED_MACOS,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Windows',
|
|
|
|
platform: 'win32',
|
|
|
|
expectedDefault: EXPECTED_WINDOWS,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Linux',
|
|
|
|
platform: 'linux',
|
|
|
|
expectedDefault: EXPECTED_LINUX,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
describe('createTemplate', () => {
|
2022-09-27 21:01:06 +00:00
|
|
|
const { i18n } = loadLocale({
|
2023-01-25 00:54:46 +00:00
|
|
|
preferredSystemLocales: ['en'],
|
2023-11-06 21:19:23 +00:00
|
|
|
localeOverride: null,
|
2023-12-12 19:41:14 +00:00
|
|
|
localeDirectionTestingOverride: null,
|
2023-07-31 16:23:19 +00:00
|
|
|
hourCyclePreference: HourCyclePreference.UnknownPreference,
|
2022-01-11 17:28:04 +00:00
|
|
|
logger: {
|
2023-04-20 17:03:43 +00:00
|
|
|
fatal: stub().throwsArg(0),
|
|
|
|
error: stub().throwsArg(0),
|
|
|
|
warn: stub().throwsArg(0),
|
|
|
|
info: stub(),
|
|
|
|
debug: stub(),
|
|
|
|
trace: stub(),
|
2022-01-11 17:28:04 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const actions = {
|
|
|
|
forceUpdate,
|
2023-02-27 22:34:43 +00:00
|
|
|
openArtCreator,
|
2022-01-11 17:28:04 +00:00
|
|
|
openContactUs,
|
|
|
|
openForums,
|
|
|
|
openJoinTheBeta,
|
|
|
|
openReleaseNotes,
|
|
|
|
openSupportPage,
|
|
|
|
setupAsNewDevice,
|
|
|
|
setupAsStandalone,
|
|
|
|
showAbout,
|
|
|
|
showDebugLog,
|
|
|
|
showKeyboardShortcuts,
|
|
|
|
showSettings,
|
|
|
|
showWindow,
|
2023-12-22 20:27:49 +00:00
|
|
|
zoomIn,
|
|
|
|
zoomOut,
|
|
|
|
zoomReset,
|
2022-01-11 17:28:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PLATFORMS.forEach(({ label, platform, expectedDefault }) => {
|
|
|
|
describe(label, () => {
|
|
|
|
it('should return the correct template without setup options', () => {
|
2022-06-08 22:00:32 +00:00
|
|
|
const options: CreateTemplateOptionsType = {
|
2022-01-11 17:28:04 +00:00
|
|
|
development: false,
|
|
|
|
devTools: true,
|
|
|
|
includeSetup: false,
|
|
|
|
isProduction: true,
|
|
|
|
platform,
|
|
|
|
...actions,
|
|
|
|
};
|
|
|
|
|
2022-09-27 21:01:06 +00:00
|
|
|
const actual = createTemplate(options, i18n);
|
2022-01-11 17:28:04 +00:00
|
|
|
assert.deepEqual(actual, expectedDefault);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return correct template with setup options', () => {
|
2022-06-08 22:00:32 +00:00
|
|
|
const options: CreateTemplateOptionsType = {
|
2022-01-11 17:28:04 +00:00
|
|
|
development: false,
|
|
|
|
devTools: true,
|
|
|
|
includeSetup: true,
|
|
|
|
isProduction: true,
|
|
|
|
platform,
|
|
|
|
...actions,
|
|
|
|
};
|
|
|
|
|
|
|
|
const expected: MenuListType = expectedDefault.map(menuItem => {
|
|
|
|
if (menuItem.label === '&File' && Array.isArray(menuItem.submenu)) {
|
|
|
|
return {
|
|
|
|
...menuItem,
|
|
|
|
submenu: [
|
|
|
|
{ label: 'Set Up as New Device', click: setupAsNewDevice },
|
|
|
|
{ type: 'separator' },
|
|
|
|
...menuItem.submenu,
|
|
|
|
],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return menuItem;
|
|
|
|
});
|
|
|
|
|
2022-09-27 21:01:06 +00:00
|
|
|
const actual = createTemplate(options, i18n);
|
2022-01-11 17:28:04 +00:00
|
|
|
assert.deepEqual(actual, expected);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|