test: 分享文本和消耗分析动态单位测试
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 6s
Test / build-check (push) Successful in 4s
PR Preview / test (pull_request) Successful in 6s
PR Preview / deploy-preview (pull_request) Successful in 14s
Test / e2e-test (push) Failing after 1m27s
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 6s
Test / build-check (push) Successful in 4s
PR Preview / test (pull_request) Successful in 6s
PR Preview / deploy-preview (pull_request) Successful in 14s
Test / e2e-test (push) Failing after 1m27s
新增2个测试: 分享文本各成分用正确单位、消耗分析用量/容量单位 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user