From 317ea3a2b604bbda4be6c40b010de1a9d1d6cce7 Mon Sep 17 00:00:00 2001 From: Hera Zhao Date: Tue, 14 Apr 2026 18:09:08 +0000 Subject: [PATCH] =?UTF-8?q?test:=20=E5=88=86=E4=BA=AB=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E5=92=8C=E6=B6=88=E8=80=97=E5=88=86=E6=9E=90=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E5=8D=95=E4=BD=8D=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增2个测试: 分享文本各成分用正确单位、消耗分析用量/容量单位 Co-Authored-By: Claude Opus 4.6 (1M context) --- frontend/src/__tests__/pr27Features.test.js | 37 +++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/frontend/src/__tests__/pr27Features.test.js b/frontend/src/__tests__/pr27Features.test.js index b810949..56e98d8 100644 --- a/frontend/src/__tests__/pr27Features.test.js +++ b/frontend/src/__tests__/pr27Features.test.js @@ -608,3 +608,40 @@ describe('product edit UI logic — PR34', () => { expect(labelForMl).toBe('产品名称') }) }) + +// --------------------------------------------------------------------------- +// PR34: Share text and consumption analysis use dynamic unit +// --------------------------------------------------------------------------- +describe('share text and consumption use dynamic unit — PR34', () => { + const UNIT_MAP = { drop: '滴', ml: 'ml', g: 'g', capsule: '颗' } + function unitLabel(name, unitMap) { return UNIT_MAP[unitMap[name] || 'drop'] } + + it('share text uses unitLabel for each ingredient', () => { + const units = { '薰衣草': 'drop', '无香乳液': 'ml', '植物空胶囊': 'capsule' } + const ings = [ + { oil: '薰衣草', drops: 3 }, + { oil: '无香乳液', drops: 30 }, + { oil: '植物空胶囊', drops: 2 }, + ] + const lines = ings.map(i => `${i.oil} ${i.drops}${unitLabel(i.oil, units)}`) + expect(lines[0]).toBe('薰衣草 3滴') + expect(lines[1]).toBe('无香乳液 30ml') + expect(lines[2]).toBe('植物空胶囊 2颗') + }) + + it('consumption analysis uses unitLabel per oil', () => { + const units = { '薰衣草': 'drop', '活力磨砂膏': 'g' } + const data = [ + { oil: '薰衣草', drops: 15, bottleDrops: 280 }, + { oil: '活力磨砂膏', drops: 30, bottleDrops: 70 }, + ] + const display = data.map(c => ({ + usage: `${c.drops}${unitLabel(c.oil, units)}`, + capacity: `${c.bottleDrops}${unitLabel(c.oil, units)}`, + })) + expect(display[0].usage).toBe('15滴') + expect(display[0].capacity).toBe('280滴') + expect(display[1].usage).toBe('30g') + expect(display[1].capacity).toBe('70g') + }) +})