@@ -7,13 +7,11 @@ import { WEBSOCKET_CLOSE_CODES } from "@bus/workers/websocket_worker";
77import { describe , expect , test } from "@odoo/hoot" ;
88import { manuallyDispatchProgrammaticEvent , runAllTimers } from "@odoo/hoot-dom" ;
99import {
10- asyncStep ,
1110 getService ,
1211 makeMockEnv ,
1312 MockServer ,
1413 mockService ,
1514 patchWithCleanup ,
16- waitForSteps ,
1715} from "@web/../tests/web_test_helpers" ;
1816
1917defineBusModels ( ) ;
@@ -26,7 +24,7 @@ function stepConnectionStateChanges() {
2624 } ,
2725 set isConnectionLost ( value ) {
2826 if ( value !== this . _isConnectionLost ) {
29- asyncStep ( `isConnectionLost - ${ value } ` ) ;
27+ expect . step ( `isConnectionLost - ${ value } ` ) ;
3028 }
3129 this . _isConnectionLost = value ;
3230 } ,
@@ -36,53 +34,53 @@ function stepConnectionStateChanges() {
3634test ( "connection considered as lost after failed reconnect attempt" , async ( ) => {
3735 stepConnectionStateChanges ( ) ;
3836 addBusServiceListeners (
39- [ "BUS:CONNECT" , ( ) => asyncStep ( "BUS:CONNECT" ) ] ,
40- [ "BUS:DISCONNECT" , ( ) => asyncStep ( "BUS:DISCONNECT" ) ]
37+ [ "BUS:CONNECT" , ( ) => expect . step ( "BUS:CONNECT" ) ] ,
38+ [ "BUS:DISCONNECT" , ( ) => expect . step ( "BUS:DISCONNECT" ) ]
4139 ) ;
4240 await makeMockEnv ( ) ;
43- await waitForSteps ( [ "isConnectionLost - false" , "BUS:CONNECT" ] ) ;
41+ await expect . waitForSteps ( [ "isConnectionLost - false" , "BUS:CONNECT" ] ) ;
4442 const unlockWebsocket = lockWebsocketConnect ( ) ;
4543 MockServer . env [ "bus.bus" ] . _simulateDisconnection ( WEBSOCKET_CLOSE_CODES . ABNORMAL_CLOSURE ) ;
46- await waitForSteps ( [ "BUS:DISCONNECT" ] ) ;
44+ await expect . waitForSteps ( [ "BUS:DISCONNECT" ] ) ;
4745 await runAllTimers ( ) ;
48- await waitForSteps ( [ "isConnectionLost - true" ] ) ;
46+ await expect . waitForSteps ( [ "isConnectionLost - true" ] ) ;
4947 unlockWebsocket ( ) ;
5048 await runAllTimers ( ) ;
51- await waitForSteps ( [ "isConnectionLost - false" ] ) ;
49+ await expect . waitForSteps ( [ "isConnectionLost - false" ] ) ;
5250} ) ;
5351
5452test ( "brief disconect not considered lost" , async ( ) => {
5553 stepConnectionStateChanges ( ) ;
5654 addBusServiceListeners (
57- [ "BUS:CONNECT" , ( ) => asyncStep ( "BUS:CONNECT" ) ] ,
58- [ "BUS:DISCONNECT" , ( ) => asyncStep ( "BUS:DISCONNECT" ) ] ,
59- [ "BUS:RECONNECT" , ( ) => asyncStep ( "BUS:RECONNECT" ) ]
55+ [ "BUS:CONNECT" , ( ) => expect . step ( "BUS:CONNECT" ) ] ,
56+ [ "BUS:DISCONNECT" , ( ) => expect . step ( "BUS:DISCONNECT" ) ] ,
57+ [ "BUS:RECONNECT" , ( ) => expect . step ( "BUS:RECONNECT" ) ]
6058 ) ;
6159 await makeMockEnv ( ) ;
62- await waitForSteps ( [ "isConnectionLost - false" , "BUS:CONNECT" ] ) ;
60+ await expect . waitForSteps ( [ "isConnectionLost - false" , "BUS:CONNECT" ] ) ;
6361 MockServer . env [ "bus.bus" ] . _simulateDisconnection ( WEBSOCKET_CLOSE_CODES . SESSION_EXPIRED ) ;
64- await waitForSteps ( [ "BUS:DISCONNECT" ] ) ;
62+ await expect . waitForSteps ( [ "BUS:DISCONNECT" ] ) ;
6563 await runAllTimers ( ) ;
66- await waitForSteps ( [ "BUS:RECONNECT" ] ) ; // Only reconnect step, which means the monitoring state didn't change.
64+ await expect . waitForSteps ( [ "BUS:RECONNECT" ] ) ; // Only reconnect step, which means the monitoring state didn't change.
6765} ) ;
6866
6967test ( "computer sleep doesn't mark connection as lost" , async ( ) => {
7068 stepConnectionStateChanges ( ) ;
7169 addBusServiceListeners (
72- [ "BUS:CONNECT" , ( ) => asyncStep ( "BUS:CONNECT" ) ] ,
73- [ "BUS:DISCONNECT" , ( ) => asyncStep ( "BUS:DISCONNECT" ) ] ,
74- [ "BUS:RECONNECT" , ( ) => asyncStep ( "BUS:RECONNECT" ) ]
70+ [ "BUS:CONNECT" , ( ) => expect . step ( "BUS:CONNECT" ) ] ,
71+ [ "BUS:DISCONNECT" , ( ) => expect . step ( "BUS:DISCONNECT" ) ] ,
72+ [ "BUS:RECONNECT" , ( ) => expect . step ( "BUS:RECONNECT" ) ]
7573 ) ;
7674 await makeMockEnv ( ) ;
77- await waitForSteps ( [ "isConnectionLost - false" , "BUS:CONNECT" ] ) ;
75+ await expect . waitForSteps ( [ "isConnectionLost - false" , "BUS:CONNECT" ] ) ;
7876 const unlockWebsocket = lockWebsocketConnect ( ) ;
7977 patchWithCleanup ( navigator , { onLine : false } ) ;
8078 await manuallyDispatchProgrammaticEvent ( window , "offline" ) ; // Offline event is triggered when the computer goes to sleep.
81- await waitForSteps ( [ "BUS:DISCONNECT" ] ) ;
79+ await expect . waitForSteps ( [ "BUS:DISCONNECT" ] ) ;
8280 patchWithCleanup ( navigator , { onLine : true } ) ;
8381 await manuallyDispatchProgrammaticEvent ( window , "online" ) ; // Online event is triggered when the computer wakes up.
8482 unlockWebsocket ( ) ;
8583 await runAllTimers ( ) ;
86- await waitForSteps ( [ "BUS:CONNECT" ] ) ;
84+ await expect . waitForSteps ( [ "BUS:CONNECT" ] ) ;
8785 expect ( getService ( "bus.monitoring_service" ) . isConnectionLost ) . toBe ( false ) ;
8886} ) ;
0 commit comments