@@ -4,6 +4,7 @@ import * as sorter from '../../utils/sorter';
44import * as error from '../../utils/error' ;
55import { IS_ERROR_DISPLAYED , TASK_NEW_NOT_STARTED , TASK_MAX_GROUP_ASSIGNEES } from '../../constants' ;
66import Feed from '../Feed' ;
7+ import { annotation as mockAnnotation } from '../../__mocks__/annotations' ;
78
89const mockTask = {
910 created_by : {
@@ -98,6 +99,12 @@ const versionsWithCurrent = {
9899 entries : [ mockCurrentVersion , mockFirstVersion , deleted_version ] ,
99100} ;
100101
102+ const annotations = {
103+ entries : [ mockAnnotation ] ,
104+ limit : 1000 ,
105+ next_marker : null ,
106+ } ;
107+
101108jest . mock ( 'lodash/uniqueId' , ( ) => ( ) => 'uniqueId' ) ;
102109
103110const mockCreateTask = jest . fn ( ) . mockImplementation ( ( { successCallback } ) => {
@@ -237,6 +244,12 @@ jest.mock('../Versions', () => {
237244 } ) ) ;
238245} ) ;
239246
247+ jest . mock ( '../Annotations' , ( ) =>
248+ jest . fn ( ) . mockImplementation ( ( ) => ( {
249+ getAnnotations : jest . fn ( ) ,
250+ } ) ) ,
251+ ) ;
252+
240253const MOCK_APP_ACTIVITY_ITEM = {
241254 activity_template : {
242255 id : '1' ,
@@ -380,6 +393,7 @@ describe('api/Feed', () => {
380393 ...tasks . entries ,
381394 ...comments . entries ,
382395 ...appActivities . entries ,
396+ ...annotations . entries ,
383397 ] ;
384398 let successCb ;
385399 let errorCb ;
@@ -390,6 +404,7 @@ describe('api/Feed', () => {
390404 feed . fetchTasksNew = jest . fn ( ) . mockResolvedValue ( tasks ) ;
391405 feed . fetchComments = jest . fn ( ) . mockResolvedValue ( comments ) ;
392406 feed . fetchAppActivity = jest . fn ( ) . mockReturnValue ( appActivities ) ;
407+ feed . fetchAnnotations = jest . fn ( ) . mockReturnValue ( annotations ) ;
393408 feed . setCachedItems = jest . fn ( ) ;
394409 feed . versionsAPI = {
395410 getVersion : jest . fn ( ) . mockReturnValue ( versions ) ,
@@ -406,10 +421,19 @@ describe('api/Feed', () => {
406421 } ) ;
407422
408423 test ( 'should get feed items, sort, save to cache, and call the success callback' , done => {
409- feed . feedItems ( file , false , successCb , errorCb , jest . fn ( ) , { shouldShowAppActivity : true } ) ;
424+ feed . feedItems ( file , false , successCb , errorCb , jest . fn ( ) , {
425+ shouldShowAnnotations : true ,
426+ shouldShowAppActivity : true ,
427+ } ) ;
410428 setImmediate ( ( ) => {
411429 expect ( feed . versionsAPI . addCurrentVersion ) . toHaveBeenCalledWith ( mockCurrentVersion , versions , file ) ;
412- expect ( sorter . sortFeedItems ) . toHaveBeenCalledWith ( versionsWithCurrent , comments , tasks , appActivities ) ;
430+ expect ( sorter . sortFeedItems ) . toHaveBeenCalledWith (
431+ versionsWithCurrent ,
432+ comments ,
433+ tasks ,
434+ appActivities ,
435+ annotations ,
436+ ) ;
413437 expect ( feed . setCachedItems ) . toHaveBeenCalledWith ( file . id , sortedItems ) ;
414438 expect ( successCb ) . toHaveBeenCalledWith ( sortedItems ) ;
415439 done ( ) ;
@@ -445,6 +469,22 @@ describe('api/Feed', () => {
445469 } ) ;
446470 } ) ;
447471
472+ test ( 'should use the annotations api if shouldShowannotations is true' , done => {
473+ feed . feedItems ( file , false , successCb , errorCb , errorCb , { shouldShowAnnotations : true } ) ;
474+ setImmediate ( ( ) => {
475+ expect ( feed . fetchAnnotations ) . toHaveBeenCalled ( ) ;
476+ done ( ) ;
477+ } ) ;
478+ } ) ;
479+
480+ test ( 'should not use the annotations api if shouldShowannotations is false' , done => {
481+ feed . feedItems ( file , false , successCb , errorCb , errorCb , { shouldShowAnnotations : false } ) ;
482+ setImmediate ( ( ) => {
483+ expect ( feed . fetchAnnotations ) . not . toHaveBeenCalled ( ) ;
484+ done ( ) ;
485+ } ) ;
486+ } ) ;
487+
448488 test ( 'should not call success or error callback if it is destroyed' , done => {
449489 feed . isDestroyed = jest . fn ( ) . mockReturnValue ( true ) ;
450490 feed . feedItems ( file , false , successCb , errorCb ) ;
@@ -483,6 +523,19 @@ describe('api/Feed', () => {
483523 } ) ;
484524 } ) ;
485525
526+ describe ( 'fetchAnnotations()' , ( ) => {
527+ beforeEach ( ( ) => {
528+ feed . file = file ;
529+ feed . fetchFeedItemErrorCallback = jest . fn ( ) ;
530+ } ) ;
531+
532+ test ( 'should return a promise and call the annotations api' , ( ) => {
533+ const annotationItems = feed . fetchAnnotations ( ) ;
534+ expect ( annotationItems instanceof Promise ) . toBeTruthy ( ) ;
535+ expect ( feed . annotationsAPI . getAnnotations ) . toBeCalled ( ) ;
536+ } ) ;
537+ } ) ;
538+
486539 describe ( 'fetchComments()' , ( ) => {
487540 beforeEach ( ( ) => {
488541 feed . file = file ;
@@ -1306,15 +1359,20 @@ describe('api/Feed', () => {
13061359 } ) ;
13071360
13081361 describe ( 'destroy()' , ( ) => {
1362+ let annotationFn ;
13091363 let commentFn ;
13101364 let versionFn ;
13111365 let taskFn ;
13121366
13131367 beforeEach ( ( ) => {
1368+ annotationFn = jest . fn ( ) ;
13141369 commentFn = jest . fn ( ) ;
13151370 versionFn = jest . fn ( ) ;
13161371 taskFn = jest . fn ( ) ;
13171372
1373+ feed . annotationsAPI = {
1374+ destroy : annotationFn ,
1375+ } ;
13181376 feed . tasksNewAPI = {
13191377 destroy : taskFn ,
13201378 } ;
@@ -1331,6 +1389,7 @@ describe('api/Feed', () => {
13311389 expect ( versionFn ) . toBeCalled ( ) ;
13321390 expect ( commentFn ) . toBeCalled ( ) ;
13331391 expect ( taskFn ) . toBeCalled ( ) ;
1392+ expect ( annotationFn ) . toBeCalled ( ) ;
13341393 } ) ;
13351394 } ) ;
13361395
0 commit comments