@@ -83,15 +83,27 @@ const libraryData: ContentLibrary = {
83
83
numBlocks : 2 ,
84
84
version : 0 ,
85
85
lastPublished : null ,
86
+ lastDraftCreated : '2024-07-22' ,
87
+ publishedBy : 'staff' ,
88
+ lastDraftCreatedBy : 'staff' ,
86
89
allowLti : false ,
87
90
allowPublicLearning : false ,
88
91
allowPublicRead : false ,
89
92
hasUnpublishedChanges : true ,
90
93
hasUnpublishedDeletes : false ,
91
94
canEditLibrary : true ,
92
95
license : '' ,
96
+ created : '2024-06-26' ,
97
+ updated : '2024-07-20' ,
93
98
} ;
94
99
100
+ const clipboardBroadcastChannelMock = {
101
+ postMessage : jest . fn ( ) ,
102
+ close : jest . fn ( ) ,
103
+ } ;
104
+
105
+ ( global as any ) . BroadcastChannel = jest . fn ( ( ) => clipboardBroadcastChannelMock ) ;
106
+
95
107
const RootWrapper = ( ) => (
96
108
< AppProvider store = { store } >
97
109
< IntlProvider locale = "en" messages = { { } } >
@@ -177,23 +189,23 @@ describe('<LibraryAuthoringPage />', () => {
177
189
axiosMock . onGet ( getContentLibraryApiUrl ( libraryData . id ) ) . reply ( 200 , libraryData ) ;
178
190
179
191
const {
180
- getByRole, getByText, getAllByText , queryByText ,
192
+ getByRole, getByText, queryByText , findByText , findAllByText ,
181
193
} = render ( < RootWrapper /> ) ;
182
194
183
195
// Ensure the search endpoint is called:
184
196
// Call 1: To fetch searchable/filterable/sortable library data
185
197
// Call 2: To fetch the recently modified components only
186
198
await waitFor ( ( ) => { expect ( fetchMock ) . toHaveFetchedTimes ( 2 , searchEndpoint , 'post' ) ; } ) ;
187
199
188
- expect ( getByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
189
- expect ( getByText ( libraryData . title ) ) . toBeInTheDocument ( ) ;
200
+ expect ( await findByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
201
+ expect ( ( await findAllByText ( libraryData . title ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
190
202
191
203
expect ( queryByText ( 'You have not added any content to this library yet.' ) ) . not . toBeInTheDocument ( ) ;
192
204
193
205
expect ( getByText ( 'Recently Modified' ) ) . toBeInTheDocument ( ) ;
194
206
expect ( getByText ( 'Collections (0)' ) ) . toBeInTheDocument ( ) ;
195
207
expect ( getByText ( 'Components (6)' ) ) . toBeInTheDocument ( ) ;
196
- expect ( getAllByText ( 'Test HTML Block' ) [ 0 ] ) . toBeInTheDocument ( ) ;
208
+ expect ( ( await findAllByText ( 'Test HTML Block' ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
197
209
198
210
// Navigate to the components tab
199
211
fireEvent . click ( getByRole ( 'tab' , { name : 'Components' } ) ) ;
@@ -222,10 +234,10 @@ describe('<LibraryAuthoringPage />', () => {
222
234
axiosMock . onGet ( getContentLibraryApiUrl ( libraryData . id ) ) . reply ( 200 , libraryData ) ;
223
235
fetchMock . post ( searchEndpoint , returnEmptyResult , { overwriteRoutes : true } ) ;
224
236
225
- const { findByText, getByText } = render ( < RootWrapper /> ) ;
237
+ const { findByText, getByText, findAllByText } = render ( < RootWrapper /> ) ;
226
238
227
239
expect ( await findByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
228
- expect ( await findByText ( libraryData . title ) ) . toBeInTheDocument ( ) ;
240
+ expect ( ( await findAllByText ( libraryData . title ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
229
241
230
242
// Ensure the search endpoint is called:
231
243
// Call 1: To fetch searchable/filterable/sortable library data
@@ -282,10 +294,15 @@ describe('<LibraryAuthoringPage />', () => {
282
294
axiosMock . onGet ( getContentLibraryApiUrl ( libraryData . id ) ) . reply ( 200 , libraryData ) ;
283
295
fetchMock . post ( searchEndpoint , returnEmptyResult , { overwriteRoutes : true } ) ;
284
296
285
- const { findByText, getByRole, getByText } = render ( < RootWrapper /> ) ;
297
+ const {
298
+ findByText,
299
+ getByRole,
300
+ getByText,
301
+ findAllByText,
302
+ } = render ( < RootWrapper /> ) ;
286
303
287
304
expect ( await findByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
288
- expect ( await findByText ( libraryData . title ) ) . toBeInTheDocument ( ) ;
305
+ expect ( ( await findAllByText ( libraryData . title ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
289
306
290
307
// Ensure the search endpoint is called:
291
308
// Call 1: To fetch searchable/filterable/sortable library data
@@ -329,12 +346,54 @@ describe('<LibraryAuthoringPage />', () => {
329
346
expect ( screen . queryByText ( / a d d c o n t e n t / i) ) . not . toBeInTheDocument ( ) ;
330
347
} ) ;
331
348
349
+ it ( 'should open Library Info by default' , async ( ) => {
350
+ mockUseParams . mockReturnValue ( { libraryId : libraryData . id } ) ;
351
+ axiosMock . onGet ( getContentLibraryApiUrl ( libraryData . id ) ) . reply ( 200 , libraryData ) ;
352
+
353
+ render ( < RootWrapper /> ) ;
354
+
355
+ expect ( await screen . findByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
356
+ expect ( ( await screen . findAllByText ( libraryData . title ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
357
+ expect ( ( await screen . findAllByText ( libraryData . title ) ) [ 1 ] ) . toBeInTheDocument ( ) ;
358
+
359
+ expect ( screen . getByText ( 'Draft' ) ) . toBeInTheDocument ( ) ;
360
+ expect ( screen . getByText ( '(Never Published)' ) ) . toBeInTheDocument ( ) ;
361
+ expect ( screen . getByText ( 'July 22, 2024' ) ) . toBeInTheDocument ( ) ;
362
+ expect ( screen . getByText ( 'staff' ) ) . toBeInTheDocument ( ) ;
363
+ expect ( screen . getByText ( libraryData . org ) ) . toBeInTheDocument ( ) ;
364
+ expect ( screen . getByText ( 'July 20, 2024' ) ) . toBeInTheDocument ( ) ;
365
+ expect ( screen . getByText ( 'June 26, 2024' ) ) . toBeInTheDocument ( ) ;
366
+ } ) ;
367
+
368
+ it ( 'should close and open Library Info' , async ( ) => {
369
+ mockUseParams . mockReturnValue ( { libraryId : libraryData . id } ) ;
370
+ axiosMock . onGet ( getContentLibraryApiUrl ( libraryData . id ) ) . reply ( 200 , libraryData ) ;
371
+
372
+ render ( < RootWrapper /> ) ;
373
+
374
+ expect ( await screen . findByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
375
+ expect ( ( await screen . findAllByText ( libraryData . title ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
376
+ expect ( ( await screen . findAllByText ( libraryData . title ) ) [ 1 ] ) . toBeInTheDocument ( ) ;
377
+
378
+ const closeButton = screen . getByRole ( 'button' , { name : / c l o s e / i } ) ;
379
+ fireEvent . click ( closeButton ) ;
380
+
381
+ expect ( screen . queryByText ( 'Draft' ) ) . not . toBeInTheDocument ( ) ;
382
+ expect ( screen . queryByText ( '(Never Published)' ) ) . not . toBeInTheDocument ( ) ;
383
+
384
+ const libraryInfoButton = screen . getByRole ( 'button' , { name : / l i b r a r y i n f o / i } ) ;
385
+ fireEvent . click ( libraryInfoButton ) ;
386
+
387
+ expect ( screen . getByText ( 'Draft' ) ) . toBeInTheDocument ( ) ;
388
+ expect ( screen . getByText ( '(Never Published)' ) ) . toBeInTheDocument ( ) ;
389
+ } ) ;
390
+
332
391
it ( 'show the "View All" button when viewing library with many components' , async ( ) => {
333
392
mockUseParams . mockReturnValue ( { libraryId : libraryData . id } ) ;
334
393
axiosMock . onGet ( getContentLibraryApiUrl ( libraryData . id ) ) . reply ( 200 , libraryData ) ;
335
394
336
395
const {
337
- getByRole, getByText, queryByText, getAllByText,
396
+ getByRole, getByText, queryByText, getAllByText, findAllByText ,
338
397
} = render ( < RootWrapper /> ) ;
339
398
340
399
// Ensure the search endpoint is called:
@@ -343,7 +402,7 @@ describe('<LibraryAuthoringPage />', () => {
343
402
await waitFor ( ( ) => { expect ( fetchMock ) . toHaveFetchedTimes ( 2 , searchEndpoint , 'post' ) ; } ) ;
344
403
345
404
expect ( getByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
346
- expect ( getByText ( libraryData . title ) ) . toBeInTheDocument ( ) ;
405
+ expect ( ( await findAllByText ( libraryData . title ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
347
406
348
407
await waitFor ( ( ) => { expect ( getByText ( 'Recently Modified' ) ) . toBeInTheDocument ( ) ; } ) ;
349
408
expect ( getByText ( 'Collections (0)' ) ) . toBeInTheDocument ( ) ;
@@ -376,7 +435,7 @@ describe('<LibraryAuthoringPage />', () => {
376
435
fetchMock . post ( searchEndpoint , returnLowNumberResults , { overwriteRoutes : true } ) ;
377
436
378
437
const {
379
- getByText, queryByText, getAllByText,
438
+ getByText, queryByText, getAllByText, findAllByText ,
380
439
} = render ( < RootWrapper /> ) ;
381
440
382
441
// Ensure the search endpoint is called:
@@ -385,7 +444,7 @@ describe('<LibraryAuthoringPage />', () => {
385
444
await waitFor ( ( ) => { expect ( fetchMock ) . toHaveFetchedTimes ( 2 , searchEndpoint , 'post' ) ; } ) ;
386
445
387
446
expect ( getByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
388
- expect ( getByText ( libraryData . title ) ) . toBeInTheDocument ( ) ;
447
+ expect ( ( await findAllByText ( libraryData . title ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
389
448
390
449
await waitFor ( ( ) => { expect ( getByText ( 'Recently Modified' ) ) . toBeInTheDocument ( ) ; } ) ;
391
450
expect ( getByText ( 'Collections (0)' ) ) . toBeInTheDocument ( ) ;
0 commit comments