Fix dashboard trend test expectations
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { describe, expect, it, vi } from 'vitest'
|
import { describe, expect, it, vi } from 'vitest'
|
||||||
import type { Block } from '@/services/api/blocks'
|
import type { Block } from '@/services/api/blocks'
|
||||||
import type { ExplorerStats } from '@/services/api/stats'
|
import type { ExplorerStats, ExplorerTransactionTrendPoint } from '@/services/api/stats'
|
||||||
import { loadDashboardData } from './dashboard'
|
import { loadDashboardData } from './dashboard'
|
||||||
|
|
||||||
const sampleStats: ExplorerStats = {
|
const sampleStats: ExplorerStats = {
|
||||||
@@ -23,6 +23,17 @@ const sampleBlocks: Block[] = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const sampleTrend: ExplorerTransactionTrendPoint[] = [
|
||||||
|
{
|
||||||
|
date: '2026-04-03',
|
||||||
|
count: 11,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: '2026-04-04',
|
||||||
|
count: 17,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
describe('loadDashboardData', () => {
|
describe('loadDashboardData', () => {
|
||||||
it('returns both stats and recent blocks when both loaders succeed', async () => {
|
it('returns both stats and recent blocks when both loaders succeed', async () => {
|
||||||
const result = await loadDashboardData({
|
const result = await loadDashboardData({
|
||||||
@@ -33,6 +44,7 @@ describe('loadDashboardData', () => {
|
|||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
stats: sampleStats,
|
stats: sampleStats,
|
||||||
recentBlocks: sampleBlocks,
|
recentBlocks: sampleBlocks,
|
||||||
|
recentTransactionTrend: [],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -50,6 +62,7 @@ describe('loadDashboardData', () => {
|
|||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
stats: null,
|
stats: null,
|
||||||
recentBlocks: sampleBlocks,
|
recentBlocks: sampleBlocks,
|
||||||
|
recentTransactionTrend: [],
|
||||||
})
|
})
|
||||||
expect(onError).toHaveBeenCalledTimes(1)
|
expect(onError).toHaveBeenCalledTimes(1)
|
||||||
expect(onError).toHaveBeenCalledWith('stats', expect.any(Error))
|
expect(onError).toHaveBeenCalledWith('stats', expect.any(Error))
|
||||||
@@ -69,8 +82,44 @@ describe('loadDashboardData', () => {
|
|||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
stats: sampleStats,
|
stats: sampleStats,
|
||||||
recentBlocks: [],
|
recentBlocks: [],
|
||||||
|
recentTransactionTrend: [],
|
||||||
})
|
})
|
||||||
expect(onError).toHaveBeenCalledTimes(1)
|
expect(onError).toHaveBeenCalledTimes(1)
|
||||||
expect(onError).toHaveBeenCalledWith('blocks', expect.any(Error))
|
expect(onError).toHaveBeenCalledWith('blocks', expect.any(Error))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('returns the recent transaction trend when the optional loader succeeds', async () => {
|
||||||
|
const result = await loadDashboardData({
|
||||||
|
loadStats: async () => sampleStats,
|
||||||
|
loadRecentBlocks: async () => sampleBlocks,
|
||||||
|
loadRecentTransactionTrend: async () => sampleTrend,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
stats: sampleStats,
|
||||||
|
recentBlocks: sampleBlocks,
|
||||||
|
recentTransactionTrend: sampleTrend,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('falls back to an empty recent transaction trend when the optional loader fails', async () => {
|
||||||
|
const onError = vi.fn()
|
||||||
|
|
||||||
|
const result = await loadDashboardData({
|
||||||
|
loadStats: async () => sampleStats,
|
||||||
|
loadRecentBlocks: async () => sampleBlocks,
|
||||||
|
loadRecentTransactionTrend: async () => {
|
||||||
|
throw new Error('trend unavailable')
|
||||||
|
},
|
||||||
|
onError,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
stats: sampleStats,
|
||||||
|
recentBlocks: sampleBlocks,
|
||||||
|
recentTransactionTrend: [],
|
||||||
|
})
|
||||||
|
expect(onError).toHaveBeenCalledTimes(1)
|
||||||
|
expect(onError).toHaveBeenCalledWith('trend', expect.any(Error))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user