Files
MyGoNavi/frontend/src/utils/windowStateUi.test.ts
Syngnat e4a8c53079 🐛 fix(window): 修复 Windows 恢复窗口后字体模糊
- Windows 从任务栏恢复窗口时直接触发 WebView2 zoom reset
- restore 场景不再依赖 viewport ratio drift 判断
- 覆盖最大化和非最大化窗口的恢复修复路径
- 保留最大化窗口零动画修复,避免二次最大化抖动
- 补充窗口恢复策略和 App 自动修复路径测试
2026-06-02 14:04:00 +08:00

49 lines
2.3 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 when a minimized taskbar window is restored with viewport drift', () => {
expect(shouldApplyWindowsScaleFix('restore', true)).toBe(true);
expect(shouldApplyWindowsScaleFix('restore', false)).toBe(false);
// 关键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');
});
});