Files
SubTracker/apps/web/tests/unit/utils/statistics-top-subscriptions.test.ts
SmileQWQ afe7fcdeb7 fix: finish web locale utilities and ignore local scratch dirs
- remove the last frontend locale branches from reminder, currency and timezone helpers and keep the rendered copy on shared messages only

- align settings and statistics web tests with the new locale-aware helper behavior and reminder preview wording

- ignore .tmp and docs workspace scratch directories so the i18n branch stays clean while local analysis notes remain untracked
2026-05-17 22:45:16 +08:00

47 lines
1.3 KiB
TypeScript
Raw Permalink 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 { describe, expect, it } from 'vitest'
import { buildTopSubscriptionsOption } from '../../../src/utils/statistics-top-subscriptions'
describe('buildTopSubscriptionsOption', () => {
it('returns null when there is no data', () => {
expect(buildTopSubscriptionsOption([], 'CNY')).toBeNull()
})
it('builds a horizontal bar chart option from top subscription data', () => {
const option = buildTopSubscriptionsOption(
[
{
id: 'a',
name: 'Netflix',
amount: 120,
currency: 'USD',
monthlyAmountBase: 88,
baseCurrency: 'CNY'
}
],
'CNY'
)
expect(option?.yAxis.data).toEqual(['Netflix'])
expect(option?.yAxis.inverse).toBe(true)
expect(option?.xAxis.name).toBe('金额CNY')
expect(option?.series[0].data).toEqual([88])
})
it('limits the chart to the first 10 items', () => {
const option = buildTopSubscriptionsOption(
Array.from({ length: 12 }, (_, index) => ({
id: `${index + 1}`,
name: `Subscription ${index + 1}`,
amount: index + 1,
currency: 'CNY',
monthlyAmountBase: index + 1,
baseCurrency: 'CNY'
})),
'CNY'
)
expect(option?.yAxis.data).toHaveLength(10)
expect(option?.series[0].data).toHaveLength(10)
})
})