spotlightView.test.ts
3.16 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
import { describe, expect, it } from 'vitest';
import { attrSpotlight } from './spotlightView';
import type { MetaFile, StatsResult } from '../aggregate/types';
/**
* 车辆属性那一屏的组装。
*
* 钉的是三条最容易悄悄错掉的事:
* 1. 屏上那一块的起数必须等于构成条上那一段(同一份 counts,不能现算);
* 2. 点屏上那一块开出来的清单,切的就是这一类(where 里的白名单);
* 3. 「未填」那一类走的是未填起数,不是榜上下标 0 的那一项。
*/
function meta(): MetaFile {
return {
dict: {
districts: [],
streets: [],
roads: [],
useNatures: ['', '非营业', '营业'],
newEnergy: ['', '否', '是'],
vehicleClasses: ['', '客车', '货车'],
},
} as unknown as MetaFile;
}
function stats(): StatsResult {
return {
matched: 1000,
useNatureCounts: [
[1, 600],
[2, 300],
],
useNatureUnresolved: 100,
newEnergyCounts: [[1, 500]],
newEnergyUnresolved: 0,
vehicleClassCounts: [[1, 700]],
vehicleClassUnresolved: 0,
} as unknown as StatsResult;
}
describe('attrSpotlight', () => {
it('铺点中的那一类,起数与构成条同源', () => {
const view = attrSpotlight('useNature', 1, stats(), meta());
expect(view).not.toBeNull();
expect(view?.kind).toBe('attrs');
expect(view?.attrDim).toBe('useNature');
expect(view?.units).toHaveLength(1);
expect(view?.units[0].label).toBe('非营业');
expect(view?.units[0].count).toBe(600);
expect(view?.units[0].roster.where).toEqual({ useNatures: [1] });
// 屏上只有点中的那一类:与街道那一屏不同,这里不带前几名做参照(理由见函数上的注释)
expect(view?.active).toBe(0);
});
it('「未填」那一类念未填起数,切的是下标 0', () => {
const view = attrSpotlight('useNature', 0, stats(), meta());
expect(view?.units[0].label).toBe('未填');
expect(view?.units[0].count).toBe(100);
expect(view?.units[0].roster.where).toEqual({ useNatures: [0] });
});
it('这一类 0 起时不铺(入口据此不做反应,而不是弹一句没有数据)', () => {
expect(attrSpotlight('vehicleClass', 2, stats(), meta())).toBeNull();
});
it('另外两维各走各的白名单', () => {
const ne = attrSpotlight('newEnergy', 1, stats(), meta());
expect(ne?.attrDim).toBe('newEnergy');
expect(ne?.units[0].roster.where).toEqual({ newEnergy: [1] });
const vc = attrSpotlight('vehicleClass', 1, stats(), meta());
expect(vc?.units[0].roster.where).toEqual({ vehicleClasses: [1] });
});
it('「是否新能源」念全:是 → 新能源、否 → 非新能源,与组合、面板同一套念法', () => {
// 字典里存的是源表原值「否 / 是」,牌子上不能只写一个「否」——
// 那一屏上没有人告诉读的人这一维在问什么
const s = stats();
s.newEnergyCounts = [
[1, 500],
[2, 300],
];
expect(attrSpotlight('newEnergy', 1, s, meta())?.units[0].label).toBe('非新能源');
expect(attrSpotlight('newEnergy', 2, s, meta())?.units[0].label).toBe('新能源');
});
});