drawerWidth.test.ts
2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { describe, expect, it } from 'vitest';
import {
DRAWER_COMPACT_W,
DRAWER_MAX_W,
DRAWER_MIN_W,
drawerWidthAt,
isDrawerCompact,
} from './drawerWidth';
/**
* 抽屉宽度是四张抽屉与地图共用的那一个数(避让、热力补偿都读它),
* 所以这三档边界钉在测试里:改了系数的人会立刻看到「笔记本上抽屉又变回半个屏」是哪一档崩了。
*/
describe('drawerWidthAt · 三档夹住', () => {
it('宽屏封顶:1920 与 2560 都只给上限,不给「半个屏幕」', () => {
expect(drawerWidthAt(1920)).toBe(DRAWER_MAX_W);
expect(drawerWidthAt(2560)).toBe(DRAWER_MAX_W);
});
it('笔记本走比例那一档:1440 比原来写死的 736 窄,1280 更窄', () => {
expect(drawerWidthAt(1440)).toBeLessThan(736);
expect(drawerWidthAt(1440)).toBeLessThanOrEqual(DRAWER_MAX_W);
expect(drawerWidthAt(1280)).toBeLessThan(drawerWidthAt(1440));
});
it('小屏托底:再窄也不低于读得动一张表的那个数', () => {
// 933 以下 42% 已经掉到 392 之下,由下限托住
expect(drawerWidthAt(1024)).toBe(430);
expect(drawerWidthAt(880)).toBe(DRAWER_MIN_W);
});
it('视口比下限还窄时跟着视口走,不把抽屉顶出屏幕', () => {
expect(drawerWidthAt(420)).toBeLessThan(420);
expect(drawerWidthAt(320)).toBeLessThanOrEqual(320 - 24);
});
it('单调:窗口越宽抽屉不越窄', () => {
let prev = 0;
for (let vw = 320; vw <= 2560; vw += 8) {
const w = drawerWidthAt(vw);
expect(w).toBeGreaterThanOrEqual(prev);
prev = w;
}
});
});
describe('isDrawerCompact · 紧凑档的分界', () => {
it('窄于分界就换紧凑排版,宽于分界保持完整列', () => {
expect(isDrawerCompact(DRAWER_COMPACT_W - 1)).toBe(true);
expect(isDrawerCompact(DRAWER_COMPACT_W)).toBe(false);
// 下限那一档必然走紧凑:列的取舍就是为它准备的
expect(isDrawerCompact(drawerWidthAt(1024))).toBe(true);
// 上限那一档必然是完整排版
expect(isDrawerCompact(drawerWidthAt(1920))).toBe(false);
});
});