clusterDrawn.test.ts
1.48 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
import { describe, expect, it } from 'vitest';
import { isClusterDrawn } from './useHeatmapStore';
/**
* 方格数字层的可见性判据。
*
* 单测要钉住的是「降噪时收起、退出后原样放回」——用户 never 碰过图层开关,
* 不能因为进出了一趟黑点降噪就丢掉自己的设置。
*/
function state(patch: Partial<Parameters<typeof isClusterDrawn>[0]> = {}) {
return {
layerVisible: { cluster: true },
analysisOn: false,
spotlight: null,
casePin: null,
...patch,
};
}
describe('isClusterDrawn', () => {
it('常态显示方格数字', () => {
expect(isClusterDrawn(state())).toBe(true);
});
it('黑点降噪开启时收起方格数字,热力和黑点照旧', () => {
expect(isClusterDrawn(state({ analysisOn: true }))).toBe(false);
});
it('退出降噪后按用户自己的图层设置恢复,不被这次进出改掉', () => {
const on = state({ analysisOn: true });
expect(isClusterDrawn(on)).toBe(false);
expect(isClusterDrawn({ ...on, analysisOn: false })).toBe(true);
});
it('用户主动关掉方格数字后,即使没降噪也不画', () => {
expect(
isClusterDrawn(state({ layerVisible: { cluster: false } })),
).toBe(false);
});
it('铺开聚焦与清单定位仍按原判据让位', () => {
expect(isClusterDrawn(state({ spotlight: { kind: 'districts' } }))).toBe(false);
expect(isClusterDrawn(state({ casePin: { lng: 114, lat: 22 } }))).toBe(false);
});
});