1
1
import { screen , waitFor } from '@testing-library/react' ;
2
2
3
+ import { getConfig , setConfig } from '@edx/frontend-platform' ;
4
+ import { PLUGIN_OPERATIONS , DIRECT_PLUGIN } from '@openedx/frontend-plugin-framework' ;
3
5
import { PagesAndResources } from '.' ;
4
6
import { render } from './utils.test' ;
5
7
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
+
6
22
const courseId = 'course-v1:edX+TestX+Test_Course' ;
7
23
8
24
describe ( 'PagesAndResources' , ( ) => {
9
25
beforeEach ( ( ) => {
10
26
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
+ } ) ;
11
34
} ) ;
12
35
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 ( ) => {
14
37
const initialState = {
15
38
models : {
16
39
courseApps : { } ,
@@ -25,8 +48,11 @@ describe('PagesAndResources', () => {
25
48
{ preloadedState : initialState } ,
26
49
) ;
27
50
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 ( ) ) ;
29
54
} ) ;
55
+
30
56
it ( 'show content permissions section if Learning Assistant app is enabled' , async ( ) => {
31
57
const initialState = {
32
58
models : {
@@ -56,6 +82,8 @@ describe('PagesAndResources', () => {
56
82
57
83
await waitFor ( ( ) => expect ( screen . getByRole ( 'heading' , { name : 'Content permissions' } ) ) . toBeInTheDocument ( ) ) ;
58
84
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 ( ) ) ;
59
87
} ) ;
60
88
61
89
it ( 'show content permissions section if Xpert learning summaries app is enabled' , async ( ) => {
@@ -89,5 +117,7 @@ describe('PagesAndResources', () => {
89
117
90
118
await waitFor ( ( ) => expect ( screen . getByRole ( 'heading' , { name : 'Content permissions' } ) ) . toBeInTheDocument ( ) ) ;
91
119
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 ( ) ) ;
92
122
} ) ;
93
123
} ) ;
0 commit comments