@@ -83,13 +83,18 @@ 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
95
100
const RootWrapper = ( ) => (
@@ -177,23 +182,23 @@ describe('<LibraryAuthoringPage />', () => {
177
182
axiosMock . onGet ( getContentLibraryApiUrl ( libraryData . id ) ) . reply ( 200 , libraryData ) ;
178
183
179
184
const {
180
- getByRole, getByText, getAllByText , queryByText ,
185
+ getByRole, getByText, queryByText , findByText , findAllByText ,
181
186
} = render ( < RootWrapper /> ) ;
182
187
183
188
// Ensure the search endpoint is called:
184
189
// Call 1: To fetch searchable/filterable/sortable library data
185
190
// Call 2: To fetch the recently modified components only
186
191
await waitFor ( ( ) => { expect ( fetchMock ) . toHaveFetchedTimes ( 2 , searchEndpoint , 'post' ) ; } ) ;
187
192
188
- expect ( getByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
189
- expect ( getByText ( libraryData . title ) ) . toBeInTheDocument ( ) ;
193
+ expect ( await findByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
194
+ expect ( ( await findAllByText ( libraryData . title ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
190
195
191
196
expect ( queryByText ( 'You have not added any content to this library yet.' ) ) . not . toBeInTheDocument ( ) ;
192
197
193
198
expect ( getByText ( 'Recently Modified' ) ) . toBeInTheDocument ( ) ;
194
199
expect ( getByText ( 'Collections (0)' ) ) . toBeInTheDocument ( ) ;
195
200
expect ( getByText ( 'Components (6)' ) ) . toBeInTheDocument ( ) ;
196
- expect ( getAllByText ( 'Test HTML Block' ) [ 0 ] ) . toBeInTheDocument ( ) ;
201
+ expect ( ( await findAllByText ( 'Test HTML Block' ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
197
202
198
203
// Navigate to the components tab
199
204
fireEvent . click ( getByRole ( 'tab' , { name : 'Components' } ) ) ;
@@ -222,10 +227,10 @@ describe('<LibraryAuthoringPage />', () => {
222
227
axiosMock . onGet ( getContentLibraryApiUrl ( libraryData . id ) ) . reply ( 200 , libraryData ) ;
223
228
fetchMock . post ( searchEndpoint , returnEmptyResult , { overwriteRoutes : true } ) ;
224
229
225
- const { findByText, getByText } = render ( < RootWrapper /> ) ;
230
+ const { findByText, getByText, findAllByText } = render ( < RootWrapper /> ) ;
226
231
227
232
expect ( await findByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
228
- expect ( await findByText ( libraryData . title ) ) . toBeInTheDocument ( ) ;
233
+ expect ( ( await findAllByText ( libraryData . title ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
229
234
230
235
// Ensure the search endpoint is called:
231
236
// Call 1: To fetch searchable/filterable/sortable library data
@@ -282,10 +287,15 @@ describe('<LibraryAuthoringPage />', () => {
282
287
axiosMock . onGet ( getContentLibraryApiUrl ( libraryData . id ) ) . reply ( 200 , libraryData ) ;
283
288
fetchMock . post ( searchEndpoint , returnEmptyResult , { overwriteRoutes : true } ) ;
284
289
285
- const { findByText, getByRole, getByText } = render ( < RootWrapper /> ) ;
290
+ const {
291
+ findByText,
292
+ getByRole,
293
+ getByText,
294
+ findAllByText,
295
+ } = render ( < RootWrapper /> ) ;
286
296
287
297
expect ( await findByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
288
- expect ( await findByText ( libraryData . title ) ) . toBeInTheDocument ( ) ;
298
+ expect ( ( await findAllByText ( libraryData . title ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
289
299
290
300
// Ensure the search endpoint is called:
291
301
// Call 1: To fetch searchable/filterable/sortable library data
@@ -329,12 +339,54 @@ describe('<LibraryAuthoringPage />', () => {
329
339
expect ( screen . queryByText ( / a d d c o n t e n t / i) ) . not . toBeInTheDocument ( ) ;
330
340
} ) ;
331
341
342
+ it ( 'should open Library Info by default' , async ( ) => {
343
+ mockUseParams . mockReturnValue ( { libraryId : libraryData . id } ) ;
344
+ axiosMock . onGet ( getContentLibraryApiUrl ( libraryData . id ) ) . reply ( 200 , libraryData ) ;
345
+
346
+ render ( < RootWrapper /> ) ;
347
+
348
+ expect ( await screen . findByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
349
+ expect ( ( await screen . findAllByText ( libraryData . title ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
350
+ expect ( ( await screen . findAllByText ( libraryData . title ) ) [ 1 ] ) . toBeInTheDocument ( ) ;
351
+
352
+ expect ( screen . getByText ( 'Draft' ) ) . toBeInTheDocument ( ) ;
353
+ expect ( screen . getByText ( '(Never Published)' ) ) . toBeInTheDocument ( ) ;
354
+ expect ( screen . getByText ( 'July 22, 2024' ) ) . toBeInTheDocument ( ) ;
355
+ expect ( screen . getByText ( 'staff' ) ) . toBeInTheDocument ( ) ;
356
+ expect ( screen . getByText ( libraryData . org ) ) . toBeInTheDocument ( ) ;
357
+ expect ( screen . getByText ( 'July 20, 2024' ) ) . toBeInTheDocument ( ) ;
358
+ expect ( screen . getByText ( 'June 26, 2024' ) ) . toBeInTheDocument ( ) ;
359
+ } ) ;
360
+
361
+ it ( 'should close and open Library Info' , async ( ) => {
362
+ mockUseParams . mockReturnValue ( { libraryId : libraryData . id } ) ;
363
+ axiosMock . onGet ( getContentLibraryApiUrl ( libraryData . id ) ) . reply ( 200 , libraryData ) ;
364
+
365
+ render ( < RootWrapper /> ) ;
366
+
367
+ expect ( await screen . findByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
368
+ expect ( ( await screen . findAllByText ( libraryData . title ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
369
+ expect ( ( await screen . findAllByText ( libraryData . title ) ) [ 1 ] ) . toBeInTheDocument ( ) ;
370
+
371
+ const closeButton = screen . getByRole ( 'button' , { name : / c l o s e / i } ) ;
372
+ fireEvent . click ( closeButton ) ;
373
+
374
+ expect ( screen . queryByText ( 'Draft' ) ) . not . toBeInTheDocument ( ) ;
375
+ expect ( screen . queryByText ( '(Never Published)' ) ) . not . toBeInTheDocument ( ) ;
376
+
377
+ const libraryInfoButton = screen . getByRole ( 'button' , { name : / l i b r a r y i n f o / i } ) ;
378
+ fireEvent . click ( libraryInfoButton ) ;
379
+
380
+ expect ( screen . getByText ( 'Draft' ) ) . toBeInTheDocument ( ) ;
381
+ expect ( screen . getByText ( '(Never Published)' ) ) . toBeInTheDocument ( ) ;
382
+ } ) ;
383
+
332
384
it ( 'show the "View All" button when viewing library with many components' , async ( ) => {
333
385
mockUseParams . mockReturnValue ( { libraryId : libraryData . id } ) ;
334
386
axiosMock . onGet ( getContentLibraryApiUrl ( libraryData . id ) ) . reply ( 200 , libraryData ) ;
335
387
336
388
const {
337
- getByRole, getByText, queryByText, getAllByText,
389
+ getByRole, getByText, queryByText, getAllByText, findAllByText ,
338
390
} = render ( < RootWrapper /> ) ;
339
391
340
392
// Ensure the search endpoint is called:
@@ -343,7 +395,7 @@ describe('<LibraryAuthoringPage />', () => {
343
395
await waitFor ( ( ) => { expect ( fetchMock ) . toHaveFetchedTimes ( 2 , searchEndpoint , 'post' ) ; } ) ;
344
396
345
397
expect ( getByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
346
- expect ( getByText ( libraryData . title ) ) . toBeInTheDocument ( ) ;
398
+ expect ( ( await findAllByText ( libraryData . title ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
347
399
348
400
await waitFor ( ( ) => { expect ( getByText ( 'Recently Modified' ) ) . toBeInTheDocument ( ) ; } ) ;
349
401
expect ( getByText ( 'Collections (0)' ) ) . toBeInTheDocument ( ) ;
@@ -376,7 +428,7 @@ describe('<LibraryAuthoringPage />', () => {
376
428
fetchMock . post ( searchEndpoint , returnLowNumberResults , { overwriteRoutes : true } ) ;
377
429
378
430
const {
379
- getByText, queryByText, getAllByText,
431
+ getByText, queryByText, getAllByText, findAllByText ,
380
432
} = render ( < RootWrapper /> ) ;
381
433
382
434
// Ensure the search endpoint is called:
@@ -385,7 +437,7 @@ describe('<LibraryAuthoringPage />', () => {
385
437
await waitFor ( ( ) => { expect ( fetchMock ) . toHaveFetchedTimes ( 2 , searchEndpoint , 'post' ) ; } ) ;
386
438
387
439
expect ( getByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
388
- expect ( getByText ( libraryData . title ) ) . toBeInTheDocument ( ) ;
440
+ expect ( ( await findAllByText ( libraryData . title ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
389
441
390
442
await waitFor ( ( ) => { expect ( getByText ( 'Recently Modified' ) ) . toBeInTheDocument ( ) ; } ) ;
391
443
expect ( getByText ( 'Collections (0)' ) ) . toBeInTheDocument ( ) ;
0 commit comments