import assert from 'node:assert/strict' import test from 'node:test' import { loadTestModule } from './load-test-module.mjs' const { windowDisplayPresets, fullscreenDisplayPresets, recommendedDisplayPresets, recommendedResolution, hostDisplayAdvice, canKeepDisplayPreset } = await loadTestModule(`export * from './lib/format'`) function profile(width, height) { return { primary_display: { width, height, scale_pct: 125 }, display_presets: [ { resolution: '1920x1080', label: '1920 × 1080', hidpi: false, recommended: true }, { resolution: '1600x900', label: '1600 × 900', hidpi: false }, ], } } for (const [width, height] of [[2560, 1440], [2560, 1600]]) { test(`fixed-mode runtime offers native ${width}x${height} in a window without changing fit recommendations`, () => { const host = profile(width, height) const before = structuredClone(host) const fit = recommendedDisplayPresets(host) assert.strictEqual(windowDisplayPresets(host, false), fit) const options = windowDisplayPresets(host, true) assert.deepEqual(options.slice(0, fit.length), fit) assert.deepEqual(options.at(-1), { resolution: `${width}x${height}`, label: `${width} × ${height}`, hidpi: false, scaleToFit: true, }) assert.equal(options.filter((p) => p.recommended).length, 1) assert.equal(recommendedResolution(host), '1920x1080') assert.deepEqual(host, before) }) } test('an existing native preset is not duplicated or relabeled', () => { const host = profile(2560, 1440) host.display_presets.push({ resolution: '2560x1440', label: '2560 × 1440', hidpi: false }) assert.strictEqual(windowDisplayPresets(host, true), host.display_presets) }) test('missing or invalid target geometry keeps fit-only presets', () => { for (const display of [undefined, { width: 0, height: 1440 }, { width: 2560, height: -1 }, { width: 1920, height: 1080 }]) { const host = { ...profile(2560, 1440), primary_display: display } assert.strictEqual(windowDisplayPresets(host, true), host.display_presets) } }) test('native guest HiDPI metadata is preserved when scaling into a window', () => { const host = { ...profile(3840, 2160), fullscreen_hidpi: true } const preset = windowDisplayPresets(host, true).at(-1) assert.equal(preset.hidpi, true) assert.equal(preset.scaleToFit, true) }) test('window HiDPI presets suppress only the contradictory fullscreen advice', () => { const host = { ...profile(2560, 1600), fullscreen_hidpi: true, hidpi_advice: 'fullscreen' } const tr = (key) => key assert.equal(hostDisplayAdvice(host, tr, windowDisplayPresets(host, false)), 'hidpiTipFullscreen') assert.equal(hostDisplayAdvice(host, tr, windowDisplayPresets(host, true)), undefined) assert.equal(hostDisplayAdvice({ ...host, hidpi_advice: 'scale' }, tr, windowDisplayPresets(host, true)), 'hidpiTipScale') assert.equal(hostDisplayAdvice({ ...host, hidpi_advice: 'unavailable' }, tr, windowDisplayPresets(host, true)), 'hidpiTipUnavailable') }) test('fullscreen round trips return to fit presets instead of implicitly opting into scaling', () => { for (const fixedModeSupported of [false, true]) { const host = profile(2560, 1440) const windows = windowDisplayPresets(host, fixedModeSupported) const full = fullscreenDisplayPresets(host) const switchMode = (resolution, borderless) => { const list = borderless ? full : windows return list.some((p) => canKeepDisplayPreset(p, resolution, borderless)) ? resolution : list.find((p) => p.recommended)?.resolution ?? list[0].resolution } const native = switchMode('1920x1080', true) assert.equal(native, '2560x1440') assert.equal(switchMode(native, false), '1920x1080') assert.equal(switchMode('1600x900', false), '1600x900') } const native = windowDisplayPresets(profile(2560, 1440), true).at(-1) assert.equal(native.scaleToFit, true) // Still available for explicit window-mode selection. assert.equal(canKeepDisplayPreset(native, '2560 × 1440', true), true) assert.equal(canKeepDisplayPreset(native, '2560 × 1440', false), false) }) test('new scaled window presets stay within the supported 5K bounds', () => { for (const [width, height] of [[6016, 3384], [7680, 2160], [5120, 3202]]) { const host = profile(width, height) assert.strictEqual(windowDisplayPresets(host, true), host.display_presets) } assert.equal(windowDisplayPresets(profile(5120, 3200), true).at(-1).resolution, '5120x3200') }) test('the effective target profile determines the added window resolution', () => { const primary = profile(3840, 2160) const target = { ...primary, primary_display: { width: 2560, height: 1600, scale_pct: 150 } } assert.equal(windowDisplayPresets(target, true).at(-1).resolution, '2560x1600') assert.equal(windowDisplayPresets(primary, true).at(-1).resolution, '3840x2160') })