From 6a27d2c0e8c9062d40b7ca0f0f07371c5293907b Mon Sep 17 00:00:00 2001 From: defiQUG Date: Thu, 16 Apr 2026 13:48:23 -0700 Subject: [PATCH] Fix dashboard trend test expectations --- frontend/src/utils/dashboard.test.ts | 51 +++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/frontend/src/utils/dashboard.test.ts b/frontend/src/utils/dashboard.test.ts index 144126d..9bab6be 100644 --- a/frontend/src/utils/dashboard.test.ts +++ b/frontend/src/utils/dashboard.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it, vi } from 'vitest' 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' 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', () => { it('returns both stats and recent blocks when both loaders succeed', async () => { const result = await loadDashboardData({ @@ -33,6 +44,7 @@ describe('loadDashboardData', () => { expect(result).toEqual({ stats: sampleStats, recentBlocks: sampleBlocks, + recentTransactionTrend: [], }) }) @@ -50,6 +62,7 @@ describe('loadDashboardData', () => { expect(result).toEqual({ stats: null, recentBlocks: sampleBlocks, + recentTransactionTrend: [], }) expect(onError).toHaveBeenCalledTimes(1) expect(onError).toHaveBeenCalledWith('stats', expect.any(Error)) @@ -69,8 +82,44 @@ describe('loadDashboardData', () => { expect(result).toEqual({ stats: sampleStats, recentBlocks: [], + recentTransactionTrend: [], }) expect(onError).toHaveBeenCalledTimes(1) 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)) + }) })