Files
MyGoNavi/frontend/src/utils/windowStateUi.test.ts
Syngnat 77a306beb2 🐛 fix(window): 修复外接显示器恢复后字体模糊
- 恢复策略:Windows 最小化恢复时不再依赖 viewport drift 才触发修复
- 渲染刷新:普通窗口执行 1px 尺寸 nudge,强制 WebView2/DWM 重建渲染 surface
- 体验保护:最大化窗口继续保留 zoom reset + resize,避免可见重复最大化动画
- 测试覆盖:补充 restore 无 drift 场景与自动修复路径断言
Refs #495
2026-06-12 15:58:30 +08:00

51 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from 'vitest';
import {
resolveTitleBarToggleIconKey,
resolveWindowsScaleCheckDelayMs,
shouldApplyWindowsScaleFix,
shouldResetWebViewZoomForScaleFix,
shouldToggleMaximisedWindowForScaleFix,
} from './windowStateUi';
describe('windowStateUi', () => {
it('does not re-toggle a maximized window on activation when focus returns', () => {
expect(shouldToggleMaximisedWindowForScaleFix('activation', true)).toBe(false);
});
it('only applies the Windows scale fix on real ratio drift', () => {
expect(shouldApplyWindowsScaleFix('activation', true)).toBe(false);
expect(shouldApplyWindowsScaleFix('ratio-change', true)).toBe(true);
});
it('applies the Windows scale fix whenever a minimized taskbar window is restored', () => {
expect(shouldApplyWindowsScaleFix('restore', true)).toBe(true);
// 外接显示器恢复后的 WebView2/DWM backing surface 可能被旧 DPI 缩放,
// 但不一定表现为 viewport ratio driftrestore 仍要触发 1px 轻量重绘。
expect(shouldApplyWindowsScaleFix('restore', false)).toBe(true);
// 关键restore 场景刻意不再触发 maximised 窗口的 toggle —— Unmaximise → Maximise 在
// 任务栏恢复的真实交互里会被用户肉眼看见为"重复最大化"动画,比偶发字体变大更糟。
// 这是 9848b8b2 已有的取舍,禁止再次被"修复"成 true。
expect(shouldToggleMaximisedWindowForScaleFix('restore', true)).toBe(false);
});
it('calls the backend WebView2 zoom reset whenever a minimized window is restored', () => {
expect(shouldResetWebViewZoomForScaleFix('restore', true)).toBe(true);
// 字体模糊/DirectWrite 度量缓存异常不一定表现为 viewport ratio drift
// 因此任务栏恢复场景必须直接走零动画 WebView2 zoom reset。
expect(shouldResetWebViewZoomForScaleFix('restore', false)).toBe(true);
expect(shouldResetWebViewZoomForScaleFix('activation', true)).toBe(false);
expect(shouldResetWebViewZoomForScaleFix('ratio-change', true)).toBe(false);
});
it('debounces resize-triggered Windows scale checks until window transitions settle', () => {
expect(resolveWindowsScaleCheckDelayMs('resize')).toBeGreaterThan(0);
expect(resolveWindowsScaleCheckDelayMs('focus')).toBe(0);
expect(resolveWindowsScaleCheckDelayMs('poll')).toBe(0);
});
it('switches the titlebar toggle icon to restore when the window is maximized', () => {
expect(resolveTitleBarToggleIconKey('maximized')).toBe('restore');
});
});