import { readFileSync } from 'node:fs'; import path from 'path'; import { describe, expect, it } from 'vitest'; describe('验收称同商品合并入库 + 相近列内选', () => { // 原「设计文档存在」断言已移除:`20260910-weigh-inspection-merge-similar-inline.md` // 不在本仓库(git 历史亦无此文件;合并口径现由 `20260910-weigh-merge-total-batch.md` 覆盖)。 // 行为契约由本文件其余用例与 `weighInspectionMergeSimilar` 服务用例覆盖(T7 AC-T7.1.3)。 it('总重量分批抵扣设计存在', () => { const design = readFileSync( path.join(__dirname, '../../docs/design/20260910-weigh-merge-total-batch.md'), 'utf8' ); expect(design).toContain('分批'); expect(design).toContain('need_confirm_over'); }); it('服务端导出 merge 并挂路由', () => { const weigh = readFileSync( path.join(__dirname, '../src/services/weighStationService.ts'), 'utf8' ); expect(weigh).toContain('submitInspectionWeighMergeByProduct'); expect(weigh).toContain('orderMergeInspectionLines'); expect(weigh).toContain('allocateMergeInspectionQtys'); expect(weigh).toContain('mergedCount'); // 2026-09-17 起超量不再拦截:原 400 need_confirm_over 已移除,改为一律照实入账 + 留痕 // 见 docs/design/20260917-weigh-over-qty-confirm.md expect(weigh).toContain('confirmOverQty: true'); expect(weigh).not.toContain("code: 'need_confirm_over'"); const routes = readFileSync( path.join(__dirname, '../src/routes/mobile/mobileWarehouseRoutes.ts'), 'utf8' ); expect(routes).toContain('/inspection/complete-merge'); expect(routes).toContain('submitInspectionWeighMergeByProduct'); }); it('选中行优先于 created_at FIFO', async () => { const { orderMergeInspectionLines } = await import('../src/services/weighStationService'); const ordered = orderMergeInspectionLines( [ { id: 'old', prepare_qty: 10 }, { id: 'new', prepare_qty: 10 }, ], 'new' ); expect(ordered.map((r) => r.id)).toEqual(['new', 'old']); }); it('总重量分批抵扣:够合计全结、不够分摊、超量未确认保留 unallocated', async () => { const { allocateMergeInspectionQtys, orderMergeInspectionLines } = await import( '../src/services/weighStationService' ); const lines = orderMergeInspectionLines( [ { id: 'a', prepare_qty: 10 }, { id: 'b', prepare_qty: 10 }, ], 'a' ); const full = allocateMergeInspectionQtys(lines, 20); expect(full.allocations).toEqual([ { id: 'a', qty: 10 }, { id: 'b', qty: 10 }, ]); expect(full.unallocated).toBe(0); const batch = allocateMergeInspectionQtys(lines, 12); expect(batch.allocations).toEqual([ { id: 'a', qty: 10 }, { id: 'b', qty: 2 }, ]); expect(batch.unallocated).toBe(0); const over = allocateMergeInspectionQtys(lines, 25); expect(over.allocations).toEqual([ { id: 'a', qty: 10 }, { id: 'b', qty: 10 }, ]); expect(over.unallocated).toBeCloseTo(5); const overOk = allocateMergeInspectionQtys(lines, 25, { confirmOverQty: true }); expect(overOk.allocations).toEqual([ { id: 'a', qty: 10 }, { id: 'b', qty: 15 }, ]); expect(overOk.unallocated).toBe(0); }); it('Android:列内选相近 + completeMerge + 需 SUM + 分批提示', () => { const act = readFileSync( path.join( __dirname, '../../android-weigh-terminal/app/src/main/java/com/canteen/weigh/ui/InspectionWeighActivity.java' ), 'utf8' ); expect(act).toContain('formatSimilarCandidateLabel'); expect(act).toContain(' · 需'); expect(act).toContain('rebuildSimilarPickLabelsFromDemand'); expect(act).toContain('applySimilarCandidate'); expect(act).toContain('默认最像'); expect(act).not.toContain('showSimilarCandidatesPickDialog'); expect(act).toContain('completeMerge'); expect(act).toContain('prevReq + remain'); expect(act).toContain('已分批抵扣'); const api = readFileSync( path.join( __dirname, '../../android-weigh-terminal/app/src/main/java/com/canteen/weigh/api/InspectionApi.java' ), 'utf8' ); expect(api).toContain('complete-merge'); expect(api).toContain('force_complete'); }); it('Android:偏差入库按钮 + forceComplete', () => { const act = readFileSync( path.join( __dirname, '../../android-weigh-terminal/app/src/main/java/com/canteen/weigh/ui/InspectionWeighActivity.java' ), 'utf8' ); expect(act).toContain('btn_force_complete'); expect(act).toContain('confirmSubmit(true)'); expect(act).toContain('forceComplete'); expect(act).toContain('偏差入库'); const layout = readFileSync( path.join( __dirname, '../../android-weigh-terminal/app/src/main/res/layout/activity_inspection_weigh.xml' ), 'utf8' ); expect(layout).toContain('偏差入库'); expect(layout).toContain('确认入库'); const weigh = readFileSync( path.join(__dirname, '../src/services/weighStationService.ts'), 'utf8' ); expect(weigh).toContain('force_complete'); expect(weigh).toContain('forceComplete'); const compliance = readFileSync( path.join(__dirname, '../src/services/inspectionComplianceService.ts'), 'utf8' ); expect(compliance).toContain('force_complete'); expect(compliance).toContain('forceComplete'); }); });