feat(projects): 增加意见反馈
This commit is contained in:
48
tests/feedback-stat-normalization.test.ts
Normal file
48
tests/feedback-stat-normalization.test.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, it } from 'node:test';
|
||||
import { normalizeFeedbackStat } from '../src/service/api/feedback-normalize';
|
||||
|
||||
describe('normalizeFeedbackStat', () => {
|
||||
it('maps backend type/status count arrays to code-keyed records', () => {
|
||||
const result = normalizeFeedbackStat({
|
||||
total: 128,
|
||||
typeCounts: [
|
||||
{ type: 1, count: 52 },
|
||||
{ type: 2, count: 31 },
|
||||
{ type: 3, count: 45 }
|
||||
],
|
||||
statusCounts: [
|
||||
{ status: 1, count: 40 },
|
||||
{ status: 2, count: 33 },
|
||||
{ status: 3, count: 50 },
|
||||
{ status: 4, count: 5 }
|
||||
]
|
||||
});
|
||||
|
||||
assert.deepEqual(result, {
|
||||
total: 128,
|
||||
typeCounts: {
|
||||
'1': 52,
|
||||
'2': 31,
|
||||
'3': 45
|
||||
},
|
||||
statusCounts: {
|
||||
'1': 40,
|
||||
'2': 33,
|
||||
'3': 50,
|
||||
'4': 5
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps zero-count dictionary codes visible to the facet panel', () => {
|
||||
const result = normalizeFeedbackStat({
|
||||
total: 0,
|
||||
typeCounts: [{ type: '1', count: 0 }],
|
||||
statusCounts: [{ status: '4', count: 0 }]
|
||||
});
|
||||
|
||||
assert.deepEqual(result.typeCounts, { '1': 0 });
|
||||
assert.deepEqual(result.statusCounts, { '4': 0 });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user