import assert from 'node:assert/strict' import test, { after, before } from 'node:test' import { loadTestModule } from './load-test-module.mjs' let fixture before(async () => { // Wails reads its window bindings at import time. Static rendering uses the VM detail before the first live poll. globalThis.window = {} fixture = await loadTestModule(` import { createElement } from 'react' import { renderToStaticMarkup } from 'react-dom/server.edge' import { TooltipProvider } from './ui/controls' import { VMPage } from './components/VMPage' import { ConnectionSection } from './components/vmPage/connections' export { showHostDropAck } from './App' export function render({ locale = 'en-US', installed = 21, bundled = 21, connected = true, denied, disabled = false } = {}) { const detail = { guest_tools_configured: true, guest_tools_connected: connected, guest_tools_agent_version: installed, guest_tools_drop_access_denied: denied, guest_tools_disabled: disabled, } return renderToStaticMarkup(createElement(TooltipProvider, null, createElement(VMPage, { locale, name: 'mac', driverID: '', state: 'running', macosMajor: null, host: {}, pending: [], currentAgentVersion: bundled, detail, }))) } export function renderLiveConnection(detailDenied, liveDenied) { return renderToStaticMarkup(createElement(TooltipProvider, null, createElement(ConnectionSection, { locale: 'en-US', vmKey: 'mac', state: 'running', pending: [], currentAgentVersion: 21, detail: { ssh_port: 0, guest_tools_drop_access_denied: detailDenied }, stats: { guest_tools_connected: true, guest_tools_drop_access_denied: liveDenied }, }))) } `) }) after(() => { delete globalThis.window }) const permissionCopy = [ ['en-US', 'File drop limited', 'File drops transfer via WebDAV. Enable Network Volumes for sh in macOS System Settings → Privacy & Security → Files and Folders'], ['zh-CN', '文件拖放受限', '拖放通过 WebDAV 传输文件,请在 macOS「系统设置 → 隐私与安全性 → 文件与文件夹」中开启 sh 的「网络宗卷」权限'], ] test('Guest Tools offers an update when a connected guest is older than the bundled agent', () => { for (const [installed, bundled, connected, needsUpdate] of [ [13, 14, true, true], [14, 14, true, false], [14, 15, true, true], [15, 15, true, false], [16, 15, true, false], [14, 15, false, false], [15, 14, true, false], [0, 14, true, false], [13, 14, false, false], ]) { const html = fixture.render({ installed, bundled, connected }) const context = `guest v${installed}, bundled v${bundled}, connected=${connected}` assert.equal(html.includes('>Update needed<'), needsUpdate, context) assert.equal(html.includes('Update…'), needsUpdate, context) } }) test('Guest Tools shows a localized idle sub-row only while connected and denied', () => { for (const [locale, title, guidance] of permissionCopy) { const html = fixture.render({ locale, denied: true }) const subRow = '
' + '' + `${title}${guidance.replaceAll('&', '&')}
` assert.ok(html.includes(subRow), locale) for (const [state, overrides] of [ ['allowed', { denied: false }], ['unprompted', { denied: undefined }], ['disabled', { denied: true, disabled: true }], ['disconnected', { denied: true, connected: false }], ]) { const hidden = fixture.render({ locale, ...overrides }) assert.ok(!hidden.includes('conn-drop-access') && !hidden.includes(title), `${locale}, ${state}`) } } }) test('Guest Tools shows the current drop permission even when detail is stale', () => { assert.ok(fixture.renderLiveConnection(false, true).includes('conn-drop-access')) assert.ok(!fixture.renderLiveConnection(true, false).includes('conn-drop-access')) }) test('A failed Network Volumes drop shows the localized permission toast', () => { for (const [locale, title, description] of permissionCopy) { const toasts = [] fixture.showHostDropAck({ status: 'failed', error: 'Network Volumes permission denied' }, locale, (toast) => toasts.push(toast), () => assert.fail(`${locale} used the generic drop failure`)) assert.deepEqual(toasts, [{ kind: 'error', title, description }], locale) } }) test('Other drop failures keep their details and successful or cancelled drops produce no error toast', () => { const failures = [] const push = () => assert.fail('unexpected permission toast') const fail = (...args) => failures.push(args) fixture.showHostDropAck({ status: 'failed', error: 'Placement failed' }, 'en-US', push, fail) assert.deepEqual(failures, [['Couldn’t drop into the VM', 'Placement failed']]) for (const status of ['placed', 'pasted', 'cancelled']) { fixture.showHostDropAck({ status, error: 'Network Volumes permission denied' }, 'en-US', push, fail) } assert.equal(failures.length, 1) })