@@ -10,13 +10,13 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
1010import AsyncContent , {
1111 Props ,
1212} from "../../../src/ts/components/common/AsyncContent" ;
13- import * as Notifications from "../../../src/ts/elements /notifications" ;
13+ import * as Notifications from "../../../src/ts/stores /notifications" ;
1414
1515describe ( "AsyncContent" , ( ) => {
16- const addNotificationMock = vi . spyOn ( Notifications , "add " ) ;
16+ const notifyErrorMock = vi . spyOn ( Notifications , "showErrorNotification " ) ;
1717
1818 beforeEach ( ( ) => {
19- addNotificationMock . mockClear ( ) ;
19+ notifyErrorMock . mockClear ( ) ;
2020 } ) ;
2121
2222 describe ( "with single query" , ( ) => {
@@ -55,30 +55,30 @@ describe("AsyncContent", () => {
5555 } ) ;
5656
5757 it ( "renders default error message on fail" , async ( ) => {
58- renderWithQuery ( { result : new Error ( "Test error" ) } ) ;
58+ const error = new Error ( "Test error" ) ;
59+ renderWithQuery ( { result : error } ) ;
5960
6061 await waitFor ( ( ) => {
6162 expect ( screen . getByText ( / A n e r r o r o c c u r r e d / ) ) . toBeInTheDocument ( ) ;
6263 } ) ;
63- expect ( addNotificationMock ) . toHaveBeenCalledWith (
64- "An error occurred: Test error" ,
65- - 1 ,
66- ) ;
64+ expect ( notifyErrorMock ) . toHaveBeenCalledWith ( "An error occurred" , {
65+ error,
66+ } ) ;
6767 } ) ;
6868
6969 it ( "renders custom error message on fail" , async ( ) => {
70+ const error = new Error ( "Test error" ) ;
7071 renderWithQuery (
71- { result : new Error ( "Test error" ) } ,
72+ { result : error } ,
7273 { errorMessage : "Custom error message" } ,
7374 ) ;
7475
7576 await waitFor ( ( ) => {
7677 expect ( screen . getByText ( / C u s t o m e r r o r m e s s a g e / ) ) . toBeInTheDocument ( ) ;
7778 } ) ;
78- expect ( addNotificationMock ) . toHaveBeenCalledWith (
79- "Custom error message: Test error" ,
80- - 1 ,
81- ) ;
79+ expect ( notifyErrorMock ) . toHaveBeenCalledWith ( "Custom error message" , {
80+ error,
81+ } ) ;
8282 } ) ;
8383
8484 it ( "ignores error on fail if ignoreError is set" , async ( ) => {
@@ -89,7 +89,7 @@ describe("AsyncContent", () => {
8989 await waitFor ( ( ) => {
9090 expect ( screen . getByText ( / n o d a t a / ) ) . toBeInTheDocument ( ) ;
9191 } ) ;
92- expect ( addNotificationMock ) . not . toHaveBeenCalled ( ) ;
92+ expect ( notifyErrorMock ) . not . toHaveBeenCalled ( ) ;
9393 } ) ;
9494
9595 it ( "renders on pending if alwaysShowContent" , async ( ) => {
@@ -111,18 +111,18 @@ describe("AsyncContent", () => {
111111 } ) ;
112112
113113 it ( "renders on fail if alwaysShowContent" , async ( ) => {
114+ const error = new Error ( "Test error" ) ;
114115 renderWithQuery (
115- { result : new Error ( "Test error" ) } ,
116+ { result : error } ,
116117 { errorMessage : "Custom error message" } ,
117118 ) ;
118119
119120 await waitFor ( ( ) => {
120121 expect ( screen . getByText ( / C u s t o m e r r o r m e s s a g e / ) ) . toBeInTheDocument ( ) ;
121122 } ) ;
122- expect ( addNotificationMock ) . toHaveBeenCalledWith (
123- "Custom error message: Test error" ,
124- - 1 ,
125- ) ;
123+ expect ( notifyErrorMock ) . toHaveBeenCalledWith ( "Custom error message" , {
124+ error,
125+ } ) ;
126126 } ) ;
127127
128128 function renderWithQuery (
@@ -216,30 +216,30 @@ describe("AsyncContent", () => {
216216 } ) ;
217217
218218 it ( "renders default error message on fail" , async ( ) => {
219- renderWithQuery ( { first : "data" , second : new Error ( "Test error" ) } ) ;
219+ const error = new Error ( "Test error" ) ;
220+ renderWithQuery ( { first : "data" , second : error } ) ;
220221
221222 await waitFor ( ( ) => {
222223 expect ( screen . getByText ( / A n e r r o r o c c u r r e d / ) ) . toBeInTheDocument ( ) ;
223224 } ) ;
224- expect ( addNotificationMock ) . toHaveBeenCalledWith (
225- "An error occurred: Test error" ,
226- - 1 ,
227- ) ;
225+ expect ( notifyErrorMock ) . toHaveBeenCalledWith ( "An error occurred" , {
226+ error,
227+ } ) ;
228228 } ) ;
229229
230230 it ( "renders custom error message on fail" , async ( ) => {
231+ const firstError = new Error ( "First error" ) ;
231232 renderWithQuery (
232- { first : new Error ( "First error" ) , second : new Error ( "Second error" ) } ,
233+ { first : firstError , second : new Error ( "Second error" ) } ,
233234 { errorMessage : "Custom error message" } ,
234235 ) ;
235236
236237 await waitFor ( ( ) => {
237238 expect ( screen . getByText ( / C u s t o m e r r o r m e s s a g e / ) ) . toBeInTheDocument ( ) ;
238239 } ) ;
239- expect ( addNotificationMock ) . toHaveBeenCalledWith (
240- "Custom error message: First error" ,
241- - 1 ,
242- ) ;
240+ expect ( notifyErrorMock ) . toHaveBeenCalledWith ( "Custom error message" , {
241+ error : firstError ,
242+ } ) ;
243243 } ) ;
244244
245245 it ( "ignores error on fail if ignoreError is set" , async ( ) => {
@@ -252,7 +252,7 @@ describe("AsyncContent", () => {
252252 expect ( screen . getByText ( / n o d a t a / ) ) . toBeInTheDocument ( ) ;
253253 } ) ;
254254
255- expect ( addNotificationMock ) . not . toHaveBeenCalled ( ) ;
255+ expect ( notifyErrorMock ) . not . toHaveBeenCalled ( ) ;
256256 } ) ;
257257
258258 it ( "renders on pending if alwaysShowContent" , async ( ) => {
@@ -287,18 +287,18 @@ describe("AsyncContent", () => {
287287 } ) ;
288288
289289 it ( "renders on fail if alwaysShowContent" , async ( ) => {
290+ const error = new Error ( "Test error" ) ;
290291 renderWithQuery (
291- { first : "data" , second : new Error ( "Test error" ) } ,
292+ { first : "data" , second : error } ,
292293 { errorMessage : "Custom error message" } ,
293294 ) ;
294295
295296 await waitFor ( ( ) => {
296297 expect ( screen . getByText ( / C u s t o m e r r o r m e s s a g e / ) ) . toBeInTheDocument ( ) ;
297298 } ) ;
298- expect ( addNotificationMock ) . toHaveBeenCalledWith (
299- "Custom error message: Test error" ,
300- - 1 ,
301- ) ;
299+ expect ( notifyErrorMock ) . toHaveBeenCalledWith ( "Custom error message" , {
300+ error,
301+ } ) ;
302302 } ) ;
303303
304304 function renderWithQuery (
0 commit comments