- 分类不再用滚轮选择器,改成一排可点 chip(选中态高亮) - chip 末尾「+ 新建分类」,在表单内就地输入名称创建 - 新建复用库存入库建分类接口,建完直接选中且不关表单
174 lines
9.5 KiB
JavaScript
174 lines
9.5 KiB
JavaScript
/**
|
|
* 小程序「独立加工 ≠ 正常录单加工」契约(2026-10-23 开发者:记住两者是两回事)。
|
|
*
|
|
* 只读校验:独立加工(source_type='standalone')在小程序里
|
|
* ① 创建 = 多行原料(materials)+ 幂等请求号;
|
|
* ② 完工 = 申报成品(成品多行 / 成本自动均分 / 损耗自动差额 / 两个继承开关);
|
|
* ③ 订单加工与需求单的「毛重/净重 + 加工单价」流程**保持原样**。
|
|
*/
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const assert = require('assert');
|
|
|
|
const js = fs.readFileSync(path.join(__dirname, 'index.js'), 'utf8');
|
|
const wxml = fs.readFileSync(path.join(__dirname, 'index.wxml'), 'utf8');
|
|
const wxss = fs.readFileSync(path.join(__dirname, 'index.wxss'), 'utf8');
|
|
const api = fs.readFileSync(path.join(__dirname, '../../utils/request.js'), 'utf8');
|
|
|
|
let failed = 0;
|
|
function it(name, fn) {
|
|
try {
|
|
fn();
|
|
console.log(' ✓', name);
|
|
} catch (err) {
|
|
failed += 1;
|
|
console.log(' ✗', name, '→', err.message);
|
|
}
|
|
}
|
|
|
|
it('创建:独立加工走多行原料 + client_request_no', () => {
|
|
assert.ok(js.includes('materials: rows.map((row) => ({ sku_code: row.sku_code, qty: Number(row.qty) }))'));
|
|
assert.ok(js.includes('client_request_no:'));
|
|
assert.ok(wxml.includes('原料明细(可多行)'));
|
|
assert.ok(wxml.includes('onCreateMaterialQty'));
|
|
assert.ok(wxml.includes('removeCreateMaterial'));
|
|
});
|
|
|
|
it('完工:独立加工走成品申报(不再要求毛重/净重)', () => {
|
|
assert.ok(js.includes("String(row.source_type || '') === 'standalone'"));
|
|
assert.ok(js.includes('this.openOutputForm(row);'));
|
|
assert.ok(js.includes('await completeStandaloneProcessingTask(outputTaskId'));
|
|
assert.ok(wxml.includes('申报加工成品'));
|
|
assert.ok(wxml.includes('确认完工并回仓'));
|
|
});
|
|
|
|
it('成品:成本默认均分 + 损耗自动差额 + 两个继承开关', () => {
|
|
assert.ok(js.includes('this.data.outputMaterialCost / totalQty'));
|
|
assert.ok(js.includes('outputAutoLoss'));
|
|
assert.ok(wxml.includes('inherit_batch_report'));
|
|
assert.ok(wxml.includes('inherit_inspection_report'));
|
|
});
|
|
|
|
/**
|
|
* 2026-10-23 开发者:「这两个按钮是默认勾选上的,选中状态显眼点,绿色的勾选箭头」。
|
|
* 三个新建成品的入口(原料带出 / 单据头回退 / 搜索添加)都默认勾选,
|
|
* 选中态用绿色实心块 + 白色 ✓(不再用 ☑/☐ 字符 —— 小程序里跟正文同色,看不出是否勾选)。
|
|
*/
|
|
it('两个继承开关默认勾选,且选中态是绿色勾', () => {
|
|
assert.ok((js.match(/inherit_batch_report: true/g) || []).length >= 3, '三处新建成品行都要默认勾选');
|
|
assert.ok((js.match(/inherit_inspection_report: true/g) || []).length >= 3);
|
|
assert.ok(!js.includes('inherit_batch_report: false'));
|
|
assert.ok(!js.includes('inherit_inspection_report: false'));
|
|
// 模板:类名带 is-on 控制选中态,勾号只在选中时渲染
|
|
assert.ok(wxml.includes("inherit-toggle {{item.inherit_batch_report ? 'is-on' : ''}}"));
|
|
assert.ok(wxml.includes("item.inherit_batch_report ? '✓'"));
|
|
assert.ok(!wxml.includes("'☑'"));
|
|
// 样式:选中态绿色实心 + 白勾 + 标签变绿加粗
|
|
assert.ok(wxss.includes('.inherit-toggle.is-on .inherit-check'));
|
|
assert.ok(wxss.includes('background: #10b981'));
|
|
assert.ok(wxss.includes('.inherit-toggle.is-on .inherit-label'));
|
|
});
|
|
|
|
/**
|
|
* 2026-10-23 开发者报障:「成品明细」搜索框显示字面量 undefined、搜索商品没反应。
|
|
* 根因:WXML 绑定的 `outputSkuSearch` / `outputSkuOptions` 没在 `data` 里声明,
|
|
* setData 写不进数据层 ⇒ input 把 undefined 渲染成字面量,每次重渲染又把输入值刷回 undefined。
|
|
*/
|
|
it('成品搜索:input 绑定的键必须在 data 中声明', () => {
|
|
const dataStart = js.indexOf(' data: {');
|
|
const dataEnd = js.indexOf('\n observers:');
|
|
assert.ok(dataStart > 0 && dataEnd > dataStart, ' 解析不到 data 块');
|
|
const dataBlock = js.slice(dataStart, dataEnd);
|
|
assert.ok(/\boutputSkuSearch:\s*''/.test(dataBlock), 'data 缺少 outputSkuSearch');
|
|
assert.ok(/\boutputSkuOptions:\s*\[\]/.test(dataBlock), 'data 缺少 outputSkuOptions');
|
|
assert.ok(wxml.includes('bindinput="onOutputSkuInput"'));
|
|
});
|
|
|
|
/**
|
|
* 2026-10-23 真机两轮复现:
|
|
* ① 先出现字面量 `undefined`(数据层被写入 undefined,又被 bindinput 当关键字提交);
|
|
* ② 改成"非受控 + epoch 重建"后,真机表现为**输入什么都被清空**。
|
|
* 现行修法:**受控输入 + data 声明 + 写入时严格取字符串**(不再重建输入框)。
|
|
*/
|
|
it('搜索框必须受控(绑定 value),且处理器只回写字符串', () => {
|
|
assert.ok(/value="\{\{outputSkuSearch\}\}"/.test(wxml), '搜索框必须绑定 value(否则真机上输入会被丢弃)');
|
|
assert.ok(!js.includes('outputSearchEpochList'), '不应再用 epoch 重建输入框');
|
|
// 处理器只认字符串;非字符串一律当空串(不再出现 `undefined` 字面量)
|
|
const inputFn = js.slice(js.indexOf('onOutputSkuInput(e)'), js.indexOf('refreshOutputSkuOptions(keyword)'));
|
|
assert.ok(inputFn.includes("typeof raw === 'string' ? raw : ''"), '输入处理器必须只回写字符串');
|
|
// 输入处理器里**不得**触碰候选/搜索结果(历史上就是把结果写回输入框导致清空/undefined)
|
|
assert.ok(!inputFn.includes('outputSkuOptions'), '输入处理器不得把候选列表写回输入框');
|
|
const dataBlock = js.slice(js.indexOf(' data: {'), js.indexOf('\n observers:'));
|
|
assert.ok(/outputSkuSearch:\s*''/.test(dataBlock), 'data 必须声明 outputSkuSearch');
|
|
});
|
|
|
|
it('成品搜索与 Web 同交互:打开即载入候选 + 本地即时过滤 + 本地没有再回服务端', () => {
|
|
const dataStart = js.indexOf(' data: {');
|
|
const dataBlock = js.slice(dataStart, js.indexOf('\n observers:'));
|
|
assert.ok(/\ballOutputSkus:\s*\[\]/.test(dataBlock), 'data 缺少 allOutputSkus');
|
|
// 打开弹窗就载入(不必先打字)
|
|
assert.ok(js.includes('this.loadOutputSkuOptions();'));
|
|
assert.ok(js.includes('const rows = res && Array.isArray(res.data) ? res.data : [];'));
|
|
// 输入时本地过滤
|
|
assert.ok(js.includes('const local = all.filter((o) => matchesOutputSku(o, kw));'));
|
|
// 本地没命中才请求服务端,且丢弃过期响应
|
|
assert.ok(js.includes('const seq = (this._outputSkuSeq || 0) + 1;'));
|
|
assert.ok(js.includes('if (seq !== this._outputSkuSeq) return;'));
|
|
// 候选只留展示字段(不把服务端的大对象整块 setData)
|
|
assert.ok(js.includes('function toOutputSkuOption(row)'));
|
|
});
|
|
|
|
/**
|
|
* 2026-10-23 开发者:「没有搜索到应该是新增商品呀」。
|
|
* 搜不到时不再是一片空白,而是给「搜不到「xx」,点此用该名称新建商品」入口,
|
|
* 建品复用库存入库同一个接口/字段(`fetchStockInboundCategories` + `createStockInboundProduct`),建好直接加入成品行。
|
|
*/
|
|
it('搜不到 → 用该名称新建商品(复用库存入库建品接口)', () => {
|
|
assert.ok(wxml.includes("catchtap=\"openOutputProductForm\""), '搜不到入口必须真的渲染出来');
|
|
assert.ok(wxml.includes('搜不到「{{outputSkuSearch}}」'));
|
|
assert.ok(wxml.includes('wx:elif="{{outputSkuSearch}}"'), '候选为空且有关键字时才显示建品入口');
|
|
assert.ok(js.includes('async openOutputProductForm()'));
|
|
assert.ok(js.includes('fetchStockInboundCategories()'));
|
|
assert.ok(js.includes('await createStockInboundProduct({'));
|
|
assert.ok(js.includes('parent_code: cat.code'));
|
|
// 建好直接加入成品行(默认勾选两个继承开关)
|
|
assert.ok(js.includes('this.appendOutputRow({'));
|
|
assert.ok(wxml.includes('showOutputProductModal'));
|
|
});
|
|
|
|
/**
|
|
* 2026-10-23 开发者(附截图):「新增商品这块 分类框优化一下别在展开弹窗了 支持新建分类」。
|
|
* 建品表单里的分类从 `<picker>`(滚轮弹窗)改为内联标签 + 就地新建,新建复用库存入库同一个建分类接口。
|
|
*/
|
|
it('新建商品的分类框:内联标签 + 就地新建分类(不用滚轮选择器)', () => {
|
|
assert.ok(!/<picker[^>]*onOutputProductCategory/.test(wxml), '不得再用 picker 选分类');
|
|
assert.ok(wxml.includes('class="cat-chips"'));
|
|
assert.ok(wxml.includes('catchtap="pickOutputCategory"'));
|
|
assert.ok(wxml.includes('+ 新建分类'));
|
|
assert.ok(wxml.includes('catchtap="toggleOutputCategoryCreate"'));
|
|
assert.ok(wxml.includes('catchtap="submitOutputCategory"'));
|
|
assert.ok(js.includes('await createStockInboundCategory(name);'));
|
|
assert.ok(js.includes('createStockInboundCategory,'), '建分类接口必须从 request 引入');
|
|
// 建完直接选中(不关表单)
|
|
assert.ok(js.includes("'outputProductForm.categoryIndex': index < 0 ? 0 : index,"));
|
|
});
|
|
|
|
it('订单/需求单加工:毛重净重流程保持原样(不许被改)', () => {
|
|
assert.ok(js.includes('await completeProcessingWork({'));
|
|
assert.ok(js.includes('gross_weight: grossWeight,'));
|
|
assert.ok(js.includes('net_weight: netWeight,'));
|
|
assert.ok(wxml.includes('加工损耗(毛重 − 净重)'));
|
|
});
|
|
|
|
it('接口:新完工/行查询走移动端路由(与 Web 同一服务)', () => {
|
|
assert.ok(api.includes("'/mobile/processing/standalone/'") || api.includes('/mobile/processing/standalone/${encodeURIComponent(taskId)}/complete'));
|
|
assert.ok(api.includes('/complete`'));
|
|
assert.ok(api.includes('/lines`'));
|
|
});
|
|
|
|
if (failed) {
|
|
console.error(`\n ${failed} 条失败`);
|
|
process.exit(1);
|
|
}
|
|
console.log('\n 全部通过');
|