Some checks failed
Deploy Production / test (push) Successful in 5s
Deploy Production / deploy (push) Successful in 6s
PR Preview / teardown-preview (pull_request) Has been skipped
PR Preview / test (pull_request) Successful in 5s
Test / unit-test (push) Successful in 4s
Test / build-check (push) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 10s
Test / e2e-test (push) Has been cancelled
新增单元测试 (11个): - parseMultiRecipes: 单条/空格/连写/多条/无名称 - getPinyinInitials: 常见精油/忍冬花 - matchesPinyinInitials: 前缀匹配/不匹配子串/忍冬花 - EDITOR_ONLY_TAGS: 导出验证 E2E测试更新: - recipe-detail: 适配新UI(无编辑按钮) - 新增卡片视图测试 全部通过: 179 unit + 36 e2e Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
88 lines
3.4 KiB
JavaScript
88 lines
3.4 KiB
JavaScript
import { describe, it, expect } from 'vitest'
|
||
import { parseMultiRecipes } from '../composables/useSmartPaste'
|
||
import { getPinyinInitials, matchesPinyinInitials } from '../composables/usePinyinMatch'
|
||
|
||
const oilNames = ['薰衣草','茶树','柠檬','芳香调理','永久花','椒样薄荷','乳香','檀香','天竺葵','佛手柑','生姜']
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// parseMultiRecipes
|
||
// ---------------------------------------------------------------------------
|
||
describe('parseMultiRecipes', () => {
|
||
it('parses single recipe with name', () => {
|
||
const results = parseMultiRecipes('舒缓放松,薰衣草3,茶树2', oilNames)
|
||
expect(results).toHaveLength(1)
|
||
expect(results[0].name).toBe('舒缓放松')
|
||
expect(results[0].ingredients).toHaveLength(2)
|
||
})
|
||
|
||
it('parses recipe with space-separated parts', () => {
|
||
const results = parseMultiRecipes('长高 芳香调理8 永久花10', oilNames)
|
||
expect(results).toHaveLength(1)
|
||
expect(results[0].name).toBe('长高')
|
||
expect(results[0].ingredients.length).toBeGreaterThanOrEqual(2)
|
||
})
|
||
|
||
it('parses recipe with concatenated name+oil', () => {
|
||
const results = parseMultiRecipes('长高芳香调理8永久花10', oilNames)
|
||
expect(results).toHaveLength(1)
|
||
expect(results[0].name).toBe('长高')
|
||
})
|
||
|
||
it('parses multiple recipes', () => {
|
||
const results = parseMultiRecipes('舒缓放松,薰衣草3,茶树2,提神醒脑,柠檬5', oilNames)
|
||
expect(results).toHaveLength(2)
|
||
expect(results[0].name).toBe('舒缓放松')
|
||
expect(results[1].name).toBe('提神醒脑')
|
||
})
|
||
|
||
it('handles recipe with no name', () => {
|
||
const results = parseMultiRecipes('薰衣草3,茶树2', oilNames)
|
||
expect(results).toHaveLength(1)
|
||
expect(results[0].ingredients).toHaveLength(2)
|
||
})
|
||
})
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Pinyin matching
|
||
// ---------------------------------------------------------------------------
|
||
describe('getPinyinInitials', () => {
|
||
it('returns correct initials for common oils', () => {
|
||
expect(getPinyinInitials('薰衣草')).toBe('xyc')
|
||
expect(getPinyinInitials('茶树')).toBe('cs')
|
||
expect(getPinyinInitials('生姜')).toBe('sj')
|
||
})
|
||
|
||
it('handles 忍冬花', () => {
|
||
expect(getPinyinInitials('忍冬花呵护')).toBe('rdhhh')
|
||
})
|
||
})
|
||
|
||
describe('matchesPinyinInitials', () => {
|
||
it('matches prefix only', () => {
|
||
expect(matchesPinyinInitials('生姜', 's')).toBe(true)
|
||
expect(matchesPinyinInitials('生姜', 'sj')).toBe(true)
|
||
expect(matchesPinyinInitials('茶树', 's')).toBe(false) // cs doesn't start with s
|
||
expect(matchesPinyinInitials('茶树', 'cs')).toBe(true)
|
||
})
|
||
|
||
it('does not match substring', () => {
|
||
expect(matchesPinyinInitials('茶树', 's')).toBe(false)
|
||
})
|
||
|
||
it('matches 忍冬花 with r', () => {
|
||
expect(matchesPinyinInitials('忍冬花呵护', 'r')).toBe(true)
|
||
expect(matchesPinyinInitials('忍冬花呵护', 'rdh')).toBe(true)
|
||
expect(matchesPinyinInitials('忍冬花呵护', 'l')).toBe(false)
|
||
})
|
||
})
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// EDITOR_ONLY_TAGS
|
||
// ---------------------------------------------------------------------------
|
||
describe('EDITOR_ONLY_TAGS', () => {
|
||
it('exports EDITOR_ONLY_TAGS from recipes store', async () => {
|
||
const { EDITOR_ONLY_TAGS } = await import('../stores/recipes')
|
||
expect(EDITOR_ONLY_TAGS).toContain('已审核')
|
||
})
|
||
})
|