11import { screen , waitFor } from '@testing-library/react' ;
22
3+ import { getConfig , setConfig } from '@edx/frontend-platform' ;
4+ import { PLUGIN_OPERATIONS , DIRECT_PLUGIN } from '@openedx/frontend-plugin-framework' ;
35import { PagesAndResources } from '.' ;
46import { render } from './utils.test' ;
57
8+ const mockPlugin = ( identifier ) => ( {
9+ plugins : [
10+ {
11+ op : PLUGIN_OPERATIONS . Insert ,
12+ widget : {
13+ id : 'mock-plugin-1' ,
14+ type : DIRECT_PLUGIN ,
15+ priority : 1 ,
16+ RenderWidget : ( ) => < div data-testid = { identifier } > HELLO</ div > ,
17+ } ,
18+ } ,
19+ ] ,
20+ } ) ;
21+
622const courseId = 'course-v1:edX+TestX+Test_Course' ;
723
824describe ( 'PagesAndResources' , ( ) => {
925 beforeEach ( ( ) => {
1026 jest . clearAllMocks ( ) ;
27+ setConfig ( {
28+ ...getConfig ( ) ,
29+ pluginSlots : {
30+ 'org.openedx.frontend.authoring.additional_course_plugin.v1' : mockPlugin ( 'additional_course_plugin' ) ,
31+ 'org.openedx.frontend.authoring.additional_course_content_plugin.v1' : mockPlugin ( 'additional_course_content_plugin' ) ,
32+ } ,
33+ } ) ;
1134 } ) ;
1235
13- it ( 'doesn\'t show content permissions section if relevant apps are not enabled' , ( ) => {
36+ it ( 'doesn\'t show content permissions section if relevant apps are not enabled' , async ( ) => {
1437 const initialState = {
1538 models : {
1639 courseApps : { } ,
@@ -25,8 +48,11 @@ describe('PagesAndResources', () => {
2548 { preloadedState : initialState } ,
2649 ) ;
2750
28- expect ( screen . queryByRole ( 'heading' , { name : 'Content permissions' } ) ) . not . toBeInTheDocument ( ) ;
51+ await waitFor ( ( ) => expect ( screen . queryByRole ( 'heading' , { name : 'Content permissions' } ) ) . not . toBeInTheDocument ( ) ) ;
52+ await waitFor ( ( ) => expect ( screen . queryByTestId ( 'additional_course_plugin' ) ) . toBeInTheDocument ( ) ) ;
53+ await waitFor ( ( ) => expect ( screen . queryByTestId ( 'additional_course_content_plugin' ) ) . not . toBeInTheDocument ( ) ) ;
2954 } ) ;
55+
3056 it ( 'show content permissions section if Learning Assistant app is enabled' , async ( ) => {
3157 const initialState = {
3258 models : {
@@ -56,6 +82,8 @@ describe('PagesAndResources', () => {
5682
5783 await waitFor ( ( ) => expect ( screen . getByRole ( 'heading' , { name : 'Content permissions' } ) ) . toBeInTheDocument ( ) ) ;
5884 await waitFor ( ( ) => expect ( screen . getByText ( 'Learning Assistant' ) ) . toBeInTheDocument ( ) ) ;
85+ await waitFor ( ( ) => expect ( screen . queryByTestId ( 'additional_course_plugin' ) ) . toBeInTheDocument ( ) ) ;
86+ await waitFor ( ( ) => expect ( screen . queryByTestId ( 'additional_course_content_plugin' ) ) . toBeInTheDocument ( ) ) ;
5987 } ) ;
6088
6189 it ( 'show content permissions section if Xpert learning summaries app is enabled' , async ( ) => {
@@ -89,5 +117,7 @@ describe('PagesAndResources', () => {
89117
90118 await waitFor ( ( ) => expect ( screen . getByRole ( 'heading' , { name : 'Content permissions' } ) ) . toBeInTheDocument ( ) ) ;
91119 await waitFor ( ( ) => expect ( screen . getByText ( 'Xpert unit summaries' ) ) . toBeInTheDocument ( ) ) ;
120+ await waitFor ( ( ) => expect ( screen . queryByTestId ( 'additional_course_plugin' ) ) . toBeInTheDocument ( ) ) ;
121+ await waitFor ( ( ) => expect ( screen . queryByTestId ( 'additional_course_content_plugin' ) ) . toBeInTheDocument ( ) ) ;
92122 } ) ;
93123} ) ;
0 commit comments