Files
SupplierSystem/server/tests/mpPickingScopeSelect.test.ts
T
Ubuntu 73228d2eac
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
fix(红队): 收口单位伪造、BOM jsonb、成本口径与出库兜底
单位取库内/冻结看订单单位;BOM JSON.stringify;单位不一致成本按库存量;库存0不写全额标记;补货释放清新列;人工追价默认售价。
2026-11-04 13:30:24 +08:00

101 lines
4.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { readFileSync } from 'fs';
import { describe, expect, it } from 'vitest';
const wxml = readFileSync(
new URL('../../miniprogram/components/picking-panel/index.wxml', import.meta.url),
'utf8'
);
const js = readFileSync(
new URL('../../miniprogram/components/picking-panel/index.js', import.meta.url),
'utf8'
);
describe('小程序分拣范围选择框', () => {
it('页内点击选范围:按订单/分类/商品都走选择框;完成组不占位', () => {
expect(wxml).not.toContain('scroll-x class="task-tabs"');
expect(wxml).toContain('toggleScopeMenu');
expect(wxml).toContain('scope-menu');
expect(wxml).toContain('wx:if="{{scopeGroups.length}}"');
expect(wxml).not.toContain('!skuCatalogMode');
expect(js).toContain('function groupStillOpen');
expect(js).toContain('onScopeOptionTap');
expect(js).toContain('scopeMenuOpen');
expect(js).toContain("if (type === 'category') return String(task.scope_label");
expect(js).toContain("if (type === 'sku') return String(task.scope_standard_label");
expect(js).toContain('this.selectGroupByKey(activeGroupKey)');
expect(js).not.toContain('this.applyPickingDayView()');
});
it('日期轴仍在;行内「打印」已从界面移除(2026-10-15 开发者:只取消界面、代码保留)', () => {
expect(wxml).toContain('date-axis');
expect(js).toContain('confirmAllPicks');
// 2026-10-13 曾加回行内「打印」(BLE 热敏直连,不进旧 print_jobs / 称重终端链路);
// 2026-10-15 开发者要求「打印按钮取消了,只是界面的取消而已」⇒ **wxml 不再有该按钮**,
// 但实现代码(`printCurrentPick` / `pickingLabelPrint`)仍保留,随时可把那段 wxml 加回。
expect(wxml).not.toContain('printCurrentPick');
expect(wxml).not.toContain('btn-print-row');
expect(js).toContain('printCurrentPick');
expect(js).toContain('pickingLabelPrint');
expect(js).not.toContain('printPickLabels');
expect(js).not.toContain('fetchPickingWeighDevices');
expect(js).not.toContain('createPickingPrintJobs');
});
/**
* 2026-11-05 新增「按区域」拣货模式,且是**未配置分公司的兜底默认**(`pickingConfigService`):
* 一张单的明细跨两个区域 ⇒ 后端 `createZoneScopeTasks` 拆出两张 `scope_type='zone'` 任务。
* `taskGroupKey` 早就认 zone,但 `taskPickerLabel` 漏了 zone 分支 ⇒ 两个组都回落到订单号,
* 再被同名补丁拼成 `ORD_X · ORD_X` —— 分拣主流程的首要导航控件里两个区域**完全同名**,无法区分。
*/
it('区域单(scope_type=zone)在选择框里显示区域名,不回落成订单号', () => {
const { taskPickerLabel, buildScopeGroups } = loadScopeFns();
const zoneTask = (scopeKey: string, label: string) => ({
pick_code: `PK_${scopeKey}`,
order_code: 'ORD_API_20261105_BR001_0001',
order_code_short: 'ORD_X',
scope_type: 'zone',
scope_key: scopeKey,
scope_label: label,
});
expect(taskPickerLabel(zoneTask('冷库A', '冷库A'))).toBe('冷库A');
expect(taskPickerLabel({ ...zoneTask('未设区域', '') })).toBe('未设区域');
const groups = buildScopeGroups([
zoneTask('冷库A', '冷库A'),
zoneTask('冷库B', '冷库B'),
]);
expect(groups.map((g) => g.label)).toEqual(['冷库A', '冷库B']);
// 订单模式不受影响(仍显示单号)
expect(
taskPickerLabel({ order_code: 'ORD_X', order_code_short: 'ORD_X', scope_type: 'order' })
).toBe('ORD_X');
});
});
/**
* 从 `index.js` 源码里抽出纯函数执行(小程序组件文件不是可 import 的模块,
* 但这两个函数是纯函数 —— 真跑源码比字符串断言更能钉住行为)。
*/
function loadScopeFns(): {
taskPickerLabel: (task: Record<string, unknown>) => string;
buildScopeGroups: (tasks: Array<Record<string, unknown>>) => Array<{ label: string }>;
} {
const extract = (name: string): string => {
const start = js.indexOf(`function ${name}(`);
if (start < 0) throw new Error(`源码缺少函数 ${name}`);
let depth = 0;
for (let i = js.indexOf('{', start); i < js.length; i += 1) {
if (js[i] === '{') depth += 1;
else if (js[i] === '}') {
depth -= 1;
if (depth === 0) return js.slice(start, i + 1);
}
}
throw new Error(`函数 ${name} 括号不闭合`);
};
const source = ['taskScopeType', 'taskGroupKey', 'taskPickerLabel', 'buildScopeGroups']
.map(extract)
.join('\n');
return new Function(`${source}\nreturn { taskPickerLabel, buildScopeGroups };`)();
}