@@ -29,7 +29,7 @@ let store;
2929let axiosMock ;
3030
3131async function renderComponent ( {
32- postId, topicId, category, myPosts,
32+ postId, topicId, category, myPosts, inContext = false ,
3333} = { myPosts : false } ) {
3434 let path = generatePath ( Routes . POSTS . ALL_POSTS , { courseId } ) ;
3535 let page ;
@@ -56,6 +56,7 @@ async function renderComponent({
5656 topicId,
5757 category,
5858 page,
59+ inContext,
5960 } }
6061 >
6162 < Switch >
@@ -85,12 +86,6 @@ describe('PostsView', () => {
8586 roles : [ ] ,
8687 } ,
8788 } ) ;
88-
89- store = initializeStore ( {
90- blocks : { blocks : { 'test-usage-key' : { topics : [ 'some-topic-2' , 'some-topic-0' ] } } } ,
91- config : { hasModerationPrivileges : true } ,
92- } ) ;
93- store . dispatch ( fetchConfigSuccess ( { } ) ) ;
9489 Factory . resetAll ( ) ;
9590 axiosMock = new MockAdapter ( getAuthenticatedHttpClient ( ) ) ;
9691 axiosMock . onGet ( getCohortsApiUrl ( courseId ) ) . reply ( 200 , Factory . buildList ( 'cohort' , 1 ) ) ;
@@ -109,36 +104,71 @@ describe('PostsView', () => {
109104 } ) ;
110105 } ) ;
111106
107+ function setupStore ( data = { } ) {
108+ const storeData = {
109+ blocks : { blocks : { 'test-usage-key' : { topics : [ 'some-topic-2' , 'some-topic-0' ] } } } ,
110+ config : { hasModerationPrivileges : true } ,
111+ ...data ,
112+ } ;
113+ // console.log(storeData);
114+ store = initializeStore ( storeData ) ;
115+ store . dispatch ( fetchConfigSuccess ( { } ) ) ;
116+ }
117+
112118 describe ( 'Basic' , ( ) => {
113119 test ( 'displays a list of all posts' , async ( ) => {
120+ setupStore ( ) ;
114121 await act ( async ( ) => {
115122 await renderComponent ( ) ;
116123 } ) ;
117124 expect ( screen . getAllByText ( / t h i s i s t h r e a d - \d + / i) ) . toHaveLength ( threadCount ) ;
118125 } ) ;
119126
120127 test ( 'displays a list of user posts' , async ( ) => {
128+ setupStore ( ) ;
121129 await act ( async ( ) => {
122130 await renderComponent ( { myPosts : true } ) ;
123131 } ) ;
124132 expect ( screen . getAllByText ( 'abc123' ) ) . toHaveLength ( threadCount ) ;
125133 } ) ;
126134
127135 test ( 'displays a list of posts in a topic' , async ( ) => {
136+ setupStore ( ) ;
128137 await act ( async ( ) => {
129138 await renderComponent ( { topicId : 'some-topic-1' } ) ;
130139 } ) ;
131140 expect ( screen . getAllByText ( / t h i s i s t h r e a d - \d + i n t o p i c s o m e - t o p i c - 1 / i) ) . toHaveLength ( Math . ceil ( threadCount / 3 ) ) ;
132141 } ) ;
133142
134- test ( 'displays a list of posts in a category' , async ( ) => {
135- await act ( async ( ) => {
136- await renderComponent ( { category : 'test-usage-key' } ) ;
137- } ) ;
138- expect ( screen . queryAllByText ( / t h i s i s t h r e a d - \d + i n t o p i c s o m e - t o p i c - 1 } / i) ) . toHaveLength ( 0 ) ;
139- expect ( screen . queryAllByText ( / t h i s i s t h r e a d - \d + i n t o p i c s o m e - t o p i c - 2 / i) ) . toHaveLength ( Math . ceil ( threadCount / 3 ) ) ;
140- expect ( screen . queryAllByText ( / t h i s i s t h r e a d - \d + i n t o p i c s o m e - t o p i c - 0 / i) ) . toHaveLength ( Math . ceil ( threadCount / 3 ) ) ;
141- } ) ;
143+ test . each ( [ true , false ] ) (
144+ 'displays a list of posts in a category with grouping at subsection = %s' ,
145+ async ( grouping ) => {
146+ setupStore ( {
147+ blocks : {
148+ blocks : {
149+ 'test-usage-key' : {
150+ type : 'vertical' ,
151+ topics : [ 'some-topic-2' , 'some-topic-0' ] ,
152+ parent : 'test-seq-key' ,
153+ } ,
154+ 'test-seq-key' : { type : 'sequential' , topics : [ 'some-topic-0' , 'some-topic-1' , 'some-topic-2' ] } ,
155+ } ,
156+ } ,
157+ config : { groupAtSubsection : grouping , hasModerationPrivileges : true , provider : 'openedx' } ,
158+ } ) ;
159+ await act ( async ( ) => {
160+ await renderComponent ( { category : 'test-usage-key' , inContext : true , p : true } ) ;
161+ } ) ;
162+ const topicThreadCount = Math . ceil ( threadCount / 3 ) ;
163+ expect ( screen . queryAllByText ( / t h i s i s t h r e a d - \d + i n t o p i c s o m e - t o p i c - 2 / i) )
164+ . toHaveLength ( topicThreadCount ) ;
165+ expect ( screen . queryAllByText ( / t h i s i s t h r e a d - \d + i n t o p i c s o m e - t o p i c - 0 / i) )
166+ . toHaveLength ( topicThreadCount ) ;
167+ // When grouping is enabled, topic 1 will be shown, but not otherwise.
168+ expect ( screen . queryAllByText ( / t h i s i s t h r e a d - \d + i n t o p i c s o m e - t o p i c - 1 / i) )
169+ . toHaveLength ( grouping ? topicThreadCount : 0 ) ;
170+ } ,
171+ ) ;
142172 } ) ;
143173
144174 describe ( 'Filtering' , ( ) => {
@@ -150,6 +180,7 @@ describe('PostsView', () => {
150180 }
151181
152182 beforeEach ( async ( ) => {
183+ setupStore ( ) ;
153184 await act ( async ( ) => {
154185 await renderComponent ( ) ;
155186 } ) ;
0 commit comments