feat: 更多改进 #21

Merged
hera merged 6 commits from feat/more-improvements into main 2026-04-10 21:26:19 +00:00
Showing only changes of commit 3c808be7e5 - Show all commits

View File

@@ -0,0 +1,87 @@
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('已审核')
})
})