import { readFileSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; /** * 小程序分拣「调整批次」弹窗:批次行展示**生产日期**(2026-10-21 开发者需求)。 * * 设计:`docs/design/20261021-小程序分拣批次行展示生产日期.md` * * 这类"字段一路都在、只在最后一跳丢了"的缺陷容易复发,所以三处一起钉: * ① 后端批次查询仍返回 `production_date`; * ② 小程序 `loadBatchInfo` 与两个弹窗行构造器都映射该字段; * ③ 模板渲染「生产」且元信息行不再单行 nowrap(否则新加的段会被截断,尾部「可用」也丢)。 */ const panelJs = readFileSync( new URL('../../miniprogram/components/picking-panel/index.js', import.meta.url), 'utf8' ); const panelWxml = readFileSync( new URL('../../miniprogram/components/picking-panel/index.wxml', import.meta.url), 'utf8' ); const panelWxss = readFileSync( new URL('../../miniprogram/components/picking-panel/index.wxss', import.meta.url), 'utf8' ); const pickingService = readFileSync( new URL('../src/services/pickingService.ts', import.meta.url), 'utf8' ); describe('分拣批次行 · 生产日期', () => { it('后端分拣出库批次返回 production_date', () => { expect(pickingService).toContain('production_date: toDateOnlyLocal(r.production_date)'); }); it('loadBatchInfo 与两个弹窗行构造器都映射 production_date', () => { const hits = panelJs.split('production_date: b.production_date').length - 1; // loadBatchInfo + buildEditorState + resetBatchEditorFifo expect(hits).toBeGreaterThanOrEqual(3); }); it('模板渲染生产日期(空值显示 —)', () => { expect(panelWxml).toContain('生产 {{item.production_date || \'—\'}}'); }); it('元信息行允许换行,不再用 ellipsis 截断', () => { const css = panelWxss.slice(panelWxss.indexOf('.batch-row-meta')); const block = css.slice(0, css.indexOf('}')); expect(block).toContain('white-space: normal'); expect(block).not.toContain('text-overflow: ellipsis'); }); it('行内批次摘要口径不变(仍只有 区域 + 入库日 + 数量)', () => { const assembly = readFileSync( new URL('../../miniprogram/utils/pickingAssembly.js', import.meta.url), 'utf8' ); expect(assembly).toContain('const date = displayText(b.inbound_date || b.created_at).slice(5, 10);'); expect(assembly).toContain('return [zone, date, qty].filter(Boolean).join(\' \');'); }); });