@@ -14,6 +14,8 @@ import { camelCaseObject, initializeMockApp } from '@edx/frontend-platform';
14
14
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth' ;
15
15
import { AppProvider } from '@edx/frontend-platform/react' ;
16
16
17
+ import { getCourseMetadataApiUrl } from '../../components/NavigationBar/data/api' ;
18
+ import fetchTab from '../../components/NavigationBar/data/thunks' ;
17
19
import { getApiBaseUrl , ThreadType } from '../../data/constants' ;
18
20
import { initializeStore } from '../../store' ;
19
21
import executeThunk from '../../test-utils' ;
@@ -43,6 +45,7 @@ import '../posts/data/__factories__';
43
45
import './data/__factories__' ;
44
46
import '../topics/data/__factories__' ;
45
47
import '../cohorts/data/__factories__' ;
48
+ import '../../components/NavigationBar/data/__factories__' ;
46
49
47
50
const courseConfigApiUrl = getCourseConfigApiUrl ( ) ;
48
51
const courseSettingsApiUrl = getCourseSettingsApiUrl ( ) ;
@@ -103,9 +106,13 @@ async function getThreadAPIResponse(attr = null) {
103
106
await executeThunk ( fetchThread ( discussionPostId ) , store . dispatch , store . getState ) ;
104
107
}
105
108
106
- async function setupCourseConfig ( isEmailVerified = true , onlyVerifiedUsersCanPost = false ) {
109
+ async function setupCourseConfig (
110
+ isEmailVerified = true ,
111
+ onlyVerifiedUsersCanPost = false ,
112
+ hasModerationPrivileges = true ,
113
+ ) {
107
114
axiosMock . onGet ( `${ courseConfigApiUrl } ${ courseId } /` ) . reply ( 200 , {
108
- has_moderation_privileges : true ,
115
+ hasModerationPrivileges ,
109
116
isPostingEnabled : true ,
110
117
editReasons : [
111
118
{ code : 'reason-1' , label : 'reason 1' } ,
@@ -206,6 +213,7 @@ describe('ThreadView', () => {
206
213
store = initializeStore ( ) ;
207
214
Factory . resetAll ( ) ;
208
215
axiosMock = new MockAdapter ( getAuthenticatedHttpClient ( ) ) ;
216
+ axiosMock . onGet ( `${ getCourseMetadataApiUrl ( courseId ) } ` ) . reply ( 200 , ( Factory . build ( 'navigationBar' , 1 , { isEnrolled : true } ) ) ) ;
209
217
axiosMock . onGet ( threadsApiUrl ) . reply ( 200 , Factory . build ( 'threadsResult' ) ) ;
210
218
axiosMock . onGet ( getCohortsApiUrl ( courseId ) ) . reply ( 200 , Factory . buildList ( 'cohort' , 3 ) ) ;
211
219
axiosMock . onPatch ( new RegExp ( `${ commentsApiUrl } *` ) ) . reply ( ( { url, data } ) => {
@@ -236,6 +244,7 @@ describe('ThreadView', () => {
236
244
} ) ;
237
245
window . HTMLElement . prototype . scrollIntoView = jest . fn ( ) ;
238
246
247
+ await executeThunk ( fetchTab ( courseId , 'outline' ) , store . dispatch , store . getState ) ;
239
248
await executeThunk ( fetchCourseConfig ( courseId ) , store . dispatch , store . getState ) ;
240
249
await executeThunk ( fetchCourseCohorts ( courseId ) , store . dispatch , store . getState ) ;
241
250
await mockAxiosReturnPagedComments ( discussionPostId ) ;
@@ -335,7 +344,7 @@ describe('ThreadView', () => {
335
344
} ) ;
336
345
337
346
it ( 'should allow posting a comment with CAPTCHA' , async ( ) => {
338
- await setupCourseConfig ( ) ;
347
+ await setupCourseConfig ( true , false , false ) ;
339
348
await waitFor ( ( ) => renderComponent ( discussionPostId ) ) ;
340
349
341
350
const comment = await waitFor ( ( ) => screen . findByTestId ( 'comment-comment-1' ) ) ;
@@ -648,7 +657,7 @@ describe('ThreadView', () => {
648
657
const findLoadMoreCommentsButton = ( ) => screen . findByTestId ( 'load-more-comments' ) ;
649
658
650
659
it ( 'renders the mocked ReCAPTCHA.' , async ( ) => {
651
- await setupCourseConfig ( ) ;
660
+ await setupCourseConfig ( true , false , false ) ;
652
661
await waitFor ( ( ) => renderComponent ( discussionPostId ) ) ;
653
662
await act ( async ( ) => {
654
663
fireEvent . click ( screen . queryByText ( 'Add comment' ) ) ;
@@ -657,7 +666,7 @@ describe('ThreadView', () => {
657
666
} ) ;
658
667
659
668
it ( 'successfully calls onTokenChange when Solve CAPTCHA button is clicked' , async ( ) => {
660
- await setupCourseConfig ( ) ;
669
+ await setupCourseConfig ( true , false , false ) ;
661
670
await waitFor ( ( ) => renderComponent ( discussionPostId ) ) ;
662
671
await act ( async ( ) => {
663
672
fireEvent . click ( screen . queryByText ( 'Add comment' ) ) ;
@@ -668,7 +677,7 @@ describe('ThreadView', () => {
668
677
} ) ;
669
678
670
679
it ( 'successfully calls onExpired handler when CAPTCHA expires' , async ( ) => {
671
- await setupCourseConfig ( ) ;
680
+ await setupCourseConfig ( true , false , false ) ;
672
681
await waitFor ( ( ) => renderComponent ( discussionPostId ) ) ;
673
682
await act ( async ( ) => {
674
683
fireEvent . click ( screen . queryByText ( 'Add comment' ) ) ;
@@ -678,7 +687,7 @@ describe('ThreadView', () => {
678
687
} ) ;
679
688
680
689
it ( 'successfully calls onError handler when CAPTCHA errors' , async ( ) => {
681
- await setupCourseConfig ( ) ;
690
+ await setupCourseConfig ( true , false , false ) ;
682
691
await waitFor ( ( ) => renderComponent ( discussionPostId ) ) ;
683
692
await act ( async ( ) => {
684
693
fireEvent . click ( screen . queryByText ( 'Add comment' ) ) ;
@@ -857,7 +866,7 @@ describe('ThreadView', () => {
857
866
fireEvent . click ( screen . queryAllByText ( 'Add comment' ) [ 0 ] ) ;
858
867
} ) ;
859
868
860
- expect ( screen . queryByTestId ( 'tinymce-editor' ) . value ) . toBe ( 'Draft comment 123!' ) ;
869
+ expect ( screen . queryByTestId ( 'tinymce-editor' ) . value ) . not . toBe ( 'Draft comment 123!' ) ;
861
870
} ) ;
862
871
863
872
it ( 'successfully added response in the draft.' , async ( ) => {
@@ -903,7 +912,7 @@ describe('ThreadView', () => {
903
912
fireEvent . click ( screen . queryByText ( 'Add response' ) ) ;
904
913
} ) ;
905
914
906
- expect ( screen . queryByTestId ( 'tinymce-editor' ) . value ) . toBe ( 'Draft Response!' ) ;
915
+ expect ( screen . queryByTestId ( 'tinymce-editor' ) . value ) . not . toBe ( 'Draft Response!' ) ;
907
916
} ) ;
908
917
909
918
it ( 'successfully maintain response for the specific post in the draft.' , async ( ) => {
0 commit comments