fix: bug
This commit is contained in:
@@ -103,6 +103,13 @@ const mockCategories: Category[] = [
|
||||
{ id: 'cat-3', name: 'Category 3', templates: [] },
|
||||
]
|
||||
|
||||
// Test data with multi-language support
|
||||
const mockCategoriesWithI18n: Array<Category & { nameEn: string }> = [
|
||||
{ id: 'cat-1', name: '分类1', nameEn: 'Category 1', templates: [] },
|
||||
{ id: 'cat-2', name: '分类2', nameEn: 'Category 2', templates: [] },
|
||||
{ id: 'cat-3', name: '分类3', nameEn: 'Category 3', templates: [] },
|
||||
]
|
||||
|
||||
describe('useTabNavigation - core logic', () => {
|
||||
describe('initialization', () => {
|
||||
it('should select first category when initialCategoryId is empty', () => {
|
||||
@@ -256,4 +263,41 @@ describe('useTabNavigation - core logic', () => {
|
||||
expect(state.currentCategory).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('multi-language support', () => {
|
||||
it('should generate tabs with Chinese names when language is zh-CN', () => {
|
||||
// 模拟中文环境
|
||||
const language = 'zh-CN'
|
||||
const tabs = mockCategoriesWithI18n.map(cat =>
|
||||
language === 'en-US' ? cat.nameEn : cat.name
|
||||
)
|
||||
|
||||
expect(tabs).toEqual(['分类1', '分类2', '分类3'])
|
||||
})
|
||||
|
||||
it('should generate tabs with English names when language is en-US', () => {
|
||||
// 模拟英文环境
|
||||
const language = 'en-US'
|
||||
const tabs = mockCategoriesWithI18n.map(cat =>
|
||||
language === 'en-US' ? cat.nameEn : cat.name
|
||||
)
|
||||
|
||||
expect(tabs).toEqual(['Category 1', 'Category 2', 'Category 3'])
|
||||
})
|
||||
|
||||
it('should fallback to Chinese name when nameEn is missing', () => {
|
||||
const categoriesWithMissingEn = [
|
||||
{ id: 'cat-1', name: '分类1', nameEn: 'Category 1' },
|
||||
{ id: 'cat-2', name: '分类2', nameEn: '' }, // nameEn 为空
|
||||
{ id: 'cat-3', name: '分类3' }, // 没有 nameEn 字段
|
||||
]
|
||||
|
||||
const language = 'en-US'
|
||||
const tabs = categoriesWithMissingEn.map(cat =>
|
||||
language === 'en-US' && cat.nameEn ? cat.nameEn : cat.name
|
||||
)
|
||||
|
||||
expect(tabs).toEqual(['Category 1', '分类2', '分类3'])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user