Files
SupplierSystem/src/utils/inspectionInboundFields.contract.test.ts
T
雨天 e86c6f58de
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
订单入库拍照: 免拍照也识别 + 每批9张
跟进开发者「可以」:① 识别触发条件由 row.photoRequired && photoCount>0 改为
只看 photoCount>0 ⇒ 免拍照行拍照后同样走识别预填(截图那两行正是免拍照);
② wx.chooseImage count 3 → 9(微信单次上限)。
不改上传/门槛/入库写路径/文案;停用的 resetAiResult 未动。
契约测试补「触发不再含 photoRequired + count 9」断言,设计文档升 v2。
2026-10-16 18:04:36 +08:00

117 lines
5.9 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 'node:fs';
import { describe, expect, it } from 'vitest';
/**
* 订单入库:补 4 字段(规格 / 生产日期 / 保质期 / 产地)+ 拍照改「识别商品信息」(去掉 AI 质量判定)。
* 设计 docs/design/20261016-订单入库补规格生产日期保质期产地.md。
*
* 口径(开发者 2026-10-16):「相当于就是默认为合格就行,前端这边隐式展示为合格」⇒
* **不再调用** `analyzeInspectionQuality`(代码/prompt 保留、不接),「合格才入库/须拍照/退回」门槛不动。
*/
const read = (rel: string) => readFileSync(new URL(rel, import.meta.url), 'utf8');
const wxml = read('../../miniprogram/components/inspection-panel/index.wxml');
const wxss = read('../../miniprogram/components/inspection-panel/index.wxss');
const js = read('../../miniprogram/components/inspection-panel/index.js');
const svc = read('../../server/src/services/inspectionComplianceService.ts');
const route = read('../../server/src/routes/mobile/mobileWarehouseRoutes.ts');
describe('卡片:4 字段 + 去掉 AI 判定', () => {
it('新增规格/生产日期/保质期/产地 输入(card-r3)', () => {
expect(wxml).toContain('placeholder="规格"');
expect(wxml).toContain('placeholder="保质期"');
expect(wxml).toContain('placeholder="产地"');
expect(wxml).toContain('mode="date"');
expect(wxml).toContain('card-r3');
});
it('保质期 = 数值输入 + 年/月/日 单位选择(对齐库存入库)', () => {
expect(wxml).toContain('bindinput="onShelfValueInput"');
expect(wxml).toContain('bindchange="onShelfUnitChange"');
expect(wxml).toContain('range="{{shelfLifeUnits}}"');
expect(js).toContain('shelfLifeUnits: SHELF_LIFE_UNITS,');
// ⚠️ 卡片是 WXML template:组件 data 进不去,必须在每个 <template is> 里显式传
expect(
(
wxml.match(
/is="inboundCard" data="\{\{item, submittingId, analyzingId, resultOptions, zoneRange, shelfLifeUnits\}\}"/g
) || []
).length,
'两处 <template is="inboundCard"> 都要带上 shelfLifeUnits,否则单位选择器为空'
).toBe(2);
});
it('去掉 AI「合格/不合格」徽标与结果 picker(结果隐式合格)', () => {
expect(wxml).not.toContain('ai-verdict');
expect(wxml).not.toContain('onRatingChange');
});
it('不再调用 AI 质检(runAiForRow / analyzeInspectionQuality 保留但不接)', () => {
// 代码保留(开发者:「代码别删」)
expect(js).toContain('async runAiForRow(id) {');
expect(js).toContain('analyzeInspectionQuality');
// 拍照 / 删图都改走识别
expect(js).not.toContain('await this.runAiForRow(id)');
expect((js.match(/await this\.runRecognizeForRow\(id\)/g) || []).length).toBe(2);
// 入库不再有「请先完成 AI 质检」闸门
expect(js).not.toContain('请先完成 AI 质检');
});
});
describe('拍照 → 识别商品信息(复用库存入库那套,支持多拍)', () => {
it('本批多图一次提交(不再只用最后一张),跨行结果按字段合并', () => {
expect(js).toContain('recognizeStockInboundLines({ images_base64: images })');
// 本批每张都留 base64(uploadPhoto 从「覆盖成单张」改为 push 进数组)
expect(js).toContain('this._aiImagesById[id].push(content)');
expect(js).toContain('const images = cached.length ? cached : fallback ? [fallback] : [];');
expect(js).toContain('mergeRecognizedItemFields(items)');
});
it('识别只补空不覆盖已有值;保质期跨项取第一个能解析的值', () => {
expect(js).toContain("if (spec && !String(row.input_spec || '').trim()) patch.input_spec = spec;");
// 保质期走「数值 + 年/月/日」工具(对齐库存入库)
expect(js).toContain('const line = applyShelfLifeFromAi({}, item);');
expect(js).toContain('patch.input_shelf_life_unit_index = shelfLine.shelf_life_unit_index || 0;');
});
});
describe('多拍与免拍照行也识别(2026-10-16 开发者:可以)', () => {
it('每批最多 9 张;识别触发不再看 须/免拍照(只看有没有照片)', () => {
expect(js).toContain('count: 9,');
// 「须/免拍照都识别」:带 photoRequired 的那个条件只剩**停用的** resetAiResult 一处
expect(
(js.match(/row\?\.photoRequired && Number\(row\.photoCount \|\| 0\) > 0\)/g) || []).length
).toBe(1);
// 拍照 / 删图 两处都用「只要本行有照片就识别」
expect((js.match(/if \(Number\(row\?\.photoCount \|\| 0\) > 0\) \{/g) || []).length).toBe(2);
});
});
describe('提交:保质期 + 档案回写(只写人工改过的)', () => {
it('前端提交带 shelf_life(数值+单位合成原文)与 archive', () => {
expect(js).toContain('shelf_life:');
expect(js).toContain('shelfLifeTextFromLine({');
expect(js).toContain('archive: buildArchivePayload(');
});
it('服务端落 inventory.shelf_life/expiry_date 并回写档案(同事务)', () => {
expect(svc).toContain('production_date, shelf_life, expiry_date, storage_zone');
expect(svc).toContain('const expiryDate = deriveExpiryDate(productionDate, shelfLife);');
expect(svc).toContain('applyArchiveWriteback(client, {');
});
it('路由透传 shelf_life/archive;列表带出商品库 spec(商品有就带过去)', () => {
expect(route).toContain('shelf_life: req.body?.shelf_life ? String(req.body.shelf_life) : null,');
expect(route).toContain('archive: req.body?.archive ?? null,');
expect(route).toContain("COALESCE(s.spec, '') AS spec");
});
});
describe('可选控件呈「选择框」观感', () => {
it('区域/产月选择器有边框与 ▾(不再像纯文字)', () => {
expect(wxss).toMatch(/\.rate-pick\s*\{[^}]*border:\s*1rpx solid/);
expect(wxml).toContain("{{item.storage_zone || '区域'}} ▾");
expect(wxml).toContain("{{item.production_month || '产月'}} ▾");
});
});