gongxiangp2/components/department-dashboard/performance-conversion.test.ts

39 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {
BUSINESS_TREND_BRANDS,
addCalendarMonths,
daysBetweenInclusive,
extractValidProductIds,
isValidDateKey,
toShanghaiDateKey,
} from './performance-conversion'
describe('performance conversion helpers', () => {
it('keeps the requested six brands in the agreed order', () => {
expect(BUSINESS_TREND_BRANDS).toEqual(['亿家达', '卓禾', '欧意朗', '顾家', '索菲亚', '朴美'])
})
it('extracts and de-duplicates numeric product ids while rejecting placeholders', () => {
expect(extractValidProductIds(
'1077434823611 / 1077434823611',
'970584740986,新品暂无;0',
null,
)).toEqual(['1077434823611', '970584740986'])
})
it('adds six calendar months with month-end clamping', () => {
expect(addCalendarMonths('2026-03-31', 6)).toBe('2026-09-30')
expect(addCalendarMonths('2024-08-31', 6)).toBe('2025-02-28')
})
it('uses Shanghai dates and inclusive coverage days', () => {
expect(toShanghaiDateKey('2026-03-31T16:00:00.000Z')).toBe('2026-04-01')
expect(daysBetweenInclusive('2026-04-01', '2026-04-03')).toBe(3)
})
it('validates real calendar date keys', () => {
expect(isValidDateKey('2026-09-17')).toBe(true)
expect(isValidDateKey('2026-02-29')).toBe(false)
expect(isValidDateKey('2026-9-17')).toBe(false)
})
})