@@ -31,6 +31,7 @@ const logoutCb = jest.fn();
3131const logger = {
3232 error : jest . fn ( )
3333} ;
34+ const isAgentLoggedIn = false ;
3435
3536describe ( 'useStationLogin Hook' , ( ) => {
3637 afterEach ( ( ) => {
@@ -67,7 +68,7 @@ describe('useStationLogin Hook', () => {
6768 ccMock . stationLogin . mockResolvedValue ( successResponse ) ;
6869 const setSelectedLoginOptionSpy = jest . spyOn ( require ( '@webex/cc-store' ) , 'setSelectedLoginOption' ) ;
6970
70- const { result} = renderHook ( ( ) => useStationLogin ( { cc : ccMock , onLogin : loginCb , onLogout : logoutCb , logger} ) ) ;
71+ const { result} = renderHook ( ( ) => useStationLogin ( { cc : ccMock , onLogin : loginCb , onLogout : logoutCb , logger, isAgentLoggedIn } ) ) ;
7172
7273 act ( ( ) => {
7374 result . current . setDeviceType ( loginParams . loginOption ) ;
@@ -89,6 +90,7 @@ describe('useStationLogin Hook', () => {
8990
9091 expect ( result . current ) . toEqual ( {
9192 name : 'StationLogin' ,
93+ isAgentLoggedIn : true ,
9294 setDeviceType : expect . any ( Function ) ,
9395 setDialNumber : expect . any ( Function ) ,
9496 setTeam : expect . any ( Function ) ,
@@ -97,6 +99,7 @@ describe('useStationLogin Hook', () => {
9799 loginSuccess : successResponse ,
98100 loginFailure : undefined ,
99101 logoutSuccess : undefined ,
102+ relogin : expect . any ( Function ) ,
100103 } ) ;
101104
102105 expect ( setSelectedLoginOptionSpy ) . toHaveBeenCalledWith ( loginParams . loginOption ) ;
@@ -109,7 +112,7 @@ describe('useStationLogin Hook', () => {
109112 const setSelectedLoginOptionSpy = jest . spyOn ( require ( '@webex/cc-store' ) , 'setSelectedLoginOption' ) ;
110113
111114 loginCb . mockClear ( ) ;
112- const { result} = renderHook ( ( ) => useStationLogin ( { cc : ccMock , onLogin : loginCb , onLogout : logoutCb , logger} ) ) ;
115+ const { result} = renderHook ( ( ) => useStationLogin ( { cc : ccMock , onLogin : loginCb , onLogout : logoutCb , logger, isAgentLoggedIn } ) ) ;
113116
114117 act ( ( ) => {
115118 result . current . setDeviceType ( loginParams . loginOption ) ;
@@ -131,6 +134,7 @@ describe('useStationLogin Hook', () => {
131134
132135 expect ( result . current ) . toEqual ( {
133136 name : 'StationLogin' ,
137+ isAgentLoggedIn : false ,
134138 setDeviceType : expect . any ( Function ) ,
135139 setDialNumber : expect . any ( Function ) ,
136140 setTeam : expect . any ( Function ) ,
@@ -139,6 +143,7 @@ describe('useStationLogin Hook', () => {
139143 loginSuccess : undefined ,
140144 loginFailure : errorResponse ,
141145 logoutSuccess : undefined ,
146+ relogin : expect . any ( Function ) ,
142147 } ) ;
143148
144149 expect ( setSelectedLoginOptionSpy ) . not . toHaveBeenCalled ( ) ;
@@ -150,7 +155,7 @@ describe('useStationLogin Hook', () => {
150155 ccMock . stationLogin . mockResolvedValue ( { } ) ;
151156
152157 const { result } = renderHook ( ( ) =>
153- useStationLogin ( { cc : ccMock , onLogout : logoutCb , logger} )
158+ useStationLogin ( { cc : ccMock , onLogout : logoutCb , logger, isAgentLoggedIn } )
154159 ) ;
155160
156161 await act ( async ( ) => {
@@ -167,7 +172,7 @@ describe('useStationLogin Hook', () => {
167172 ccMock . stationLogin . mockRejectedValue ( errorResponse ) ;
168173
169174 loginCb . mockClear ( ) ;
170- const { result} = renderHook ( ( ) => useStationLogin ( { cc : ccMock , onLogin : loginCb , onLogout : logoutCb , logger} ) ) ;
175+ const { result} = renderHook ( ( ) => useStationLogin ( { cc : ccMock , onLogin : loginCb , onLogout : logoutCb , logger, isAgentLoggedIn } ) ) ;
171176
172177 act ( ( ) => {
173178 result . current . setDeviceType ( loginParams . loginOption ) ;
@@ -190,6 +195,7 @@ describe('useStationLogin Hook', () => {
190195
191196 expect ( result . current ) . toEqual ( {
192197 name : 'StationLogin' ,
198+ isAgentLoggedIn : true ,
193199 setDeviceType : expect . any ( Function ) ,
194200 setDialNumber : expect . any ( Function ) ,
195201 setTeam : expect . any ( Function ) ,
@@ -198,6 +204,7 @@ describe('useStationLogin Hook', () => {
198204 loginSuccess : undefined ,
199205 loginFailure : errorResponse ,
200206 logoutSuccess : undefined ,
207+ relogin : expect . any ( Function ) ,
201208 } ) ;
202209 } ) ;
203210 } ) ;
@@ -220,7 +227,7 @@ describe('useStationLogin Hook', () => {
220227
221228 ccMock . stationLogout . mockResolvedValue ( successResponse ) ;
222229
223- const { result} = renderHook ( ( ) => useStationLogin ( { cc : ccMock , onLogin : loginCb , onLogout : logoutCb , logger} ) ) ;
230+ const { result} = renderHook ( ( ) => useStationLogin ( { cc : ccMock , onLogin : loginCb , onLogout : logoutCb , logger, isAgentLoggedIn } ) ) ;
224231
225232 await act ( async ( ) => {
226233 await result . current . logout ( ) ;
@@ -232,6 +239,7 @@ describe('useStationLogin Hook', () => {
232239
233240 expect ( result . current ) . toEqual ( {
234241 name : 'StationLogin' ,
242+ isAgentLoggedIn : false ,
235243 setDeviceType : expect . any ( Function ) ,
236244 setDialNumber : expect . any ( Function ) ,
237245 setTeam : expect . any ( Function ) ,
@@ -240,6 +248,7 @@ describe('useStationLogin Hook', () => {
240248 loginSuccess : undefined ,
241249 loginFailure : undefined ,
242250 logoutSuccess : successResponse ,
251+ relogin : expect . any ( Function ) ,
243252 } ) ;
244253 } ) ;
245254 } ) ;
@@ -248,7 +257,7 @@ describe('useStationLogin Hook', () => {
248257 ccMock . stationLogout . mockRejectedValue ( new Error ( 'Logout failed' ) ) ;
249258
250259 const { result} = renderHook ( ( ) =>
251- useStationLogin ( { cc : ccMock , onLogin : loginCb , onLogout : logoutCb , logger} )
260+ useStationLogin ( { cc : ccMock , onLogin : loginCb , onLogout : logoutCb , logger, isAgentLoggedIn } )
252261 ) ;
253262
254263 await act ( async ( ) => {
@@ -266,7 +275,7 @@ describe('useStationLogin Hook', () => {
266275 it ( 'should not call logout callback if not present' , async ( ) => {
267276 ccMock . stationLogout . mockResolvedValue ( { } ) ;
268277
269- const { result} = renderHook ( ( ) => useStationLogin ( { cc : ccMock , onLogin : loginCb , logger} ) ) ;
278+ const { result} = renderHook ( ( ) => useStationLogin ( { cc : ccMock , onLogin : loginCb , logger, isAgentLoggedIn } ) ) ;
270279
271280 await act ( async ( ) => {
272281 await result . current . logout ( ) ;
@@ -276,4 +285,19 @@ describe('useStationLogin Hook', () => {
276285 expect ( logoutCb ) . not . toHaveBeenCalled ( ) ;
277286 } ) ;
278287 } ) ;
288+
289+ it ( 'should call relogin and set device type' , async ( ) => {
290+ const setSelectedLoginOptionSpy = jest . spyOn ( require ( '@webex/cc-store' ) , 'setSelectedLoginOption' ) ;
291+
292+ const { result } = renderHook ( ( ) => useStationLogin ( { cc : ccMock , onLogin : loginCb , onLogout : logoutCb , logger, isAgentLoggedIn } ) ) ;
293+
294+ act ( ( ) => {
295+ result . current . relogin ( ) ;
296+ } ) ;
297+
298+ await waitFor ( ( ) => {
299+ expect ( setSelectedLoginOptionSpy ) . toHaveBeenCalled ( ) ;
300+ expect ( loginCb ) . toHaveBeenCalled ( ) ;
301+ } ) ;
302+ } ) ;
279303} ) ;
0 commit comments