bucketCard.test.ts
3.78 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
93
94
95
96
97
98
/**
* 屏上那张「点了这一格」的浮动桶卡,与右缘抽屉之间的进退关系。
*
* 两件事是一起改的,所以守在一起:
* 1. 点「查看全部」进抽屉之后,卡要收掉 —— 同一份明细不该一份浮在屏上、一份摊在抽屉里;
* 但 **selection 不能清**,抽屉里那张表正是拿它渲染的。
* 2. 从「查看全部 · 营运区分」里点一行只是**收窄地图**,抽屉要留着,
* 让人接着点第二类;卡则该收 —— 它钉着的那一格已经不是同一批数了。
*/
import { beforeEach, describe, expect, it } from 'vitest';
import { useHeatmapStore, type Selection } from './useHeatmapStore';
const hit: Selection = {
gx: 12,
gy: 34,
count: 57,
lng: 114.05,
lat: 22.54,
dLng: 0.01,
dLat: 0.01,
screenX: 640,
screenY: 380,
key: '12:34',
};
const reset = () =>
useHeatmapStore.setState({
selection: null,
members: null,
cardOpen: false,
drawerOpen: false,
statsBoard: null,
roster: null,
mapScope: null,
});
beforeEach(reset);
describe('桶卡与抽屉', () => {
it('选中一格就浮出卡;清空选中就收起', () => {
useHeatmapStore.getState().select(hit);
expect(useHeatmapStore.getState().cardOpen).toBe(true);
useHeatmapStore.getState().select(null);
expect(useHeatmapStore.getState().cardOpen).toBe(false);
});
it('「查看全部」进抽屉:卡收掉,但选中项留着(抽屉那张表要用它)', () => {
useHeatmapStore.getState().select(hit);
useHeatmapStore.getState().setDrawerOpen(true);
const s = useHeatmapStore.getState();
expect(s.drawerOpen).toBe(true);
expect(s.cardOpen).toBe(false);
// 关键:selection 留着。清掉的话抽屉会拿不到格心坐标与那一格的起数
expect(s.selection).toEqual(hit);
});
it('收窄地图只收卡,不动抽屉 —— 从营运区分里连着点几行的那个用法', () => {
useHeatmapStore.getState().openStatsBoard('operating');
// 库里还挂着一张浮卡(例如刚才点过屏上某一格,随后又打开了榜单)
useHeatmapStore.setState({ selection: hit, cardOpen: true });
useHeatmapStore.getState().setMapScope({ label: '营运区分 · 网约车', operatingSegments: [3] });
useHeatmapStore.getState().hideBucketCard();
const s = useHeatmapStore.getState();
expect(s.cardOpen).toBe(false);
expect(s.statsBoard).toBe('operating');
expect(s.selection).toEqual(hit);
});
it('换收窄不清榜单抽屉(原先的实现是在 MapStage 里一律 select(null),抽屉跟着没了)', () => {
useHeatmapStore.getState().openStatsBoard('operating');
useHeatmapStore.getState().setMapScope({ label: '营运区分 · 网约车', operatingSegments: [3] });
useHeatmapStore
.getState()
.setMapScope({ label: '营运区分 · 出租/租赁', operatingSegments: [2] });
expect(useHeatmapStore.getState().statsBoard).toBe('operating');
});
it('打开任意一张右缘抽屉都不会与卡同屏:三张抽屉 + 卡只能出现一个', () => {
useHeatmapStore.getState().select(hit);
useHeatmapStore.getState().openStatsBoard('districts');
expect(useHeatmapStore.getState().cardOpen).toBe(false);
useHeatmapStore.getState().select(hit);
useHeatmapStore.getState().openRoster({ source: '测试' });
expect(useHeatmapStore.getState().cardOpen).toBe(false);
});
it('清空选中仍然顺手收掉两张抽屉(原有口径,别在改卡的时候弄丢)', () => {
useHeatmapStore.getState().openStatsBoard('streets');
useHeatmapStore.getState().setDrawerOpen(true);
useHeatmapStore.getState().select(null);
const s = useHeatmapStore.getState();
expect(s.drawerOpen).toBe(false);
expect(s.statsBoard).toBeNull();
});
});