@@ -54,22 +54,29 @@ const createWrapper =
5454 < DailyProvider callObject = { callObject } > { children } </ DailyProvider > ;
5555
5656describe ( 'useNetwork' , ( ) => {
57- it ( 'returns getStats method, quality, threshold & topology with perfect defaults' , ( ) => {
57+ it ( 'returns getStats method with perfect defaults' , ( ) => {
5858 const { result } = renderHook ( ( ) => useNetwork ( ) , {
5959 wrapper : createWrapper ( ) ,
6060 } ) ;
6161 expect ( result . current ) . toHaveProperty ( 'getStats' ) ;
6262 expect ( typeof result . current . getStats ) . toBe ( 'function' ) ;
6363 expect ( result . current ) . toHaveProperty ( 'quality' ) ;
6464 expect ( result . current . quality ) . toBe ( 100 ) ;
65+ expect ( result . current ) . toHaveProperty ( 'networkState' ) ;
66+ expect ( result . current . networkState ) . toBe ( 'unknown' ) ;
67+ expect ( result . current ) . toHaveProperty ( 'networkStateReasons' ) ;
68+ expect ( result . current . networkStateReasons ) . toStrictEqual ( [ ] ) ;
6569 expect ( result . current ) . toHaveProperty ( 'threshold' ) ;
6670 expect ( result . current . threshold ) . toBe ( 'good' ) ;
6771 expect ( result . current ) . toHaveProperty ( 'topology' ) ;
6872 expect ( result . current . topology ) . toBe ( 'none' ) ;
6973 } ) ;
7074 it ( 'getStats calls getNetworkStats internally' , async ( ) => {
7175 const mockStats : DailyNetworkStats = {
76+ networkState : 'good' ,
77+ networkStateReasons : [ ] ,
7278 quality : 99 ,
79+ threshold : 'good' ,
7380 stats : {
7481 latest : {
7582 recvBitsPerSecond : 1000000 ,
@@ -102,7 +109,6 @@ describe('useNetwork', () => {
102109 worstAudioSendJitter : 0 ,
103110 averageNetworkRoundTripTime : 0.07171428571428572 ,
104111 } ,
105- threshold : 'good' ,
106112 } ;
107113 const daily = Daily . createCallObject ( ) ;
108114 (
@@ -184,14 +190,19 @@ describe('useNetwork', () => {
184190 const event : DailyEvent = 'network-quality-change' ;
185191 const payload : DailyEventObjectNetworkQualityEvent = mockEvent ( {
186192 action : 'network-quality-change' ,
193+ networkState : 'bad' ,
194+ networkStateReasons : [ 'sendPacketLoss' ] ,
187195 quality : 80 ,
188196 threshold : 'low' ,
197+ stats : { } ,
189198 } ) ;
190199 act ( ( ) => {
191200 // @ts -ignore
192201 daily . emit ( event , payload ) ;
193202 } ) ;
194203 await waitFor ( ( ) => {
204+ expect ( result . current . networkState ) . toBe ( 'bad' ) ;
205+ expect ( result . current . networkStateReasons ) . toEqual ( [ 'sendPacketLoss' ] ) ;
195206 expect ( result . current . quality ) . toBe ( 80 ) ;
196207 expect ( result . current . threshold ) . toBe ( 'low' ) ;
197208 expect ( onNetworkQualityChange ) . toHaveBeenCalledWith ( payload ) ;
0 commit comments