60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
/**
|
||
* 13-responsive: 窗口管理器——可用区域、边界钳制、Dock 尺寸自适应
|
||
* 原测试: Playwright 4 视口截图 → 改为 WM composable 层测试
|
||
*/
|
||
import { describe, it, expect } from 'vitest'
|
||
import { wm } from '../../src/composables/useWM'
|
||
import { clamp } from '../../src/utils'
|
||
|
||
describe('13-responsive — 响应式窗口管理', () => {
|
||
// ===== usableRect =====
|
||
it('usableRect.y = 30(菜单栏高度)', () => {
|
||
expect(wm.usableRect().y).toBe(30)
|
||
})
|
||
|
||
it('usableRect 返回正值', () => {
|
||
const r = wm.usableRect()
|
||
expect(r.w).toBeGreaterThan(400)
|
||
expect(r.h).toBeGreaterThan(200)
|
||
})
|
||
|
||
// ===== 初始状态 =====
|
||
it('windows 初始为空', () => { expect(wm.windows.length).toBe(0) })
|
||
it('activeWin 初始为 null', () => { expect(wm.activeWin.value).toBeNull() })
|
||
it('windowsForApp 空', () => { expect(wm.windowsForApp('finder').length).toBe(0) })
|
||
it('anyVisible 返回 false', () => { expect(wm.anyVisible()).toBe(false) })
|
||
|
||
// ===== clampAll =====
|
||
it('clampAll 空窗口不报错', () => {
|
||
expect(() => wm.clampAll()).not.toThrow()
|
||
})
|
||
|
||
// ===== clamp 工具 =====
|
||
it('clamp 正确钳制坐标', () => {
|
||
expect(clamp(-10, 0, 100)).toBe(0)
|
||
expect(clamp(200, 0, 100)).toBe(100)
|
||
expect(clamp(50, 0, 100)).toBe(50)
|
||
})
|
||
|
||
// ===== 窗口不越界(静态验证) =====
|
||
it('窗口应在 usableRect 范围内', () => {
|
||
const u = wm.usableRect()
|
||
expect(u.x).toBeGreaterThanOrEqual(0)
|
||
expect(u.y).toBe(30)
|
||
expect(u.w).toBeLessThanOrEqual(window.innerWidth || 1024)
|
||
})
|
||
|
||
// ===== effDockSize 逻辑(通过 Sys 测试) =====
|
||
it('Dock 图标尺寸逻辑:窄屏缩小', () => {
|
||
// 模拟 effDockSize 逻辑
|
||
const effDockSize = (size: number, width: number) => {
|
||
if (width <= 640) return Math.min(size, 40)
|
||
if (width <= 1100) return Math.min(size, 48)
|
||
return size
|
||
}
|
||
expect(effDockSize(54, 500)).toBeLessThanOrEqual(40)
|
||
expect(effDockSize(54, 1000)).toBeLessThanOrEqual(48)
|
||
expect(effDockSize(54, 1440)).toBe(54)
|
||
})
|
||
})
|