逐行本地校验后一次提交全部行;409 规格冲突确认后带 confirm_spec_conflict 重提(移动端路由本次补上该参数转发与 spec_conflicts 透传)。 失败行按 rowNumber 留在列表、成功行移除;报告随行绑定,绑定失败只提示 去 Web 补挂。逐行与一键共用 _submitInFlight 在途锁,防双击重复入库。
72 lines
3.2 KiB
TypeScript
72 lines
3.2 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
/**
|
|
* 小程序库存入库「一键入库」(2026-10-21 开发者需求):
|
|
* 把「识别结果 · 待审核」里的全部行一次提交,口径与 Web 批量入库一致。
|
|
*
|
|
* 设计:`docs/design/20261021-小程序库存入库一键入库.md`
|
|
*
|
|
* 钉住五件事:
|
|
* ① 逐行本地校验,任何一行不合格就整体不提交(提示第几行);
|
|
* ② 规格与档案不一致(409 `spec_conflict`)⇒ 确认后带 `confirm_spec_conflict` 重提;
|
|
* ③ **失败行按 rowNumber 留在列表**,成功行移除(与 Web 同口径);
|
|
* ④ 报告随行绑定,绑定失败只提示去 Web 补挂(不把入库判失败);
|
|
* ⑤ 在途锁:逐行与一键共用 `_submitInFlight`,防双击重复提交。
|
|
*/
|
|
const panelJs = readFileSync(
|
|
new URL('../../miniprogram/components/stock-inbound-panel/index.js', import.meta.url),
|
|
'utf8'
|
|
);
|
|
const panelWxml = readFileSync(
|
|
new URL('../../miniprogram/components/stock-inbound-panel/index.wxml', import.meta.url),
|
|
'utf8'
|
|
);
|
|
const mobileRoutes = readFileSync(
|
|
new URL('../src/routes/mobile/mobileInventoryRoutes.ts', import.meta.url),
|
|
'utf8'
|
|
);
|
|
|
|
describe('小程序:一键入库按钮与提交逻辑', () => {
|
|
it('模板有「一键入库(N)」按钮,绑 submitAllLines', () => {
|
|
expect(panelWxml).toContain('bindtap="submitAllLines"');
|
|
expect(panelWxml).toContain('一键入库(');
|
|
});
|
|
|
|
it('逐行校验后再提交,且只发一次请求', () => {
|
|
expect(panelJs).toContain('async submitAllLines()');
|
|
expect(panelJs).toContain('第 ${i + 1} 行:${built.error}');
|
|
expect(panelJs).toContain('await submitStockInboundBatch({ rows })');
|
|
});
|
|
|
|
it('规格冲突确认后带 confirm_spec_conflict 重提(与 Web 同口径)', () => {
|
|
expect(panelJs).toContain("code !== 'spec_conflict'");
|
|
expect(panelJs).toContain('仍然入库');
|
|
expect(panelJs).toContain('confirm_spec_conflict: true');
|
|
});
|
|
|
|
it('失败行按 rowNumber 保留,成功行移除;清空时一并清图片', () => {
|
|
expect(panelJs).toContain('const failedNumbers = new Set(failedRows.map((r) => Number(r.rowNumber)));');
|
|
expect(panelJs).toContain('this.data.lines || []).filter((_, i) => failedNumbers.has(i + 1)');
|
|
expect(panelJs).toContain('if (!remain.length) patch.imageList = [];');
|
|
});
|
|
|
|
it('报告绑定失败只提示补挂,不影响入库结论', () => {
|
|
expect(panelJs).toContain('report_bindings');
|
|
expect(panelJs).toContain('已入库,报告未挂上');
|
|
});
|
|
|
|
it('逐行与一键共用在途锁', () => {
|
|
expect(panelJs).toContain('if (this.data.submitting || this._submitInFlight) return;');
|
|
expect(panelJs.split('this._submitInFlight = true;').length - 1).toBeGreaterThanOrEqual(2);
|
|
expect(panelJs.split('this._submitInFlight = false;').length - 1).toBeGreaterThanOrEqual(2);
|
|
});
|
|
});
|
|
|
|
describe('移动端路由:转发规格冲突标记', () => {
|
|
it('stock-in-batch 转发 confirm_spec_conflict,并把冲突明细透给前端', () => {
|
|
expect(mobileRoutes).toContain('confirmSpecConflict: req.body?.confirm_spec_conflict === true');
|
|
expect(mobileRoutes).toContain('spec_conflicts: error?.spec_conflicts');
|
|
});
|
|
});
|