test(site): cover chart tooltip formatters

This commit is contained in:
jxxghp
2026-08-06 08:01:10 +08:00
parent 6fd259427e
commit fd1bf8df7f
@@ -148,6 +148,15 @@ describe('SiteUserDataDialog projections', () => {
expect((history.options.xaxis as { categories: string[] }).categories).toEqual(['2026-07-17', '2026-07-19']) expect((history.options.xaxis as { categories: string[] }).categories).toEqual(['2026-07-17', '2026-07-19'])
expect((history.options.theme as { mode: string }).mode).toBe('light') expect((history.options.theme as { mode: string }).mode).toBe('light')
expect((history.options.chart as { background: string; foreColor: string }).background).toBeTruthy() expect((history.options.chart as { background: string; foreColor: string }).background).toBeTruthy()
expect((history.options.tooltip as { x: { formatter: (value: string) => string } }).x.formatter('2026-07-19')).toBe(
new Date('2026-07-19').toLocaleDateString('zh-CN', {
month: 'short',
day: 'numeric',
}),
)
expect((history.options.tooltip as { y: { formatter: (value: number) => string } }).y.formatter(1234)).toBe(
`${(1234).toLocaleString()} GB`,
)
expect( expect(
(history.options.xaxis as { labels: { formatter: (value: string) => string } }).labels.formatter('2026-07-19'), (history.options.xaxis as { labels: { formatter: (value: string) => string } }).labels.formatter('2026-07-19'),
).toBe( ).toBe(
@@ -174,6 +183,9 @@ describe('SiteUserDataDialog projections', () => {
expect((seeding.options.tooltip as { x: { formatter: (value: number) => string } }).x.formatter(1234)).toBe( expect((seeding.options.tooltip as { x: { formatter: (value: number) => string } }).x.formatter(1234)).toBe(
`数量:${(1234).toLocaleString()}`, `数量:${(1234).toLocaleString()}`,
) )
expect((seeding.options.tooltip as { y: { formatter: (value: number) => string } }).y.formatter(2048)).toBe(
`${(2048).toLocaleString()} GB`,
)
expect((seeding.options.xaxis as { labels: { formatter: (value: number) => string } }).labels.formatter(1.6)).toBe( expect((seeding.options.xaxis as { labels: { formatter: (value: number) => string } }).labels.formatter(1.6)).toBe(
'2', '2',
) )