@@ -78,29 +78,29 @@ describe('<CourseLibraries />', () => {
78
78
const user = userEvent . setup ( ) ;
79
79
await renderCourseLibrariesPage ( mockGetEntityLinks . courseKey ) ;
80
80
const allTab = await screen . findByRole ( 'tab' , { name : 'Libraries' } ) ;
81
- const reviewTab = await screen . findByRole ( 'tab' , { name : 'Review Content Updates 5 ' } ) ;
81
+ const reviewTab = await screen . findByRole ( 'tab' , { name : 'Review Content Updates 7 ' } ) ;
82
82
// review tab should be open by default as outOfSyncCount is greater than 0
83
83
expect ( reviewTab ) . toHaveAttribute ( 'aria-selected' , 'true' ) ;
84
84
85
85
await user . click ( allTab ) ;
86
86
const alert = await screen . findByRole ( 'alert' ) ;
87
87
expect ( await within ( alert ) . findByText (
88
- '5 library components are out of sync. Review updates to accept or ignore changes' ,
88
+ '7 library components are out of sync. Review updates to accept or ignore changes' ,
89
89
) ) . toBeInTheDocument ( ) ;
90
90
expect ( allTab ) . toHaveAttribute ( 'aria-selected' , 'true' ) ;
91
91
92
92
const reviewBtn = await screen . findByRole ( 'button' , { name : 'Review' } ) ;
93
93
await user . click ( reviewBtn ) ;
94
94
95
95
expect ( allTab ) . toHaveAttribute ( 'aria-selected' , 'false' ) ;
96
- expect ( await screen . findByRole ( 'tab' , { name : 'Review Content Updates 5 ' } ) ) . toHaveAttribute ( 'aria-selected' , 'true' ) ;
96
+ expect ( await screen . findByRole ( 'tab' , { name : 'Review Content Updates 7 ' } ) ) . toHaveAttribute ( 'aria-selected' , 'true' ) ;
97
97
expect ( alert ) . not . toBeInTheDocument ( ) ;
98
98
} ) ;
99
99
100
100
it ( 'hide alert on dismiss' , async ( ) => {
101
101
const user = userEvent . setup ( ) ;
102
102
await renderCourseLibrariesPage ( mockGetEntityLinks . courseKey ) ;
103
- const reviewTab = await screen . findByRole ( 'tab' , { name : 'Review Content Updates 5 ' } ) ;
103
+ const reviewTab = await screen . findByRole ( 'tab' , { name : 'Review Content Updates 7 ' } ) ;
104
104
// review tab should be open by default as outOfSyncCount is greater than 0
105
105
expect ( reviewTab ) . toHaveAttribute ( 'aria-selected' , 'true' ) ;
106
106
const allTab = await screen . findByRole ( 'tab' , { name : 'Libraries' } ) ;
@@ -109,7 +109,7 @@ describe('<CourseLibraries />', () => {
109
109
110
110
const alert = await screen . findByRole ( 'alert' ) ;
111
111
expect ( await within ( alert ) . findByText (
112
- '5 library components are out of sync. Review updates to accept or ignore changes' ,
112
+ '7 library components are out of sync. Review updates to accept or ignore changes' ,
113
113
) ) . toBeInTheDocument ( ) ;
114
114
const dismissBtn = await screen . findByRole ( 'button' , { name : 'Dismiss' } ) ;
115
115
await user . click ( dismissBtn ) ;
@@ -118,7 +118,7 @@ describe('<CourseLibraries />', () => {
118
118
// review updates button
119
119
const reviewActionBtn = await screen . findByRole ( 'button' , { name : 'Review Updates' } ) ;
120
120
await user . click ( reviewActionBtn ) ;
121
- expect ( await screen . findByRole ( 'tab' , { name : 'Review Content Updates 5 ' } ) ) . toHaveAttribute ( 'aria-selected' , 'true' ) ;
121
+ expect ( await screen . findByRole ( 'tab' , { name : 'Review Content Updates 7 ' } ) ) . toHaveAttribute ( 'aria-selected' , 'true' ) ;
122
122
} ) ;
123
123
124
124
it ( 'show alert if max lastPublishedDate is greated than the local storage value' , async ( ) => {
@@ -131,14 +131,14 @@ describe('<CourseLibraries />', () => {
131
131
132
132
await renderCourseLibrariesPage ( mockGetEntityLinks . courseKey ) ;
133
133
const allTab = await screen . findByRole ( 'tab' , { name : 'Libraries' } ) ;
134
- const reviewTab = await screen . findByRole ( 'tab' , { name : 'Review Content Updates 5 ' } ) ;
134
+ const reviewTab = await screen . findByRole ( 'tab' , { name : 'Review Content Updates 7 ' } ) ;
135
135
// review tab should be open by default as outOfSyncCount is greater than 0
136
136
expect ( reviewTab ) . toHaveAttribute ( 'aria-selected' , 'true' ) ;
137
137
138
138
await user . click ( allTab ) ;
139
139
const alert = await screen . findByRole ( 'alert' ) ;
140
140
expect ( await within ( alert ) . findByText (
141
- '5 library components are out of sync. Review updates to accept or ignore changes' ,
141
+ '7 library components are out of sync. Review updates to accept or ignore changes' ,
142
142
) ) . toBeInTheDocument ( ) ;
143
143
} ) ;
144
144
@@ -152,14 +152,12 @@ describe('<CourseLibraries />', () => {
152
152
153
153
await renderCourseLibrariesPage ( mockGetEntityLinks . courseKey ) ;
154
154
const allTab = await screen . findByRole ( 'tab' , { name : 'Libraries' } ) ;
155
- const reviewTab = await screen . findByRole ( 'tab' , { name : 'Review Content Updates 5 ' } ) ;
155
+ const reviewTab = await screen . findByRole ( 'tab' , { name : 'Review Content Updates 7 ' } ) ;
156
156
// review tab should be open by default as outOfSyncCount is greater than 0
157
157
expect ( reviewTab ) . toHaveAttribute ( 'aria-selected' , 'true' ) ;
158
158
await user . click ( allTab ) ;
159
159
expect ( allTab ) . toHaveAttribute ( 'aria-selected' , 'true' ) ;
160
160
161
- screen . logTestingPlaygroundURL ( ) ;
162
-
163
161
expect ( screen . queryByRole ( 'alert' ) ) . not . toBeInTheDocument ( ) ;
164
162
} ) ;
165
163
} ) ;
@@ -195,60 +193,93 @@ describe('<CourseLibraries ReviewTab />', () => {
195
193
} ) ;
196
194
197
195
it ( 'shows all readyToSync links' , async ( ) => {
198
- await renderCourseLibrariesReviewPage ( mockGetEntityLinksSummaryByDownstreamContext . courseKey ) ;
196
+ await renderCourseLibrariesReviewPage ( ) ;
199
197
const updateBtns = await screen . findAllByRole ( 'button' , { name : 'Update' } ) ;
200
- expect ( updateBtns . length ) . toEqual ( 5 ) ;
198
+ expect ( updateBtns . length ) . toEqual ( 7 ) ;
201
199
const ignoreBtns = await screen . findAllByRole ( 'button' , { name : 'Ignore' } ) ;
202
- expect ( ignoreBtns . length ) . toEqual ( 5 ) ;
200
+ expect ( ignoreBtns . length ) . toEqual ( 7 ) ;
203
201
} ) ;
204
202
205
- it ( 'update changes works' , async ( ) => {
203
+ test . each ( [
204
+ {
205
+ label : 'update changes works with components' ,
206
+ itemIndex : 0 ,
207
+ expectedToastMsg : 'Success! "Dropdown" is updated' ,
208
+ } ,
209
+ {
210
+ label : 'update changes works with containers' ,
211
+ itemIndex : 5 ,
212
+ expectedToastMsg : 'Success! "Unit 1" is updated' ,
213
+ } ,
214
+ ] ) ( '$label' , async ( { itemIndex, expectedToastMsg } ) => {
206
215
const user = userEvent . setup ( ) ;
207
216
const mockInvalidateQueries = jest . spyOn ( queryClient , 'invalidateQueries' ) ;
208
- const usageKey = mockGetEntityLinks . response [ 0 ] . downstreamUsageKey ;
217
+ const usageKey = mockGetEntityLinks . response [ itemIndex ] . downstreamUsageKey ;
209
218
axiosMock . onPost ( libraryBlockChangesUrl ( usageKey ) ) . reply ( 200 , { } ) ;
210
219
await renderCourseLibrariesReviewPage ( mockGetEntityLinksSummaryByDownstreamContext . courseKey ) ;
211
220
const updateBtns = await screen . findAllByRole ( 'button' , { name : 'Update' } ) ;
212
- expect ( updateBtns . length ) . toEqual ( 5 ) ;
213
- await user . click ( updateBtns [ 0 ] ) ;
221
+ expect ( updateBtns . length ) . toEqual ( 7 ) ;
222
+ await user . click ( updateBtns [ itemIndex ] ) ;
214
223
await waitFor ( ( ) => {
215
224
expect ( axiosMock . history . post . length ) . toEqual ( 1 ) ;
216
225
} ) ;
217
226
expect ( axiosMock . history . post [ 0 ] . url ) . toEqual ( libraryBlockChangesUrl ( usageKey ) ) ;
218
- expect ( mockShowToast ) . toHaveBeenCalledWith ( 'Success! "Dropdown" is updated' ) ;
219
- expect ( mockInvalidateQueries ) . toHaveBeenCalledWith ( [ 'courseLibraries' , 'course-v1:OpenEdx+DemoX+CourseX' ] ) ;
227
+ expect ( mockShowToast ) . toHaveBeenCalledWith ( expectedToastMsg ) ;
228
+ expect ( mockInvalidateQueries ) . toHaveBeenCalledWith ( { queryKey : [ 'courseLibraries' , 'course-v1:OpenEdx+DemoX+CourseX' ] } ) ;
220
229
} ) ;
221
230
222
- it ( 'update changes works in preview modal' , async ( ) => {
231
+ test . each ( [
232
+ {
233
+ label : 'update changes works in preview modal with components' ,
234
+ itemIndex : 0 ,
235
+ expectedToastMsg : 'Success! "Dropdown" is updated' ,
236
+ } ,
237
+ {
238
+ label : 'update changes works in preview modal with containers' ,
239
+ itemIndex : 5 ,
240
+ expectedToastMsg : 'Success! "Unit 1" is updated' ,
241
+ } ,
242
+ ] ) ( '$label' , async ( { itemIndex, expectedToastMsg } ) => {
223
243
const user = userEvent . setup ( ) ;
224
244
const mockInvalidateQueries = jest . spyOn ( queryClient , 'invalidateQueries' ) ;
225
- const usageKey = mockGetEntityLinks . response [ 0 ] . downstreamUsageKey ;
245
+ const usageKey = mockGetEntityLinks . response [ itemIndex ] . downstreamUsageKey ;
226
246
axiosMock . onPost ( libraryBlockChangesUrl ( usageKey ) ) . reply ( 200 , { } ) ;
227
247
await renderCourseLibrariesReviewPage ( mockGetEntityLinksSummaryByDownstreamContext . courseKey ) ;
228
248
const previewBtns = await screen . findAllByRole ( 'button' , { name : 'Review Updates' } ) ;
229
- expect ( previewBtns . length ) . toEqual ( 5 ) ;
230
- await user . click ( previewBtns [ 0 ] ) ;
249
+ expect ( previewBtns . length ) . toEqual ( 7 ) ;
250
+ await user . click ( previewBtns [ itemIndex ] ) ;
231
251
const dialog = await screen . findByRole ( 'dialog' ) ;
232
252
const confirmBtn = await within ( dialog ) . findByRole ( 'button' , { name : 'Accept changes' } ) ;
233
253
await user . click ( confirmBtn ) ;
234
254
await waitFor ( ( ) => {
235
255
expect ( axiosMock . history . post . length ) . toEqual ( 1 ) ;
236
256
} ) ;
237
257
expect ( axiosMock . history . post [ 0 ] . url ) . toEqual ( libraryBlockChangesUrl ( usageKey ) ) ;
238
- expect ( mockShowToast ) . toHaveBeenCalledWith ( 'Success! "Dropdown" is updated' ) ;
239
- expect ( mockInvalidateQueries ) . toHaveBeenCalledWith ( [ 'courseLibraries' , 'course-v1:OpenEdx+DemoX+CourseX' ] ) ;
258
+ expect ( mockShowToast ) . toHaveBeenCalledWith ( expectedToastMsg ) ;
259
+ expect ( mockInvalidateQueries ) . toHaveBeenCalledWith ( { queryKey : [ 'courseLibraries' , 'course-v1:OpenEdx+DemoX+CourseX' ] } ) ;
240
260
} ) ;
241
261
242
- it ( 'ignore change works' , async ( ) => {
262
+ test . each ( [
263
+ {
264
+ label : 'ignore change works with components' ,
265
+ itemIndex : 0 ,
266
+ expectedToastMsg : '"Dropdown" will remain out of sync with library content. You will be notified when this component is updated again.' ,
267
+ } ,
268
+ {
269
+ label : 'ignore change works with containers' ,
270
+ itemIndex : 5 ,
271
+ expectedToastMsg : '"Unit 1" will remain out of sync with library content. You will be notified when this component is updated again.' ,
272
+ } ,
273
+ ] ) ( '$label' , async ( { itemIndex, expectedToastMsg } ) => {
243
274
const user = userEvent . setup ( ) ;
244
275
const mockInvalidateQueries = jest . spyOn ( queryClient , 'invalidateQueries' ) ;
245
- const usageKey = mockGetEntityLinks . response [ 0 ] . downstreamUsageKey ;
276
+ const usageKey = mockGetEntityLinks . response [ itemIndex ] . downstreamUsageKey ;
246
277
axiosMock . onDelete ( libraryBlockChangesUrl ( usageKey ) ) . reply ( 204 , { } ) ;
247
278
await renderCourseLibrariesReviewPage ( mockGetEntityLinksSummaryByDownstreamContext . courseKey ) ;
248
279
const ignoreBtns = await screen . findAllByRole ( 'button' , { name : 'Ignore' } ) ;
249
- expect ( ignoreBtns . length ) . toEqual ( 5 ) ;
280
+ expect ( ignoreBtns . length ) . toEqual ( 7 ) ;
250
281
// Show confirmation modal on clicking ignore.
251
- await user . click ( ignoreBtns [ 0 ] ) ;
282
+ await user . click ( ignoreBtns [ itemIndex ] ) ;
252
283
const dialog = await screen . findByRole ( 'dialog' , { name : 'Ignore these changes?' } ) ;
253
284
expect ( dialog ) . toBeInTheDocument ( ) ;
254
285
const confirmBtn = await within ( dialog ) . findByRole ( 'button' , { name : 'Ignore' } ) ;
@@ -257,21 +288,30 @@ describe('<CourseLibraries ReviewTab />', () => {
257
288
expect ( axiosMock . history . delete . length ) . toEqual ( 1 ) ;
258
289
} ) ;
259
290
expect ( axiosMock . history . delete [ 0 ] . url ) . toEqual ( libraryBlockChangesUrl ( usageKey ) ) ;
260
- expect ( mockShowToast ) . toHaveBeenCalledWith (
261
- '"Dropdown" will remain out of sync with library content. You will be notified when this component is updated again.' ,
262
- ) ;
263
- expect ( mockInvalidateQueries ) . toHaveBeenCalledWith ( [ 'courseLibraries' , 'course-v1:OpenEdx+DemoX+CourseX' ] ) ;
291
+ expect ( mockShowToast ) . toHaveBeenCalledWith ( expectedToastMsg ) ;
292
+ expect ( mockInvalidateQueries ) . toHaveBeenCalledWith ( { queryKey : [ 'courseLibraries' , 'course-v1:OpenEdx+DemoX+CourseX' ] } ) ;
264
293
} ) ;
265
294
266
- it ( 'ignore change works in preview' , async ( ) => {
295
+ test . each ( [
296
+ {
297
+ label : 'ignore change works with components' ,
298
+ itemIndex : 0 ,
299
+ expectedToastMsg : '"Dropdown" will remain out of sync with library content. You will be notified when this component is updated again.' ,
300
+ } ,
301
+ {
302
+ label : 'ignore change works with containers' ,
303
+ itemIndex : 5 ,
304
+ expectedToastMsg : '"Unit 1" will remain out of sync with library content. You will be notified when this component is updated again.' ,
305
+ } ,
306
+ ] ) ( '$label' , async ( { itemIndex, expectedToastMsg } ) => {
267
307
const user = userEvent . setup ( ) ;
268
308
const mockInvalidateQueries = jest . spyOn ( queryClient , 'invalidateQueries' ) ;
269
- const usageKey = mockGetEntityLinks . response [ 0 ] . downstreamUsageKey ;
309
+ const usageKey = mockGetEntityLinks . response [ itemIndex ] . downstreamUsageKey ;
270
310
axiosMock . onDelete ( libraryBlockChangesUrl ( usageKey ) ) . reply ( 204 , { } ) ;
271
311
await renderCourseLibrariesReviewPage ( mockGetEntityLinksSummaryByDownstreamContext . courseKey ) ;
272
312
const previewBtns = await screen . findAllByRole ( 'button' , { name : 'Review Updates' } ) ;
273
- expect ( previewBtns . length ) . toEqual ( 5 ) ;
274
- await user . click ( previewBtns [ 0 ] ) ;
313
+ expect ( previewBtns . length ) . toEqual ( 7 ) ;
314
+ await user . click ( previewBtns [ itemIndex ] ) ;
275
315
const previewDialog = await screen . findByRole ( 'dialog' ) ;
276
316
const ignoreBtn = await within ( previewDialog ) . findByRole ( 'button' , { name : 'Ignore changes' } ) ;
277
317
await user . click ( ignoreBtn ) ;
@@ -284,9 +324,7 @@ describe('<CourseLibraries ReviewTab />', () => {
284
324
expect ( axiosMock . history . delete . length ) . toEqual ( 1 ) ;
285
325
} ) ;
286
326
expect ( axiosMock . history . delete [ 0 ] . url ) . toEqual ( libraryBlockChangesUrl ( usageKey ) ) ;
287
- expect ( mockShowToast ) . toHaveBeenCalledWith (
288
- '"Dropdown" will remain out of sync with library content. You will be notified when this component is updated again.' ,
289
- ) ;
290
- expect ( mockInvalidateQueries ) . toHaveBeenCalledWith ( [ 'courseLibraries' , 'course-v1:OpenEdx+DemoX+CourseX' ] ) ;
327
+ expect ( mockShowToast ) . toHaveBeenCalledWith ( expectedToastMsg ) ;
328
+ expect ( mockInvalidateQueries ) . toHaveBeenCalledWith ( { queryKey : [ 'courseLibraries' , 'course-v1:OpenEdx+DemoX+CourseX' ] } ) ;
291
329
} ) ;
292
330
} ) ;
0 commit comments