transitions.test.ts
2.76 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* 视图状态转换的等价性回归(阶段 1b)。
*
* 每个断言都逐字段照抄抽取前 action 的 set 参数,不是照新的实现写。
* 抽 3 处的判据是「同一个连带在两处写过」——railTabSwitchState 的注释
* 明说与 setAnalysisEnabled(true) 同一套;setMapScope 的 casePin 无条件清
* 也是与原实现一致,不能"顺手优化"成只在有值时清。
*/
import { describe, expect, it } from 'vitest';
import type { MapScope } from './useHeatmapStore';
import {
analysisSwitchState,
mapScopeSwitchState,
railTabSwitchState,
} from './transitions';
describe('railTabSwitchState(原 store 492-514)', () => {
it('切到 analysis:开关开、清聚焦/选中/收起态/临时收窄', () => {
expect(railTabSwitchState('analysis')).toEqual({
analysisOn: true,
activeHotspot: null,
dockHidden: false,
spotlight: null,
mapScope: null,
});
});
it('切到 stats/filter:关降噪、清收窄/聚焦/定位针', () => {
const expected = { analysisOn: false, mapScope: null, spotlight: null, casePin: null };
expect(railTabSwitchState('stats')).toEqual(expected);
expect(railTabSwitchState('filter')).toEqual(expected);
});
it('收起面板(null)不动任何开关', () => {
expect(railTabSwitchState(null)).toEqual({});
});
});
describe('analysisSwitchState(原 setAnalysisEnabled 1101-1107)', () => {
it('开启:清高亮与清单收起态,并收回一屏聚焦', () => {
expect(analysisSwitchState(true)).toEqual({
analysisOn: true,
activeHotspot: null,
dockHidden: false,
spotlight: null,
});
});
it('关闭:清高亮与清单收起态,但不动 spotlight', () => {
expect(analysisSwitchState(false)).toEqual({
analysisOn: false,
activeHotspot: null,
dockHidden: false,
});
});
it('与 railTabSwitchState(analysis) 的差异仅在一处:后者还清 mapScope/casePin', () => {
const a = analysisSwitchState(true);
const r = railTabSwitchState('analysis');
expect(r).toMatchObject({ analysisOn: a.analysisOn, activeHotspot: null, spotlight: null });
expect(r).toHaveProperty('mapScope', null);
expect(a).not.toHaveProperty('mapScope');
});
});
describe('mapScopeSwitchState(原 setMapScope 1345-1353)', () => {
const scope: MapScope = { label: '营运车', vehicleClasses: [1, 2] };
it('设收窄:与聚焦互斥、清定位针', () => {
expect(mapScopeSwitchState(scope)).toEqual({
mapScope: scope,
spotlight: null,
casePin: null,
});
});
it('传 null 恢复画全部:仍清定位针(与原实现一致,不是顺手优化)', () => {
expect(mapScopeSwitchState(null)).toEqual({ mapScope: null, casePin: null });
});
});