Files
SupplierSystem/server/tests/dashboardCustomerMultiSelect.test.ts
Ubuntu 298c1e5e5a feat(数据看板): 顶部客户多选,预测复用,成本卡按客户过滤 + 表格自适应
- 顶部 SearchableMultiSelect,URL customer_code 逗号串;客户变化后台刷新不卸载筛选框
- 需求预测移除重复客户下拉,使用顶部 customerCodes
- 成本/毛利/净利卡接客户过滤;无单号期间成本按当窗客户数分摊
- 需求预测表格 100% 自适应宽度,百分比列宽
- 补 dashboard 契约/helper 测试
2026-10-25 15:53:22 +08:00

47 lines
1.7 KiB
TypeScript

import { readFileSync } from 'node:fs';
import { describe, expect, it } from 'vitest';
const service = readFileSync(
new URL('../src/services/dashboardService.ts', import.meta.url),
'utf8'
);
const route = readFileSync(new URL('../src/routes/dashboard.ts', import.meta.url), 'utf8');
describe('dashboard customer_codes 后端契约', () => {
it('route 解析 customer_codes,兼容 customer_code', () => {
expect(route).toContain('req.query.customer_codes');
expect(route).toContain('req.query.customer_code');
expect(route).toContain('customerCodes');
});
it('service 把客户码用于期间/环比/待处理/待配送/逾期/近期/客户画像/趋势', () => {
expect(service).toContain('normalizeCustomerCodesFilter(customerCodesRaw)');
for (const flag of [
'periodCustomer',
'prevCustomer',
'pendingCustomer',
'pendingDeliveryCustomer',
'overdueCustomer',
'recentCustomer',
'customerOrdersCustomer',
'customerProfilesCustomer',
'trendRevenueCustomer',
]) {
expect(service, flag).toContain(flag);
}
});
it('无客户维度的库存/临期仍保持原查询(不被误加订单客户条件)', () => {
const lowStockBlock = service.slice(
service.indexOf('FROM inventory i'),
service.indexOf('FROM inventory i') + 700
);
expect(lowStockBlock).not.toContain('customer_code');
const expiringBlock = service.slice(
service.indexOf('COUNT(*) FILTER (', service.indexOf('临期 / 已过期')),
service.indexOf('COUNT(*) FILTER (', service.indexOf('临期 / 已过期')) + 900
);
expect(expiringBlock).not.toContain('customer_code');
});
});