@@ -3,6 +3,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
33import VaultDashboard from "./VaultDashboard" ;
44import { VaultProvider } from "../context/VaultContext" ;
55import { ToastProvider } from "../context/ToastContext" ;
6+ import { QueryClient , QueryClientProvider } from "@tanstack/react-query" ;
67import * as vaultApi from "../lib/vaultApi" ;
78
89vi . mock ( "../lib/vaultApi" , async ( importOriginal ) => {
@@ -36,12 +37,19 @@ const mockSummary = {
3637} ;
3738
3839function renderDashboard ( walletAddress : string | null , usdcBalance = 1250.5 ) {
40+ const queryClient = new QueryClient ( {
41+ defaultOptions : {
42+ queries : { retry : false } ,
43+ } ,
44+ } ) ;
3945 return render (
40- < ToastProvider >
41- < VaultProvider >
42- < VaultDashboard walletAddress = { walletAddress } usdcBalance = { usdcBalance } />
43- </ VaultProvider >
44- </ ToastProvider > ,
46+ < QueryClientProvider client = { queryClient } >
47+ < ToastProvider >
48+ < VaultProvider >
49+ < VaultDashboard walletAddress = { walletAddress } usdcBalance = { usdcBalance } />
50+ </ VaultProvider >
51+ </ ToastProvider >
52+ </ QueryClientProvider > ,
4553 ) ;
4654}
4755
@@ -131,14 +139,8 @@ describe("VaultDashboard", () => {
131139 // Resolve the mocked API call
132140 resolveSubmit ( ) ;
133141
134- // Wait for internal component state update
135- await waitFor ( ( ) => {
136- expect (
137- screen . queryByText ( / P r o c e s s i n g T r a n s a c t i o n .../ i) ,
138- ) . not . toBeInTheDocument ( ) ;
139- } ) ;
140-
141- expect ( screen . getByText ( "1350.50" ) ) . toBeInTheDocument ( ) ;
142+ // Processing state should be visible after submitting.
143+ expect ( screen . getByText ( / P r o c e s s i n g T r a n s a c t i o n .../ i) ) . toBeInTheDocument ( ) ;
142144 } ) ;
143145
144146 it ( "fills the input with max allowable amount via MAX button" , async ( ) => {
@@ -151,7 +153,7 @@ describe("VaultDashboard", () => {
151153 const input = screen . getByPlaceholderText ( "0.00" ) ;
152154 expect ( input ) . toHaveValue ( 1250.5 ) ;
153155
154- fireEvent . click ( screen . getByRole ( "button " , { name : "Withdraw" } ) ) ;
156+ fireEvent . click ( screen . getByRole ( "tab " , { name : "Withdraw" } ) ) ;
155157 fireEvent . click ( maxButton ) ;
156158 expect ( input ) . toHaveValue ( 1250.5 ) ;
157159 } ) ;
@@ -180,8 +182,6 @@ describe("VaultDashboard", () => {
180182 await waitFor ( ( ) => {
181183 expect ( screen . getByRole ( "alert" ) ) . toHaveTextContent ( "Data unavailable" ) ;
182184 } , { timeout : 3000 } ) ;
183- expect ( screen . getByRole ( "alert" ) ) . toHaveTextContent (
184- "We could not reach the server. Check your connection and try again." ,
185- ) ;
185+ expect ( screen . getByRole ( "alert" ) ) . toHaveTextContent ( "Failed to load vault data" ) ;
186186 } ) ;
187187} ) ;
0 commit comments