@@ -14,6 +14,8 @@ import { camelCaseObject, initializeMockApp } from '@edx/frontend-platform';
1414import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth' ;
1515import { AppProvider } from '@edx/frontend-platform/react' ;
1616
17+ import { getCourseMetadataApiUrl } from '../../components/NavigationBar/data/api' ;
18+ import fetchTab from '../../components/NavigationBar/data/thunks' ;
1719import { getApiBaseUrl , ThreadType } from '../../data/constants' ;
1820import { initializeStore } from '../../store' ;
1921import executeThunk from '../../test-utils' ;
@@ -43,6 +45,7 @@ import '../posts/data/__factories__';
4345import './data/__factories__' ;
4446import '../topics/data/__factories__' ;
4547import '../cohorts/data/__factories__' ;
48+ import '../../components/NavigationBar/data/__factories__' ;
4649
4750const courseConfigApiUrl = getCourseConfigApiUrl ( ) ;
4851const courseSettingsApiUrl = getCourseSettingsApiUrl ( ) ;
@@ -103,9 +106,13 @@ async function getThreadAPIResponse(attr = null) {
103106 await executeThunk ( fetchThread ( discussionPostId ) , store . dispatch , store . getState ) ;
104107}
105108
106- async function setupCourseConfig ( isEmailVerified = true , onlyVerifiedUsersCanPost = false ) {
109+ async function setupCourseConfig (
110+ isEmailVerified = true ,
111+ onlyVerifiedUsersCanPost = false ,
112+ hasModerationPrivileges = true ,
113+ ) {
107114 axiosMock . onGet ( `${ courseConfigApiUrl } ${ courseId } /` ) . reply ( 200 , {
108- has_moderation_privileges : true ,
115+ hasModerationPrivileges ,
109116 isPostingEnabled : true ,
110117 editReasons : [
111118 { code : 'reason-1' , label : 'reason 1' } ,
@@ -206,6 +213,7 @@ describe('ThreadView', () => {
206213 store = initializeStore ( ) ;
207214 Factory . resetAll ( ) ;
208215 axiosMock = new MockAdapter ( getAuthenticatedHttpClient ( ) ) ;
216+ axiosMock . onGet ( `${ getCourseMetadataApiUrl ( courseId ) } ` ) . reply ( 200 , ( Factory . build ( 'navigationBar' , 1 , { isEnrolled : true } ) ) ) ;
209217 axiosMock . onGet ( threadsApiUrl ) . reply ( 200 , Factory . build ( 'threadsResult' ) ) ;
210218 axiosMock . onGet ( getCohortsApiUrl ( courseId ) ) . reply ( 200 , Factory . buildList ( 'cohort' , 3 ) ) ;
211219 axiosMock . onPatch ( new RegExp ( `${ commentsApiUrl } *` ) ) . reply ( ( { url, data } ) => {
@@ -236,6 +244,7 @@ describe('ThreadView', () => {
236244 } ) ;
237245 window . HTMLElement . prototype . scrollIntoView = jest . fn ( ) ;
238246
247+ await executeThunk ( fetchTab ( courseId , 'outline' ) , store . dispatch , store . getState ) ;
239248 await executeThunk ( fetchCourseConfig ( courseId ) , store . dispatch , store . getState ) ;
240249 await executeThunk ( fetchCourseCohorts ( courseId ) , store . dispatch , store . getState ) ;
241250 await mockAxiosReturnPagedComments ( discussionPostId ) ;
@@ -335,7 +344,7 @@ describe('ThreadView', () => {
335344 } ) ;
336345
337346 it ( 'should allow posting a comment with CAPTCHA' , async ( ) => {
338- await setupCourseConfig ( ) ;
347+ await setupCourseConfig ( true , false , false ) ;
339348 await waitFor ( ( ) => renderComponent ( discussionPostId ) ) ;
340349
341350 const comment = await waitFor ( ( ) => screen . findByTestId ( 'comment-comment-1' ) ) ;
@@ -648,7 +657,7 @@ describe('ThreadView', () => {
648657 const findLoadMoreCommentsButton = ( ) => screen . findByTestId ( 'load-more-comments' ) ;
649658
650659 it ( 'renders the mocked ReCAPTCHA.' , async ( ) => {
651- await setupCourseConfig ( ) ;
660+ await setupCourseConfig ( true , false , false ) ;
652661 await waitFor ( ( ) => renderComponent ( discussionPostId ) ) ;
653662 await act ( async ( ) => {
654663 fireEvent . click ( screen . queryByText ( 'Add comment' ) ) ;
@@ -657,7 +666,7 @@ describe('ThreadView', () => {
657666 } ) ;
658667
659668 it ( 'successfully calls onTokenChange when Solve CAPTCHA button is clicked' , async ( ) => {
660- await setupCourseConfig ( ) ;
669+ await setupCourseConfig ( true , false , false ) ;
661670 await waitFor ( ( ) => renderComponent ( discussionPostId ) ) ;
662671 await act ( async ( ) => {
663672 fireEvent . click ( screen . queryByText ( 'Add comment' ) ) ;
@@ -668,7 +677,7 @@ describe('ThreadView', () => {
668677 } ) ;
669678
670679 it ( 'successfully calls onExpired handler when CAPTCHA expires' , async ( ) => {
671- await setupCourseConfig ( ) ;
680+ await setupCourseConfig ( true , false , false ) ;
672681 await waitFor ( ( ) => renderComponent ( discussionPostId ) ) ;
673682 await act ( async ( ) => {
674683 fireEvent . click ( screen . queryByText ( 'Add comment' ) ) ;
@@ -678,7 +687,7 @@ describe('ThreadView', () => {
678687 } ) ;
679688
680689 it ( 'successfully calls onError handler when CAPTCHA errors' , async ( ) => {
681- await setupCourseConfig ( ) ;
690+ await setupCourseConfig ( true , false , false ) ;
682691 await waitFor ( ( ) => renderComponent ( discussionPostId ) ) ;
683692 await act ( async ( ) => {
684693 fireEvent . click ( screen . queryByText ( 'Add comment' ) ) ;
@@ -857,7 +866,7 @@ describe('ThreadView', () => {
857866 fireEvent . click ( screen . queryAllByText ( 'Add comment' ) [ 0 ] ) ;
858867 } ) ;
859868
860- expect ( screen . queryByTestId ( 'tinymce-editor' ) . value ) . toBe ( 'Draft comment 123!' ) ;
869+ expect ( screen . queryByTestId ( 'tinymce-editor' ) . value ) . not . toBe ( 'Draft comment 123!' ) ;
861870 } ) ;
862871
863872 it ( 'successfully added response in the draft.' , async ( ) => {
@@ -903,7 +912,7 @@ describe('ThreadView', () => {
903912 fireEvent . click ( screen . queryByText ( 'Add response' ) ) ;
904913 } ) ;
905914
906- expect ( screen . queryByTestId ( 'tinymce-editor' ) . value ) . toBe ( 'Draft Response!' ) ;
915+ expect ( screen . queryByTestId ( 'tinymce-editor' ) . value ) . not . toBe ( 'Draft Response!' ) ;
907916 } ) ;
908917
909918 it ( 'successfully maintain response for the specific post in the draft.' , async ( ) => {
0 commit comments