* feat: add experimental Apple Silicon support with Nivfold Integrate the standalone Nivfold protocol 1 runner; tested against Nivfold f436fb6. The Windows Reims vGPU runtime remains independent. * fix: open QQ invites and VM SSH on macOS * fix: move VM, View and Help to the macOS menu bar * feat(macos): add resumable Apple restore image downloads Expose the compatible restore image in the VM wizard and Images page, validate downloads before caching, and fix macOS memory reporting and plugin SVG rendering. * fix(macos): localize the native application menu * fix(macos): address native desktop review findings
79 lines
4.4 KiB
JavaScript
79 lines
4.4 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
import { loadTestModule } from './load-test-module.mjs'
|
|
|
|
const { buildNativeMenu, resolveMenuClick, buildTitleMenus, runMenuCommand, vmFeatures } = await loadTestModule(`
|
|
import './i18n/domains/core.gen'
|
|
import './i18n/domains/vm.gen'
|
|
export * from './macos/applicationMenuModel'
|
|
export * from './lib/titleMenu'
|
|
export { vmFeatures } from './lib/endpoints'
|
|
`)
|
|
const props = { locale: 'en-US', sidebarOpen: true, logsOpen: false, themeMode: 'system', canLight: true, canDark: true, vm: null }
|
|
const state = { workspaceReady: true, dialogOpen: false, vmSettingsReady: false }
|
|
const vm = { name: 'test', state: 'stopped', busy: false, canSuspend: false, features: vmFeatures() }
|
|
const find = (model, command) => model.groups.flatMap((group) => group.rows).find((row) => row.command === command)
|
|
|
|
test('the native bar localizes three menus and reflects view state and Command shortcuts', () => {
|
|
const { groups } = buildNativeMenu({ ...props, locale: 'zh-CN' }, state)
|
|
assert.deepEqual(groups.map(({ label }) => label), ['虚拟机', '视图', '帮助'])
|
|
const menu = buildNativeMenu({ ...props, canDark: false, themeMode: 'light', logsOpen: true, vm }, state)
|
|
assert.deepEqual(menu.groups.map(({ label }) => label), ['VM', 'View', 'Help'])
|
|
assert.equal(find(menu, 'sidebar').checked, true)
|
|
assert.equal(find(menu, 'logs').checked, true)
|
|
assert.equal(find(menu, 'theme:light').checked, true)
|
|
assert.equal(find(menu, 'theme:dark'), undefined)
|
|
assert.equal(find(menu, 'theme:system'), undefined)
|
|
assert.deepEqual(['new', 'sidebar', 'logs', 'settings', 'vm:start'].map((command) => find(menu, command).key), ['n', 'b', 'l', ',', '\r'])
|
|
assert.equal(buildTitleMenus(props).vm.rows[0].shortcut, 'Ctrl+N')
|
|
})
|
|
|
|
test('standard macOS menus use the same locale as the app-defined menus', () => {
|
|
const { standard: zh } = buildNativeMenu({ ...props, locale: 'zh-CN' }, state)
|
|
const { standard: en } = buildNativeMenu(props, state)
|
|
assert.deepEqual([zh.edit, zh.window, zh['hide:'], zh.Quit], ['编辑', '窗口', '隐藏 Reims-Go', '退出 Reims-Go'])
|
|
assert.deepEqual([en.edit, en.window, en['hide:'], en.Quit], ['Edit', 'Window', 'Hide Reims-Go', 'Quit Reims-Go'])
|
|
assert.deepEqual([zh['undo:'], zh['redo:'], zh['pasteAsRichText:'], zh['startSpeaking:']], ['撤销', '重做', '粘贴并匹配样式', '开始朗读'])
|
|
for (const key of Object.keys(en)) assert.notEqual(zh[key], en[key], key)
|
|
})
|
|
|
|
test('VM menu validates the current VM state and ignores stale targets', () => {
|
|
const selected = { ...state, selectedVMKey: 'driver:test', vmSettingsReady: true }
|
|
let menu = buildNativeMenu({ ...props, vm }, selected)
|
|
const click = (command, scope = selected.selectedVMKey) => resolveMenuClick({ command, scope }, menu.scope, menu.commands)
|
|
assert.equal(click('vm:start'), 'vm:start')
|
|
assert.equal(click('vm:start', 'another-driver:test'), undefined)
|
|
assert.equal(click('vmSettings'), 'vmSettings')
|
|
assert.equal(click('vm:stop'), undefined)
|
|
|
|
menu = buildNativeMenu({ ...props, vm: { ...vm, state: 'running' } }, selected)
|
|
assert.equal(click('vm:start'), undefined)
|
|
assert.equal(click('vm:focus'), 'vm:focus')
|
|
assert.equal(click('vm:stop'), 'vm:stop')
|
|
assert.equal(click('vm:delete'), undefined)
|
|
|
|
menu = buildNativeMenu({ ...props, vm: { ...vm, state: 'suspended' } }, selected)
|
|
assert.equal(click('vm:resume'), undefined)
|
|
assert.equal(click('vmSettings'), undefined)
|
|
assert.equal(click('vm:discardSuspend'), 'vm:discardSuspend')
|
|
})
|
|
|
|
test('setup only exposes external help, and modal dialogs block native menu commands', () => {
|
|
const setup = buildNativeMenu(props, { ...state, workspaceReady: false })
|
|
assert.deepEqual([...setup.commands], ['website', 'docs', 'project', 'report'])
|
|
assert.equal(buildNativeMenu(props, { ...state, dialogOpen: true }).commands.size, 0)
|
|
})
|
|
|
|
test('native menu commands reuse the renderer actions and URL localization', () => {
|
|
const calls = []
|
|
const actions = { ...props, locale: 'zh-CN',
|
|
onVMAction: (action) => calls.push(action),
|
|
onVMDelete: () => calls.push('confirm delete'),
|
|
onNavigate: (page) => calls.push(page),
|
|
onThemeMode: (mode) => calls.push(mode),
|
|
onOpenURL: (url) => calls.push(url),
|
|
}
|
|
for (const id of ['vm:stop', 'vm:delete', 'settings', 'update', 'theme:dark', 'docs']) runMenuCommand(actions, id)
|
|
assert.deepEqual(calls, ['stop', 'confirm delete', 'settings', 'about', 'dark', 'https://reims.dev/docs/quick-start'])
|
|
})
|