intentActions.test.ts
3.04 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
81
82
83
84
85
86
87
88
89
90
91
92
/**
* 阶段 3 的等价性契约:四个 action 从「改 store 里的 seq」换成「改业务字段 + 发意图」。
*
* 原来 seq 与业务字段在同一次 set 里落地;现在分成 set + dispatch 两步,
* 因此要钉住两件事:
* 1. 业务字段的连带清空没丢(spotlight / selection / members / drawerOpen / analysisError);
* 2. 每次调用都发一次意图,重复点同一行也能重新执行(原来靠 seq += 1)。
*/
import { afterEach, describe, expect, it } from 'vitest';
import { useHeatmapStore } from './useHeatmapStore';
import type { CasePin, SpotlightOpen, SpotlightView } from './useHeatmapStore';
import {
getAnalysisRerunVersion,
getCaseFocusVersion,
getHotspotFocusVersion,
getSpotlightOpenVersion,
resetIntentsForTests,
} from './intentBus';
const reset = () => {
useHeatmapStore.setState({
activeHotspot: null,
casePin: null,
spotlight: null,
analysisError: '上次的失败',
selection: null,
members: null,
drawerOpen: true,
});
resetIntentsForTests();
};
afterEach(reset);
describe('store action 的意图等价性', () => {
it('pickHotspot:清高亮 + 收聚焦 + 发一次黑点定位意图', () => {
const view: SpotlightView = {
kind: 'districts',
source: '测试聚焦',
cellM: 200,
units: [],
base: useHeatmapStore.getState().filter,
active: null,
note: null,
};
useHeatmapStore.setState({ spotlight: view });
useHeatmapStore.getState().pickHotspot(7);
expect(useHeatmapStore.getState().activeHotspot).toBe(7);
expect(useHeatmapStore.getState().spotlight).toBeNull();
expect(getHotspotFocusVersion()).toBe(1);
});
it('rerunAnalysis:清失败原文 + 发一次重算意图', () => {
useHeatmapStore.getState().rerunAnalysis();
expect(useHeatmapStore.getState().analysisError).toBeNull();
expect(getAnalysisRerunVersion()).toBe(1);
});
it('focusCasePoint:挪图钉 + 收聚焦 + 发一次案件定位意图', () => {
const pin: CasePin = { lng: 114.06, lat: 22.54, address: '测试地址' };
useHeatmapStore.getState().focusCasePoint(pin);
expect(useHeatmapStore.getState().casePin).toEqual(pin);
expect(useHeatmapStore.getState().spotlight).toBeNull();
expect(getCaseFocusVersion()).toBe(1);
});
it('openSpotlight:按当前筛选快照 + 收抽屉 + 发一次聚焦意图', () => {
const view: SpotlightOpen = {
kind: 'districts',
source: '测试聚焦',
cellM: 200,
units: [],
};
useHeatmapStore.getState().openSpotlight(view);
const st = useHeatmapStore.getState();
expect(st.spotlight?.base).toEqual(st.filter);
expect(st.selection).toBeNull();
expect(st.members).toBeNull();
expect(st.drawerOpen).toBe(false);
expect(getSpotlightOpenVersion()).toBe(1);
});
it('连点同一行两次:版本 +2,与原来 seq 自增逐次对应', () => {
useHeatmapStore.getState().pickHotspot(3);
useHeatmapStore.getState().pickHotspot(3);
expect(getHotspotFocusVersion()).toBe(2);
});
});