test: PR#27新增单元测试和e2e测试
All checks were successful
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 5s
PR Preview / deploy-preview (pull_request) Successful in 17s
Test / e2e-test (push) Successful in 53s
All checks were successful
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 5s
PR Preview / deploy-preview (pull_request) Successful in 17s
Test / e2e-test (push) Successful in 53s
后端: auto_translate/title_case 14个测试 前端: EDITOR_ONLY_TAGS、drop单复数、已下架过滤 11个测试 E2E: en_name title case、删除用户转移配方、管理配方登录引导 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
86
frontend/src/__tests__/pr27Features.test.js
Normal file
86
frontend/src/__tests__/pr27Features.test.js
Normal file
@@ -0,0 +1,86 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// EDITOR_ONLY_TAGS includes '已下架'
|
||||
// ---------------------------------------------------------------------------
|
||||
describe('EDITOR_ONLY_TAGS', () => {
|
||||
it('includes 已审核', async () => {
|
||||
const { EDITOR_ONLY_TAGS } = await import('../stores/recipes')
|
||||
expect(EDITOR_ONLY_TAGS).toContain('已审核')
|
||||
})
|
||||
|
||||
it('includes 已下架', async () => {
|
||||
const { EDITOR_ONLY_TAGS } = await import('../stores/recipes')
|
||||
expect(EDITOR_ONLY_TAGS).toContain('已下架')
|
||||
})
|
||||
|
||||
it('is an array with at least 2 entries', async () => {
|
||||
const { EDITOR_ONLY_TAGS } = await import('../stores/recipes')
|
||||
expect(Array.isArray(EDITOR_ONLY_TAGS)).toBe(true)
|
||||
expect(EDITOR_ONLY_TAGS.length).toBeGreaterThanOrEqual(2)
|
||||
})
|
||||
})
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// English drop/drops pluralization logic
|
||||
// ---------------------------------------------------------------------------
|
||||
describe('drop/drops pluralization', () => {
|
||||
const pluralize = (n) => (n === 1 ? 'drop' : 'drops')
|
||||
|
||||
it('singular: 1 drop', () => {
|
||||
expect(pluralize(1)).toBe('drop')
|
||||
})
|
||||
|
||||
it('plural: 0 drops', () => {
|
||||
expect(pluralize(0)).toBe('drops')
|
||||
})
|
||||
|
||||
it('plural: 2 drops', () => {
|
||||
expect(pluralize(2)).toBe('drops')
|
||||
})
|
||||
|
||||
it('plural: 5 drops', () => {
|
||||
expect(pluralize(5)).toBe('drops')
|
||||
})
|
||||
})
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 已下架 tag filtering logic (pure function extraction)
|
||||
// ---------------------------------------------------------------------------
|
||||
describe('已下架 tag filtering', () => {
|
||||
const recipes = [
|
||||
{ name: 'Active Recipe', tags: ['头疗'] },
|
||||
{ name: 'Delisted Recipe', tags: ['已下架'] },
|
||||
{ name: 'No Tags Recipe', tags: [] },
|
||||
{ name: 'Multi Tag', tags: ['热门', '已下架'] },
|
||||
{ name: 'Null Tags', tags: null },
|
||||
]
|
||||
|
||||
const filterDelisted = (list) =>
|
||||
list.filter((r) => !r.tags || !r.tags.includes('已下架'))
|
||||
|
||||
it('removes recipes with 已下架 tag', () => {
|
||||
const result = filterDelisted(recipes)
|
||||
expect(result.map((r) => r.name)).not.toContain('Delisted Recipe')
|
||||
expect(result.map((r) => r.name)).not.toContain('Multi Tag')
|
||||
})
|
||||
|
||||
it('keeps recipes without 已下架 tag', () => {
|
||||
const result = filterDelisted(recipes)
|
||||
expect(result.map((r) => r.name)).toContain('Active Recipe')
|
||||
expect(result.map((r) => r.name)).toContain('No Tags Recipe')
|
||||
})
|
||||
|
||||
it('handles null tags gracefully', () => {
|
||||
const result = filterDelisted(recipes)
|
||||
expect(result.map((r) => r.name)).toContain('Null Tags')
|
||||
})
|
||||
|
||||
it('returns empty array for all-delisted list', () => {
|
||||
const all = [
|
||||
{ name: 'A', tags: ['已下架'] },
|
||||
{ name: 'B', tags: ['已下架', '其他'] },
|
||||
]
|
||||
expect(filterDelisted(all)).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user