mirror of
https://github.com/Smile-QWQ/SubTracker.git
synced 2026-06-04 00:01:36 +08:00
- 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
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
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)
|
||
})
|
||
})
|