From 026ff18e92b482751a4ff3ace505afc7379f0bcf Mon Sep 17 00:00:00 2001 From: Hera Zhao Date: Sat, 11 Apr 2026 16:41:34 +0000 Subject: [PATCH] =?UTF-8?q?test:=20=E6=96=B0=E5=A2=9E=E8=8B=B1=E6=96=87?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=EF=BC=88?= =?UTF-8?q?5=E4=B8=AA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - oilEn翻译验证(已知/未知精油) - 英文查询检测 - 英文匹配精油名和配方en_name 全部通过: 209 unit + 36 e2e Co-Authored-By: Claude Opus 4.6 (1M context) --- frontend/src/__tests__/newFeatures.test.js | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/frontend/src/__tests__/newFeatures.test.js b/frontend/src/__tests__/newFeatures.test.js index 0150bae..8b50b8c 100644 --- a/frontend/src/__tests__/newFeatures.test.js +++ b/frontend/src/__tests__/newFeatures.test.js @@ -85,3 +85,51 @@ describe('EDITOR_ONLY_TAGS', () => { expect(EDITOR_ONLY_TAGS).toContain('已审核') }) }) + +// --------------------------------------------------------------------------- +// English search +// --------------------------------------------------------------------------- +describe('English search matching', () => { + const { oilEn } = require('../composables/useOilTranslation') + + it('oilEn returns English name for known oils', () => { + expect(oilEn('薰衣草')).toBe('Lavender') + expect(oilEn('茶树')).toBe('Tea Tree') + expect(oilEn('乳香')).toBe('Frankincense') + }) + + it('oilEn returns empty for unknown oils', () => { + expect(oilEn('不存在的油')).toBeFalsy() + }) + + it('English query detection', () => { + const isEn = (q) => /^[a-zA-Z\s]+$/.test(q) + expect(isEn('lavender')).toBe(true) + expect(isEn('Tea Tree')).toBe(true) + expect(isEn('薰衣草')).toBe(false) + expect(isEn('lav3')).toBe(false) + }) + + it('English matches oil name in recipe', () => { + const recipe = { + name: '助眠配方', + en_name: 'Sleep Aid Blend', + ingredients: [{ oil: '薰衣草', drops: 3 }], + tags: [] + } + const q = 'lavender' + const isEn = /^[a-zA-Z\s]+$/.test(q) + const enNameMatch = isEn && (recipe.en_name || '').toLowerCase().includes(q) + const oilEnMatch = isEn && recipe.ingredients.some(ing => (oilEn(ing.oil) || '').toLowerCase().includes(q)) + expect(oilEnMatch).toBe(true) + expect(enNameMatch).toBe(false) + }) + + it('English matches recipe en_name', () => { + const recipe = { name: '助眠', en_name: 'Sleep Aid Blend', ingredients: [], tags: [] } + const q = 'sleep' + const isEn = /^[a-zA-Z\s]+$/.test(q) + const enNameMatch = isEn && (recipe.en_name || '').toLowerCase().includes(q) + expect(enNameMatch).toBe(true) + }) +})