/** * 工单需求字段展示单测:海运拼柜隐藏箱型箱量(产品口径 2026-11-22)。 * 拼柜按体积计费,承运人不指定箱型,所以格子、列表第二行、多段详情都不出现箱型。 */ import { buildDemandFields, isSeaLcl, quantitySummary, multiSegmentViews } from '/@/views/inquiry/workOrder/demandFields'; function labelsOf(fields: { label: string }[]): string[] { return fields.map((f) => f.label); } test('isSeaLcl 识别拼柜口语,否定说法按整柜', () => { ['拼柜', '拼箱', '散货', 'LCL', 'lcl 拼箱'].forEach((v) => expect(isSeaLcl(v)).toBe(true)); ['整柜', '非拼柜', '不拼柜', '', null, undefined, 'FCL'].forEach((v) => expect(isSeaLcl(v as string)).toBe(false), ); }); test('海运拼柜:需求格子不列箱型箱量', () => { const ticket = { businessLine: 'SEA', origin: '上海', destination: '洛杉矶', goodsName: '普货', factsJson: JSON.stringify({ 起运港: '上海', 目的港: '洛杉矶', 品名: '普货', 货量: '20吨', 整柜或拼柜: '拼柜', 箱型箱量: '1x40HQ', 贸易条款: '门到门', }), }; const labels = labelsOf(buildDemandFields(ticket)); expect(labels).toContain('整柜或拼柜'); expect(labels).not.toContain('箱型箱量'); }); test('海运整柜:需求格子保留箱型箱量', () => { const ticket = { businessLine: 'SEA', factsJson: JSON.stringify({ 起运港: '上海', 目的港: '洛杉矶', 品名: '普货', 货量: '20吨', 整柜或拼柜: '整柜', 箱型箱量: '1x40HQ', 贸易条款: '门到门', }), }; const fields = buildDemandFields(ticket); expect(labelsOf(fields)).toContain('箱型箱量'); expect(fields.find((f) => f.label === '箱型箱量')?.value).toBe('1x40HQ'); }); test('海运拼柜:列表第二行不写箱型', () => { const ticket = { businessLine: 'SEA', factsJson: JSON.stringify({ 货量: '20吨', 整柜或拼柜: '拼柜', 箱型箱量: '1x40HQ', }), }; const summary = quantitySummary(ticket); expect(summary).toContain('整柜或拼柜 拼柜'); expect(summary).not.toContain('箱型箱量'); }); test('多段里海运段是拼柜时不显示箱型', () => { const ticket = { businessLine: 'MULTI', factsJson: JSON.stringify({ segments_json: JSON.stringify([ { mode: 'SEA', facts: { 起运港: '上海', 目的港: '洛杉矶', 整柜或拼柜: '拼柜', 箱型箱量: '1x40HQ' }, }, ]), }), }; const views = multiSegmentViews(ticket); expect(views.length).toBeGreaterThan(0); expect(views[0].detailLine).not.toContain('1x40HQ'); expect(views[0].detailLine).toContain('拼柜'); }); test('中港集拼:需求格子看体积毛重,不看车型/数量', () => { const ticket = { businessLine: 'LAND', factsJson: JSON.stringify({ 运输类型: '中港零担/集拼', 线路类别: '中港/中亚/中欧', 运输分类: '普件(东南亚、中港常用线路/常规车型)', 起运港: '广州', 目的港: '香港', 品名: '衣服', 体积: '20CBM', 毛重: '3000KG', }), }; const fields = buildDemandFields(ticket); const labels = labelsOf(fields); expect(labels).toContain('体积(CBM)'); expect(labels).toContain('重量(KG)'); expect(labels).not.toContain('车型/数量'); expect(fields.find((f) => f.label === '体积(CBM)')?.value).toBe('20CBM'); expect(fields.find((f) => f.label === '重量(KG)')?.value).toBe('3000KG'); const summary = quantitySummary(ticket); expect(summary).toContain('体积(CBM) 20CBM'); expect(summary).toContain('重量(KG) 3000KG'); expect(summary).not.toContain('车型/数量'); });