KNOWN-007: solarTime.ts 单元测试 KNOWN-008: 消除生产代码中 as any 类型断言 KNOWN-002: 工具层测试覆盖 KNOWN-003: lruCache 边界测试 KNOWN-004: templateService 分支覆盖(100%) KNOWN-001: 6个业务组件测试 额外修复: searchOptimizer memoize bug, templateService 常量修改 bug 测试覆盖率: 75.71% -> 90.22%, 测试用例: 412 -> 671
107 lines
3.1 KiB
TypeScript
107 lines
3.1 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { mount } from '@vue/test-utils'
|
|
import { createI18n } from 'vue-i18n'
|
|
import zhCN from '../../../locales/zh-CN'
|
|
import SearchResultCard from '../index.vue'
|
|
import type { SearchResult } from '../../../types/search'
|
|
|
|
const i18n = createI18n({
|
|
legacy: false,
|
|
locale: 'zh-CN',
|
|
messages: { 'zh-CN': zhCN },
|
|
})
|
|
|
|
function createMockResult(overrides: Partial<SearchResult> = {}): SearchResult {
|
|
return {
|
|
date: '2026-08-15',
|
|
lunarDate: '农历七月初三',
|
|
weekday: '星期六',
|
|
matchedItems: {
|
|
suitable: ['祭祀', '嫁娶'],
|
|
unsuitable: ['出行', '安葬'],
|
|
},
|
|
matchCount: 4,
|
|
almanacData: {},
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
function createWrapper(result: SearchResult) {
|
|
return mount(SearchResultCard, {
|
|
global: {
|
|
plugins: [i18n],
|
|
stubs: {
|
|
Card: true,
|
|
Typography: true,
|
|
},
|
|
},
|
|
props: { result },
|
|
})
|
|
}
|
|
|
|
describe('SearchResultCard', () => {
|
|
it('renders result data', () => {
|
|
const result = createMockResult()
|
|
const wrapper = createWrapper(result)
|
|
expect(wrapper.find('.search-result-card').exists()).toBe(true)
|
|
})
|
|
|
|
it('renders date and weekday', () => {
|
|
const result = createMockResult()
|
|
const wrapper = createWrapper(result)
|
|
expect(wrapper.props('result').date).toBe('2026-08-15')
|
|
expect(wrapper.props('result').weekday).toBe('星期六')
|
|
})
|
|
|
|
it('renders lunar date', () => {
|
|
const result = createMockResult()
|
|
const wrapper = createWrapper(result)
|
|
expect(wrapper.props('result').lunarDate).toBe('农历七月初三')
|
|
})
|
|
|
|
it('renders suitable items when present', () => {
|
|
const result = createMockResult()
|
|
const wrapper = createWrapper(result)
|
|
expect(wrapper.props('result').matchedItems.suitable).toEqual(['祭祀', '嫁娶'])
|
|
})
|
|
|
|
it('renders unsuitable items when present', () => {
|
|
const result = createMockResult()
|
|
const wrapper = createWrapper(result)
|
|
expect(wrapper.props('result').matchedItems.unsuitable).toEqual(['出行', '安葬'])
|
|
})
|
|
|
|
it('renders match count', () => {
|
|
const result = createMockResult()
|
|
const wrapper = createWrapper(result)
|
|
expect(wrapper.props('result').matchCount).toBe(4)
|
|
})
|
|
|
|
it('handles empty suitable items', () => {
|
|
const result = createMockResult({
|
|
matchedItems: { suitable: [], unsuitable: ['安葬'] },
|
|
matchCount: 1,
|
|
})
|
|
const wrapper = createWrapper(result)
|
|
expect(wrapper.props('result').matchedItems.suitable).toEqual([])
|
|
})
|
|
|
|
it('handles empty unsuitable items', () => {
|
|
const result = createMockResult({
|
|
matchedItems: { suitable: ['祭祀'], unsuitable: [] },
|
|
matchCount: 1,
|
|
})
|
|
const wrapper = createWrapper(result)
|
|
expect(wrapper.props('result').matchedItems.unsuitable).toEqual([])
|
|
})
|
|
|
|
it('handles all empty matched items', () => {
|
|
const result = createMockResult({
|
|
matchedItems: { suitable: [], unsuitable: [] },
|
|
matchCount: 0,
|
|
})
|
|
const wrapper = createWrapper(result)
|
|
expect(wrapper.props('result').matchedItems.suitable).toEqual([])
|
|
expect(wrapper.props('result').matchedItems.unsuitable).toEqual([])
|
|
})
|
|
}) |