@@ -35,8 +35,7 @@ describe('context/App.tsx', () => {
35
35
jest . clearAllMocks ( ) ;
36
36
} ) ;
37
37
38
- describe ( 'api methods' , ( ) => {
39
- const apiRequestAuthMock = jest . spyOn ( apiRequests , 'apiRequestAuth' ) ;
38
+ describe ( 'notification methods' , ( ) => {
40
39
const getNotificationCountMock = jest . spyOn (
41
40
notifications ,
42
41
'getNotificationCount' ,
@@ -269,18 +268,31 @@ describe('context/App.tsx', () => {
269
268
'github.com' ,
270
269
) ;
271
270
} ) ;
271
+ } ) ;
272
+ describe ( 'authentication methods' , ( ) => {
273
+ const apiRequestAuthMock = jest . spyOn ( apiRequests , 'apiRequestAuth' ) ;
274
+ const fetchNotificationsMock = jest . fn ( ) ;
272
275
273
- it ( 'should call validateToken' , async ( ) => {
276
+ beforeEach ( ( ) => {
277
+ ( useNotifications as jest . Mock ) . mockReturnValue ( {
278
+ fetchNotifications : fetchNotificationsMock ,
279
+ } ) ;
280
+ } ) ;
281
+
282
+ it ( 'should call loginWithPersonalAccessToken' , async ( ) => {
274
283
apiRequestAuthMock . mockResolvedValueOnce ( null ) ;
275
284
276
285
const TestComponent = ( ) => {
277
- const { validateToken } = useContext ( AppContext ) ;
286
+ const { loginWithPersonalAccessToken } = useContext ( AppContext ) ;
278
287
279
288
return (
280
289
< button
281
290
type = "button"
282
291
onClick = { ( ) =>
283
- validateToken ( { hostname : 'github.com' , token : '123-456' } )
292
+ loginWithPersonalAccessToken ( {
293
+ hostname : 'github.com' ,
294
+ token : '123-456' ,
295
+ } )
284
296
}
285
297
>
286
298
Test Case
@@ -332,90 +344,92 @@ describe('context/App.tsx', () => {
332
344
expect ( clearStateMock ) . toHaveBeenCalledTimes ( 1 ) ;
333
345
} ) ;
334
346
335
- it ( 'should call updateSetting' , async ( ) => {
336
- const saveStateMock = jest
337
- . spyOn ( storage , 'saveState' )
338
- . mockImplementation ( jest . fn ( ) ) ;
347
+ describe ( 'settings methods' , ( ) => {
348
+ it ( 'should call updateSetting' , async ( ) => {
349
+ const saveStateMock = jest
350
+ . spyOn ( storage , 'saveState' )
351
+ . mockImplementation ( jest . fn ( ) ) ;
339
352
340
- const TestComponent = ( ) => {
341
- const { updateSetting } = useContext ( AppContext ) ;
353
+ const TestComponent = ( ) => {
354
+ const { updateSetting } = useContext ( AppContext ) ;
342
355
343
- return (
344
- < button
345
- type = "button"
346
- onClick = { ( ) => updateSetting ( 'participating' , true ) }
347
- >
348
- Test Case
349
- </ button >
350
- ) ;
351
- } ;
356
+ return (
357
+ < button
358
+ type = "button"
359
+ onClick = { ( ) => updateSetting ( 'participating' , true ) }
360
+ >
361
+ Test Case
362
+ </ button >
363
+ ) ;
364
+ } ;
352
365
353
- const { getByText } = customRender ( < TestComponent /> ) ;
366
+ const { getByText } = customRender ( < TestComponent /> ) ;
354
367
355
- act ( ( ) => {
356
- fireEvent . click ( getByText ( 'Test Case' ) ) ;
357
- } ) ;
368
+ act ( ( ) => {
369
+ fireEvent . click ( getByText ( 'Test Case' ) ) ;
370
+ } ) ;
358
371
359
- expect ( saveStateMock ) . toHaveBeenCalledWith ( {
360
- auth : { enterpriseAccounts : [ ] , token : null , user : null } ,
361
- settings : {
362
- participating : true ,
363
- playSound : true ,
364
- showNotifications : true ,
365
- showBots : true ,
366
- showNotificationsCountInTray : false ,
367
- openAtStartup : false ,
368
- theme : 'SYSTEM' ,
369
- detailedNotifications : true ,
370
- markAsDoneOnOpen : false ,
371
- showAccountHostname : false ,
372
- delayNotificationState : false ,
373
- } ,
372
+ expect ( saveStateMock ) . toHaveBeenCalledWith ( {
373
+ auth : { enterpriseAccounts : [ ] , token : null , user : null } ,
374
+ settings : {
375
+ participating : true ,
376
+ playSound : true ,
377
+ showNotifications : true ,
378
+ showBots : true ,
379
+ showNotificationsCountInTray : false ,
380
+ openAtStartup : false ,
381
+ theme : 'SYSTEM' ,
382
+ detailedNotifications : true ,
383
+ markAsDoneOnOpen : false ,
384
+ showAccountHostname : false ,
385
+ delayNotificationState : false ,
386
+ } ,
387
+ } ) ;
374
388
} ) ;
375
- } ) ;
376
389
377
- it ( 'should call updateSetting and set auto launch(openAtStartup)' , async ( ) => {
378
- const setAutoLaunchMock = jest . spyOn ( comms , 'setAutoLaunch' ) ;
379
- const saveStateMock = jest
380
- . spyOn ( storage , 'saveState' )
381
- . mockImplementation ( jest . fn ( ) ) ;
390
+ it ( 'should call updateSetting and set auto launch(openAtStartup)' , async ( ) => {
391
+ const setAutoLaunchMock = jest . spyOn ( comms , 'setAutoLaunch' ) ;
392
+ const saveStateMock = jest
393
+ . spyOn ( storage , 'saveState' )
394
+ . mockImplementation ( jest . fn ( ) ) ;
382
395
383
- const TestComponent = ( ) => {
384
- const { updateSetting } = useContext ( AppContext ) ;
396
+ const TestComponent = ( ) => {
397
+ const { updateSetting } = useContext ( AppContext ) ;
385
398
386
- return (
387
- < button
388
- type = "button"
389
- onClick = { ( ) => updateSetting ( 'openAtStartup' , true ) }
390
- >
391
- Test Case
392
- </ button >
393
- ) ;
394
- } ;
399
+ return (
400
+ < button
401
+ type = "button"
402
+ onClick = { ( ) => updateSetting ( 'openAtStartup' , true ) }
403
+ >
404
+ Test Case
405
+ </ button >
406
+ ) ;
407
+ } ;
395
408
396
- const { getByText } = customRender ( < TestComponent /> ) ;
409
+ const { getByText } = customRender ( < TestComponent /> ) ;
397
410
398
- act ( ( ) => {
399
- fireEvent . click ( getByText ( 'Test Case' ) ) ;
400
- } ) ;
411
+ act ( ( ) => {
412
+ fireEvent . click ( getByText ( 'Test Case' ) ) ;
413
+ } ) ;
401
414
402
- expect ( setAutoLaunchMock ) . toHaveBeenCalledWith ( true ) ;
403
-
404
- expect ( saveStateMock ) . toHaveBeenCalledWith ( {
405
- auth : { enterpriseAccounts : [ ] , token : null , user : null } ,
406
- settings : {
407
- participating : false ,
408
- playSound : true ,
409
- showNotifications : true ,
410
- showBots : true ,
411
- showNotificationsCountInTray : false ,
412
- openAtStartup : true ,
413
- theme : 'SYSTEM' ,
414
- detailedNotifications : true ,
415
- markAsDoneOnOpen : false ,
416
- showAccountHostname : false ,
417
- delayNotificationState : false ,
418
- } ,
415
+ expect ( setAutoLaunchMock ) . toHaveBeenCalledWith ( true ) ;
416
+
417
+ expect ( saveStateMock ) . toHaveBeenCalledWith ( {
418
+ auth : { enterpriseAccounts : [ ] , token : null , user : null } ,
419
+ settings : {
420
+ participating : false ,
421
+ playSound : true ,
422
+ showNotifications : true ,
423
+ showBots : true ,
424
+ showNotificationsCountInTray : false ,
425
+ openAtStartup : true ,
426
+ theme : 'SYSTEM' ,
427
+ detailedNotifications : true ,
428
+ markAsDoneOnOpen : false ,
429
+ showAccountHostname : false ,
430
+ delayNotificationState : false ,
431
+ } ,
432
+ } ) ;
419
433
} ) ;
420
434
} ) ;
421
435
} ) ;
0 commit comments