@@ -48,4 +48,46 @@ describe('<CollectionInfoHeader />', () => {
48
48
expect ( textBox ) . not . toBeInTheDocument ( ) ;
49
49
expect ( mockShowToast ) . toHaveBeenCalledWith ( 'Collection updated successfully.' ) ;
50
50
} ) ;
51
+
52
+ it ( 'should close edit collection title on press Escape' , async ( ) => {
53
+ const { axiosMock, mockShowToast } = initializeMocks ( ) ;
54
+ const library = await mockContentLibrary ( mockContentLibrary . libraryId ) ;
55
+ render ( < CollectionInfoHeader library = { library } collection = { mockCollectionHit } /> ) ;
56
+ const url = api . getLibraryCollectionApiUrl ( library . id , mockCollectionHit . blockId ) ;
57
+ axiosMock . onPatch ( url ) . reply ( 200 ) ;
58
+
59
+ fireEvent . click ( screen . getByRole ( 'button' , { name : / e d i t c o l l e c t i o n t i t l e / i } ) ) ;
60
+
61
+ const textBox = screen . getByRole ( 'textbox' , { name : / t i t l e i n p u t / i } ) ;
62
+
63
+ fireEvent . change ( textBox , { target : { value : 'New Collection Title' } } ) ;
64
+ fireEvent . keyDown ( textBox , { key : 'Escape' , code : 'Escape' , charCode : 27 } ) ;
65
+
66
+ await waitFor ( ( ) => expect ( axiosMock . history . patch . length ) . toEqual ( 0 ) ) ;
67
+
68
+ expect ( textBox ) . not . toBeInTheDocument ( ) ;
69
+ } ) ;
70
+
71
+ it ( 'should show error on edit collection tittle' , async ( ) => {
72
+ const { axiosMock, mockShowToast } = initializeMocks ( ) ;
73
+ const library = await mockContentLibrary ( mockContentLibrary . libraryId ) ;
74
+ render ( < CollectionInfoHeader library = { library } collection = { mockCollectionHit } /> ) ;
75
+ const url = api . getLibraryCollectionApiUrl ( library . id , mockCollectionHit . blockId ) ;
76
+ axiosMock . onPatch ( url ) . reply ( 500 ) ;
77
+
78
+ fireEvent . click ( screen . getByRole ( 'button' , { name : / e d i t c o l l e c t i o n t i t l e / i } ) ) ;
79
+
80
+ const textBox = screen . getByRole ( 'textbox' , { name : / t i t l e i n p u t / i } ) ;
81
+
82
+ fireEvent . change ( textBox , { target : { value : 'New Collection Title' } } ) ;
83
+ fireEvent . keyDown ( textBox , { key : 'Enter' , code : 'Enter' , charCode : 13 } ) ;
84
+
85
+ await waitFor ( ( ) => {
86
+ expect ( axiosMock . history . patch [ 0 ] . url ) . toEqual ( url ) ;
87
+ expect ( axiosMock . history . patch [ 0 ] . data ) . toEqual ( JSON . stringify ( { title : 'New Collection Title' } ) ) ;
88
+ } ) ;
89
+
90
+ expect ( textBox ) . not . toBeInTheDocument ( ) ;
91
+ expect ( mockShowToast ) . toHaveBeenCalledWith ( 'Failed to update collection.' ) ;
92
+ } ) ;
51
93
} ) ;
0 commit comments