@@ -12,7 +12,7 @@ import { camelCaseObject, initializeMockApp } from '@edx/frontend-platform';
12
12
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth' ;
13
13
import { AppProvider } from '@edx/frontend-platform/react' ;
14
14
15
- import { getApiBaseUrl } from '../../data/constants' ;
15
+ import { getApiBaseUrl , ThreadType } from '../../data/constants' ;
16
16
import { initializeStore } from '../../store' ;
17
17
import executeThunk from '../../test-utils' ;
18
18
import { getCohortsApiUrl } from '../cohorts/data/api' ;
@@ -50,10 +50,10 @@ let testLocation;
50
50
let container ;
51
51
let unmount ;
52
52
53
- async function mockAxiosReturnPagedComments ( threadId , endorsed = false , page = 1 , count = 2 ) {
53
+ async function mockAxiosReturnPagedComments ( threadId , threadType = ThreadType . DISCUSSION , page = 1 , count = 2 ) {
54
54
axiosMock . onGet ( commentsApiUrl ) . reply ( 200 , Factory . build ( 'commentsResult' , { can_delete : true } , {
55
55
threadId,
56
- endorsed ,
56
+ threadType ,
57
57
pageSize : 1 ,
58
58
count,
59
59
childCount : page === 1 ? 2 : 0 ,
@@ -76,6 +76,7 @@ async function mockAxiosReturnPagedCommentsResponses() {
76
76
Factory . build ( 'commentsResult' , null , {
77
77
threadId : discussionPostId ,
78
78
parentId,
79
+ endorsed : false ,
79
80
page,
80
81
pageSize : 1 ,
81
82
count : 2 ,
@@ -201,6 +202,7 @@ describe('ThreadView', () => {
201
202
id : commentId ,
202
203
rendered_body : rawBody ,
203
204
raw_body : rawBody ,
205
+ endorsed : false ,
204
206
} ) ] ;
205
207
} ) ;
206
208
axiosMock . onPost ( commentsApiUrl ) . reply ( ( { data } ) => {
@@ -209,6 +211,7 @@ describe('ThreadView', () => {
209
211
rendered_body : rawBody ,
210
212
raw_body : rawBody ,
211
213
thread_id : threadId ,
214
+ endorsed : false ,
212
215
} ) ] ;
213
216
} ) ;
214
217
axiosMock . onGet ( `${ courseConfigApiUrl } ${ courseId } /` ) . reply ( 200 , { isPostingEnabled : true } ) ;
@@ -230,9 +233,9 @@ describe('ThreadView', () => {
230
233
expect ( JSON . parse ( axiosMock . history . patch [ axiosMock . history . patch . length - 1 ] . data ) ) . toMatchObject ( data ) ;
231
234
}
232
235
233
- it ( 'should not allow posting a comment on a closed post' , async ( ) => {
236
+ it ( 'should not allow posting a reply on a closed post' , async ( ) => {
234
237
axiosMock . reset ( ) ;
235
- await mockAxiosReturnPagedComments ( closedPostId , true ) ;
238
+ await mockAxiosReturnPagedComments ( closedPostId , ThreadType . QUESTION ) ;
236
239
await waitFor ( ( ) => renderComponent ( closedPostId , true ) ) ;
237
240
const comments = await waitFor ( ( ) => screen . findAllByTestId ( 'comment-comment-4' ) ) ;
238
241
const hoverCard = within ( comments [ 0 ] ) . getByTestId ( 'hover-card-comment-4' ) ;
@@ -288,7 +291,7 @@ describe('ThreadView', () => {
288
291
expect ( screen . queryByTestId ( 'tinymce-editor' ) ) . not . toBeInTheDocument ( ) ;
289
292
} ) ;
290
293
291
- it ( 'should allow posting a response ' , async ( ) => {
294
+ it ( 'should allow posting a comment ' , async ( ) => {
292
295
await waitFor ( ( ) => renderComponent ( discussionPostId ) ) ;
293
296
294
297
const post = await screen . findByTestId ( 'post-thread-1' ) ;
@@ -540,8 +543,11 @@ describe('ThreadView', () => {
540
543
// Wait for the content to load
541
544
const comment = await waitFor ( ( ) => screen . findByTestId ( 'comment-comment-1' ) ) ;
542
545
const hoverCard = within ( comment ) . getByTestId ( 'hover-card-comment-1' ) ;
546
+
547
+ const endorseButton = await waitFor ( ( ) => within ( hoverCard ) . getByRole ( 'button' , { name : / E n d o r s e / i } ) ) ;
548
+
543
549
await act ( async ( ) => {
544
- fireEvent . click ( within ( hoverCard ) . getByRole ( 'button' , { name : / E n d o r s e / i } ) ) ;
550
+ fireEvent . click ( endorseButton ) ;
545
551
} ) ;
546
552
expect ( axiosMock . history . patch ) . toHaveLength ( 2 ) ;
547
553
expect ( JSON . parse ( axiosMock . history . patch [ 1 ] . data ) ) . toMatchObject ( { endorsed : true } ) ;
@@ -591,7 +597,7 @@ describe('ThreadView', () => {
591
597
592
598
it ( 'pressing load more button will load next page of comments' , async ( ) => {
593
599
await waitFor ( ( ) => renderComponent ( discussionPostId ) ) ;
594
- await mockAxiosReturnPagedComments ( discussionPostId , false , 2 ) ;
600
+ await mockAxiosReturnPagedComments ( discussionPostId , ThreadType . DISCUSSION , 2 ) ;
595
601
596
602
const loadMoreButton = await findLoadMoreCommentsButton ( ) ;
597
603
await act ( async ( ) => {
@@ -604,7 +610,7 @@ describe('ThreadView', () => {
604
610
605
611
it ( 'newly loaded comments are appended to the old ones' , async ( ) => {
606
612
await waitFor ( ( ) => renderComponent ( discussionPostId ) ) ;
607
- await mockAxiosReturnPagedComments ( discussionPostId , false , 2 ) ;
613
+ await mockAxiosReturnPagedComments ( discussionPostId , ThreadType . DISCUSSION , 2 ) ;
608
614
609
615
const loadMoreButton = await findLoadMoreCommentsButton ( ) ;
610
616
await act ( async ( ) => {
@@ -622,7 +628,7 @@ describe('ThreadView', () => {
622
628
const findLoadMoreCommentsButtons = ( ) => screen . findByTestId ( 'load-more-comments' ) ;
623
629
624
630
it ( 'initially loads only the first page' , async ( ) => {
625
- await mockAxiosReturnPagedComments ( questionPostId ) ;
631
+ await mockAxiosReturnPagedComments ( questionPostId , ThreadType . QUESTION ) ;
626
632
act ( ( ) => renderComponent ( questionPostId ) ) ;
627
633
628
634
expect ( await screen . findByTestId ( 'comment-comment-4' ) )
@@ -633,7 +639,7 @@ describe('ThreadView', () => {
633
639
} ) ;
634
640
635
641
it ( 'pressing load more button will load next page of comments' , async ( ) => {
636
- await mockAxiosReturnPagedComments ( questionPostId ) ;
642
+ await mockAxiosReturnPagedComments ( questionPostId , ThreadType . QUESTION ) ;
637
643
await waitFor ( ( ) => renderComponent ( questionPostId ) ) ;
638
644
639
645
const loadMoreButton = await findLoadMoreCommentsButtons ( ) ;
@@ -644,7 +650,7 @@ describe('ThreadView', () => {
644
650
expect ( await screen . queryByTestId ( 'comment-comment-5' ) )
645
651
. not
646
652
. toBeInTheDocument ( ) ;
647
- await mockAxiosReturnPagedComments ( questionPostId , false , 2 , 1 ) ;
653
+ await mockAxiosReturnPagedComments ( questionPostId , ThreadType . QUESTION , 2 , 1 ) ;
648
654
await act ( async ( ) => {
649
655
fireEvent . click ( loadMoreButton ) ;
650
656
} ) ;
@@ -664,7 +670,7 @@ describe('ThreadView', () => {
664
670
expect ( screen . queryByTestId ( 'reply-comment-3' ) ) . not . toBeInTheDocument ( ) ;
665
671
} ) ;
666
672
667
- it ( 'pressing load more button will load next page of responses ' , async ( ) => {
673
+ it ( 'pressing load more button will load next page of replies ' , async ( ) => {
668
674
await waitFor ( ( ) => renderComponent ( discussionPostId ) ) ;
669
675
670
676
const loadMoreButton = await findLoadMoreCommentsResponsesButton ( ) ;
@@ -674,7 +680,7 @@ describe('ThreadView', () => {
674
680
await screen . findByTestId ( 'reply-comment-3' ) ;
675
681
} ) ;
676
682
677
- it ( 'newly loaded responses are appended to the old ones' , async ( ) => {
683
+ it ( 'newly loaded replies are appended to the old ones' , async ( ) => {
678
684
await waitFor ( ( ) => renderComponent ( discussionPostId ) ) ;
679
685
680
686
const loadMoreButton = await findLoadMoreCommentsResponsesButton ( ) ;
@@ -687,7 +693,7 @@ describe('ThreadView', () => {
687
693
expect ( screen . queryByTestId ( 'reply-comment-2' ) ) . toBeInTheDocument ( ) ;
688
694
} ) ;
689
695
690
- it ( 'load more button is hidden when no more responses pages to load' , async ( ) => {
696
+ it ( 'load more button is hidden when no more replies pages to load' , async ( ) => {
691
697
await waitFor ( ( ) => renderComponent ( discussionPostId ) ) ;
692
698
693
699
const loadMoreButton = await findLoadMoreCommentsResponsesButton ( ) ;
0 commit comments