11import { WebsocketProvider } from "y-websocket" ;
22import { handleWsClose } from "./closeHandler" ;
3+ import { showConnectionErrorAndReload } from "./connectionErrorHandler" ;
34import { setErrorData } from "./errorData" ;
45import { redirectToErrorPage } from "./redirectUtils" ;
56
67describe ( "closeHandler" , ( ) => {
78 beforeAll ( ( ) => {
9+ vi . mock ( "./connectionErrorHandler" , { spy : true } ) ;
810 vi . mock ( "./errorData" , { spy : true } ) ;
911 vi . mock ( "./redirectUtils" , { spy : true } ) ;
1012 } ) ;
@@ -27,14 +29,17 @@ describe("closeHandler", () => {
2729 return { event, providerMock } ;
2830 } ;
2931
30- it ( "should not call setErrorData or redirectToErrorPage nor disconnect " , ( ) => {
32+ it ( "should disconnect and call showConnectionErrorAndReload but not setErrorData or redirectToErrorPage" , ( ) => {
3133 const { event, providerMock } = setup ( ) ;
3234
3335 handleWsClose ( event , providerMock ) ;
3436
37+ expect ( providerMock . disconnect ) . toHaveBeenCalled ( ) ;
38+ expect ( showConnectionErrorAndReload ) . toHaveBeenCalledWith (
39+ "Connection to server lost. The page will reload in 10 seconds..." ,
40+ ) ;
3541 expect ( setErrorData ) . not . toHaveBeenCalled ( ) ;
3642 expect ( redirectToErrorPage ) . not . toHaveBeenCalled ( ) ;
37- expect ( providerMock . disconnect ) . not . toHaveBeenCalled ( ) ;
3843 } ) ;
3944 } ) ;
4045
0 commit comments