@@ -13,6 +13,7 @@ import { mockContentLibrary, mockLibraryBlockTypes, mockXBlockFields } from './d
13
13
import { mockContentSearchConfig } from '../search-manager/data/api.mock' ;
14
14
import { mockBroadcastChannel } from '../generic/data/api.mock' ;
15
15
import { LibraryLayout } from '.' ;
16
+ import { getLibraryCollectionsApiUrl } from './data/api' ;
16
17
17
18
mockContentSearchConfig . applyMock ( ) ;
18
19
mockContentLibrary . applyMock ( ) ;
@@ -164,8 +165,23 @@ describe('<LibraryAuthoringPage />', () => {
164
165
fireEvent . click ( screen . getByRole ( 'tab' , { name : 'Collections' } ) ) ;
165
166
expect ( screen . getByText ( 'You have not added any collection to this library yet.' ) ) . toBeInTheDocument ( ) ;
166
167
168
+ // Open Create collection modal
169
+ const addCollectionButton = screen . getByRole ( 'button' , { name : / a d d c o l l e c t i o n / i } ) ;
170
+ fireEvent . click ( addCollectionButton ) ;
171
+ const collectionModalHeading = await screen . findByRole ( 'heading' , { name : / n e w c o l l e c t i o n / i } ) ;
172
+ expect ( collectionModalHeading ) . toBeInTheDocument ( ) ;
173
+
174
+ // Click on Cancel button
175
+ const cancelButton = screen . getByRole ( 'button' , { name : / c a n c e l / i } ) ;
176
+ fireEvent . click ( cancelButton ) ;
177
+ expect ( collectionModalHeading ) . not . toBeInTheDocument ( ) ;
178
+
167
179
fireEvent . click ( screen . getByRole ( 'tab' , { name : 'Home' } ) ) ;
168
180
expect ( screen . getByText ( 'You have not added any content to this library yet.' ) ) . toBeInTheDocument ( ) ;
181
+
182
+ const addComponentButton = screen . getByRole ( 'button' , { name : / a d d c o m p o n e n t / i } ) ;
183
+ fireEvent . click ( addComponentButton ) ;
184
+ expect ( screen . getByText ( / a d d c o n t e n t / i) ) . toBeInTheDocument ( ) ;
169
185
} ) ;
170
186
171
187
it ( 'shows the new content button' , async ( ) => {
@@ -535,6 +551,120 @@ describe('<LibraryAuthoringPage />', () => {
535
551
expect ( screen . getByText ( / n o m a t c h i n g c o m p o n e n t s / i) ) . toBeInTheDocument ( ) ;
536
552
} ) ;
537
553
554
+ it ( 'should create a collection' , async ( ) => {
555
+ await renderLibraryPage ( ) ;
556
+ const title = 'This is a Test' ;
557
+ const description = 'This is the description of the Test' ;
558
+ const url = getLibraryCollectionsApiUrl ( mockContentLibrary . libraryId ) ;
559
+ const { axiosMock } = initializeMocks ( ) ;
560
+ axiosMock . onPost ( url ) . reply ( 200 , {
561
+ id : '1' ,
562
+ slug : 'this-is-a-test' ,
563
+ title,
564
+ description,
565
+ } ) ;
566
+
567
+ expect ( await screen . findByRole ( 'heading' ) ) . toBeInTheDocument ( ) ;
568
+ expect ( screen . queryByText ( / a d d c o n t e n t / i) ) . not . toBeInTheDocument ( ) ;
569
+
570
+ // Open Add content sidebar
571
+ const newButton = screen . getByRole ( 'button' , { name : / n e w / i } ) ;
572
+ fireEvent . click ( newButton ) ;
573
+ expect ( screen . getByText ( / a d d c o n t e n t / i) ) . toBeInTheDocument ( ) ;
574
+
575
+ // Open New collection Modal
576
+ const newCollectionButton = screen . getAllByRole ( 'button' , { name : / c o l l e c t i o n / i } ) [ 4 ] ;
577
+ fireEvent . click ( newCollectionButton ) ;
578
+ const collectionModalHeading = await screen . findByRole ( 'heading' , { name : / n e w c o l l e c t i o n / i } ) ;
579
+ expect ( collectionModalHeading ) . toBeInTheDocument ( ) ;
580
+
581
+ // Click on Cancel button
582
+ const cancelButton = screen . getByRole ( 'button' , { name : / c a n c e l / i } ) ;
583
+ fireEvent . click ( cancelButton ) ;
584
+ expect ( collectionModalHeading ) . not . toBeInTheDocument ( ) ;
585
+
586
+ // Open new collection modal again and create a collection
587
+ fireEvent . click ( newCollectionButton ) ;
588
+ const createButton = screen . getByRole ( 'button' , { name : / c r e a t e / i } ) ;
589
+ const nameField = screen . getByRole ( 'textbox' , { name : / n a m e y o u r c o l l e c t i o n / i } ) ;
590
+ const descriptionField = screen . getByRole ( 'textbox' , { name : / a d d a d e s c r i p t i o n \( o p t i o n a l \) / i } ) ;
591
+
592
+ fireEvent . change ( nameField , { target : { value : title } } ) ;
593
+ fireEvent . change ( descriptionField , { target : { value : description } } ) ;
594
+ fireEvent . click ( createButton ) ;
595
+ } ) ;
596
+
597
+ it ( 'should show validations in create collection' , async ( ) => {
598
+ await renderLibraryPage ( ) ;
599
+
600
+ const title = 'This is a Test' ;
601
+ const description = 'This is the description of the Test' ;
602
+ const url = getLibraryCollectionsApiUrl ( mockContentLibrary . libraryId ) ;
603
+ const { axiosMock } = initializeMocks ( ) ;
604
+ axiosMock . onPost ( url ) . reply ( 200 , {
605
+ id : '1' ,
606
+ slug : 'this-is-a-test' ,
607
+ title,
608
+ description,
609
+ } ) ;
610
+
611
+ expect ( await screen . findByRole ( 'heading' ) ) . toBeInTheDocument ( ) ;
612
+ expect ( screen . queryByText ( / a d d c o n t e n t / i) ) . not . toBeInTheDocument ( ) ;
613
+
614
+ // Open Add content sidebar
615
+ const newButton = screen . getByRole ( 'button' , { name : / n e w / i } ) ;
616
+ fireEvent . click ( newButton ) ;
617
+ expect ( screen . getByText ( / a d d c o n t e n t / i) ) . toBeInTheDocument ( ) ;
618
+
619
+ // Open New collection Modal
620
+ const newCollectionButton = screen . getAllByRole ( 'button' , { name : / c o l l e c t i o n / i } ) [ 4 ] ;
621
+ fireEvent . click ( newCollectionButton ) ;
622
+ const collectionModalHeading = await screen . findByRole ( 'heading' , { name : / n e w c o l l e c t i o n / i } ) ;
623
+ expect ( collectionModalHeading ) . toBeInTheDocument ( ) ;
624
+
625
+ const nameField = screen . getByRole ( 'textbox' , { name : / n a m e y o u r c o l l e c t i o n / i } ) ;
626
+ fireEvent . focus ( nameField ) ;
627
+ fireEvent . blur ( nameField ) ;
628
+
629
+ // Click on create with an empty name
630
+ const createButton = screen . getByRole ( 'button' , { name : / c r e a t e / i } ) ;
631
+ fireEvent . click ( createButton ) ;
632
+
633
+ expect ( await screen . findByText ( / c o l l e c t i o n n a m e i s r e q u i r e d / i) ) . toBeInTheDocument ( ) ;
634
+ } ) ;
635
+
636
+ it ( 'should show error on create collection' , async ( ) => {
637
+ await renderLibraryPage ( ) ;
638
+ const title = 'This is a Test' ;
639
+ const description = 'This is the description of the Test' ;
640
+ const url = getLibraryCollectionsApiUrl ( mockContentLibrary . libraryId ) ;
641
+ const { axiosMock } = initializeMocks ( ) ;
642
+ axiosMock . onPost ( url ) . reply ( 500 ) ;
643
+
644
+ expect ( await screen . findByRole ( 'heading' ) ) . toBeInTheDocument ( ) ;
645
+ expect ( screen . queryByText ( / a d d c o n t e n t / i) ) . not . toBeInTheDocument ( ) ;
646
+
647
+ // Open Add content sidebar
648
+ const newButton = screen . getByRole ( 'button' , { name : / n e w / i } ) ;
649
+ fireEvent . click ( newButton ) ;
650
+ expect ( screen . getByText ( / a d d c o n t e n t / i) ) . toBeInTheDocument ( ) ;
651
+
652
+ // Open New collection Modal
653
+ const newCollectionButton = screen . getAllByRole ( 'button' , { name : / c o l l e c t i o n / i } ) [ 4 ] ;
654
+ fireEvent . click ( newCollectionButton ) ;
655
+ const collectionModalHeading = await screen . findByRole ( 'heading' , { name : / n e w c o l l e c t i o n / i } ) ;
656
+ expect ( collectionModalHeading ) . toBeInTheDocument ( ) ;
657
+
658
+ // Create a normal collection
659
+ const createButton = screen . getByRole ( 'button' , { name : / c r e a t e / i } ) ;
660
+ const nameField = screen . getByRole ( 'textbox' , { name : / n a m e y o u r c o l l e c t i o n / i } ) ;
661
+ const descriptionField = screen . getByRole ( 'textbox' , { name : / a d d a d e s c r i p t i o n \( o p t i o n a l \) / i } ) ;
662
+
663
+ fireEvent . change ( nameField , { target : { value : title } } ) ;
664
+ fireEvent . change ( descriptionField , { target : { value : description } } ) ;
665
+ fireEvent . click ( createButton ) ;
666
+ } ) ;
667
+
538
668
it ( 'shows both components and collections in recently modified section' , async ( ) => {
539
669
await renderLibraryPage ( ) ;
540
670
0 commit comments