原改动人:雨天 <oncwnuHbbvAwYZMdPF78PsWNPadI@git.weixin.qq.com> 代为提交:Lead 会话(本 commit 内容与该会话工作区逐字节一致,未做任何修改), 目的是不让在研成果丢失、并让工作树回到干净可部署状态。 提交前由 Lead 实跑验证: - 前端 npx tsc --noEmit 0 错误;后端 server npx tsc --noEmit 0 错误 - 本批新增的 7 个测试 54/54 通过;Lead 侧契约测试(散客录单/文案/成本列)42/42 通过 - bash tools/design-consistency/run-all.sh --verify:通过 8 / 未通过 1(check-ai-cost,既有红)/ 未执行 1(verify-facts,本地库不可连)—— 与基线一致 新增能力(各含 docs/design 设计文): - 独立进货不得有配送任务:生成侧兜底 + 补建候选 + 查询侧三道防线(实测 5 张独立进货单里 4 张有僵尸 delivery_tasks) - 主系统追加行零价闸门尊重其已声明的 allowUnpriced(否则整批分配行静默丢失) - 库存抵扣为 0 的原因可见(不再静默,原因判定与抵扣量同源并落到日志与「库存抵扣」入口) - 退货/删单跟随改独立 2 分钟周期(MAIN_SYSTEM_RETURN_FOLLOW_SEC,置 0 退回旧行为) - 加工领料可用本单自己的预留(放行必须与本单预留消费成对,避免短送与同一批算两次) - 出库拍照预览、主系统实收 / SKU 映射 / 单位变更 inbox 等配套 同一批包含对已废弃旧方案的回滚(design doc 与 README 索引行一并移除): - 独立进货建客户档案(方案甲)→ 回到哨兵方案;随之删除 migrations/20261044_independent_inbound_customer.sql - 分类新建去重(同名复用已有) - 分拣标签纸张尺寸预设 / 分拣标签可选客户名与区域 未包含:src/pages/orders/OrderManagementPage.tsx(0 字节空文件,疑似误建,既未提交也未删除)
100 lines
4.4 KiB
TypeScript
100 lines
4.4 KiB
TypeScript
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_label");
|
||
expect(js).toContain('this.selectGroupByKey(activeGroupKey)');
|
||
expect(js).not.toContain('this.applyPickingDayView()');
|
||
});
|
||
|
||
it('日期轴仍在;小程序打印走 BLE 新通道(2026-10-13 起)', () => {
|
||
expect(wxml).toContain('date-axis');
|
||
expect(js).toContain('confirmAllPicks');
|
||
// 2026-10-13 开发者要求重新加回分拣「打印」:走 **BLE 热敏直连**(utils/pickingLabelPrint),
|
||
// 仍**不走**旧 print_jobs / 称重终端链路(无 printPickLabels / 设备下发)。
|
||
expect(wxml).toContain('printCurrentPick');
|
||
expect(wxml).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 };`)();
|
||
}
|