This commit is contained in:
imeepos
2026-01-28 18:46:44 +08:00
parent e478b126cd
commit 7c50d396e9
40 changed files with 6567 additions and 39 deletions

View File

@@ -123,4 +123,153 @@ describe('TemplateCard Component', () => {
expect(displayTitle).toBe('测试模板')
})
})
describe('Liked and Favorited Props', () => {
it('should accept liked prop without error', () => {
const props = {
id: '123',
title: 'Test Template',
cardWidth: 200,
onPress: jest.fn(),
liked: true,
}
// 测试 props 类型是否正确
expect(props.liked).toBeDefined()
expect(typeof props.liked).toBe('boolean')
})
it('should accept favorited prop without error', () => {
const props = {
id: '123',
title: 'Test Template',
cardWidth: 200,
onPress: jest.fn(),
favorited: true,
}
// 测试 props 类型是否正确
expect(props.favorited).toBeDefined()
expect(typeof props.favorited).toBe('boolean')
})
it('should accept both liked and favorited props', () => {
const props = {
id: '123',
title: 'Test Template',
cardWidth: 200,
onPress: jest.fn(),
liked: true,
favorited: false,
}
// 测试两个 props 可以同时存在
expect(props.liked).toBeDefined()
expect(props.favorited).toBeDefined()
})
it('should handle undefined liked prop', () => {
const props = {
id: '123',
title: 'Test Template',
cardWidth: 200,
onPress: jest.fn(),
liked: undefined,
}
// 测试 liked prop 可以是 undefined
expect(props.liked).toBeUndefined()
})
it('should handle undefined favorited prop', () => {
const props = {
id: '123',
title: 'Test Template',
cardWidth: 200,
onPress: jest.fn(),
favorited: undefined,
}
// 测试 favorited prop 可以是 undefined
expect(props.favorited).toBeUndefined()
})
})
describe('Icon Display Logic', () => {
it('should show heart icon when liked is true', () => {
const liked = true
const iconName = liked ? 'heart' : 'heart-outline'
expect(iconName).toBe('heart')
})
it('should show heart-outline icon when liked is false', () => {
const liked = false
const iconName = liked ? 'heart' : 'heart-outline'
expect(iconName).toBe('heart-outline')
})
it('should show heart-outline icon when liked is undefined', () => {
const liked = undefined
const iconName = liked ? 'heart' : 'heart-outline'
expect(iconName).toBe('heart-outline')
})
it('should show red color when liked is true', () => {
const liked = true
const iconColor = liked ? '#FF3B30' : 'rgba(142, 142, 147, 0.7)'
expect(iconColor).toBe('#FF3B30')
})
it('should show gray color when liked is false', () => {
const liked = false
const iconColor = liked ? '#FF3B30' : 'rgba(142, 142, 147, 0.7)'
expect(iconColor).toBe('rgba(142, 142, 147, 0.7)')
})
it('should show star icon when favorited is true', () => {
const favorited = true
const iconName = favorited ? 'star' : 'star-outline'
expect(iconName).toBe('star')
})
it('should show star-outline icon when favorited is false', () => {
const favorited = false
const iconName = favorited ? 'star' : 'star-outline'
expect(iconName).toBe('star-outline')
})
it('should show star-outline icon when favorited is undefined', () => {
const favorited = undefined
const iconName = favorited ? 'star' : 'star-outline'
expect(iconName).toBe('star-outline')
})
it('should show gold color when favorited is true', () => {
const favorited = true
const iconColor = favorited ? '#FFD700' : 'rgba(142, 142, 147, 0.7)'
expect(iconColor).toBe('#FFD700')
})
it('should show gray color when favorited is false', () => {
const favorited = false
const iconColor = favorited ? '#FFD700' : 'rgba(142, 142, 147, 0.7)'
expect(iconColor).toBe('rgba(142, 142, 147, 0.7)')
})
it('should have icon size of 16', () => {
const iconSize = 16
expect(iconSize).toBe(16)
})
})
})