@@ -6,11 +6,12 @@ import {
66 screen ,
77 waitFor ,
88 initializeMocks ,
9- } from '../.. /testUtils' ;
9+ } from '@src /testUtils' ;
1010import { mockContentLibrary } from '../data/api.mocks' ;
1111import { getCommitLibraryChangesUrl } from '../data/api' ;
1212import { LibraryProvider } from '../common/context/LibraryContext' ;
1313import LibraryInfo from './LibraryInfo' ;
14+ import * as apiHooks from '../data/apiHooks' ;
1415
1516const {
1617 libraryId : mockLibraryId ,
@@ -105,7 +106,10 @@ describe('<LibraryInfo />', () => {
105106
106107 expect ( await screen . findByText ( libraryData . org ) ) . toBeInTheDocument ( ) ;
107108
108- expect ( screen . getByText ( 'Published' ) ) . toBeInTheDocument ( ) ;
109+ // First 'Published' from the state
110+ expect ( screen . getAllByText ( 'Published' ) [ 0 ] ) . toBeInTheDocument ( ) ;
111+ // Second 'Published' from the published button
112+ expect ( screen . getAllByText ( 'Published' ) [ 1 ] ) . toBeInTheDocument ( ) ;
109113 expect ( screen . getByText ( 'July 26, 2024' ) ) . toBeInTheDocument ( ) ;
110114 expect ( screen . getByText ( 'staff' ) ) . toBeInTheDocument ( ) ;
111115 } ) ;
@@ -115,7 +119,10 @@ describe('<LibraryInfo />', () => {
115119
116120 expect ( await screen . findByText ( libraryData . org ) ) . toBeInTheDocument ( ) ;
117121
118- expect ( screen . getByText ( 'Published' ) ) . toBeInTheDocument ( ) ;
122+ // First 'Published' from the state
123+ expect ( screen . getAllByText ( 'Published' ) [ 0 ] ) . toBeInTheDocument ( ) ;
124+ // Second 'Published' from the published button
125+ expect ( screen . getAllByText ( 'Published' ) [ 1 ] ) . toBeInTheDocument ( ) ;
119126 expect ( screen . getByText ( 'July 26, 2024' ) ) . toBeInTheDocument ( ) ;
120127 expect ( screen . queryByText ( 'staff' ) ) . not . toBeInTheDocument ( ) ;
121128 } ) ;
@@ -136,6 +143,31 @@ describe('<LibraryInfo />', () => {
136143 } ) ;
137144 } ) ;
138145
146+ it ( 'should publish library 2' , async ( ) => {
147+ const useCommitLibraryChangesSpy = jest
148+ . spyOn ( apiHooks , 'useCommitLibraryChanges' )
149+ . mockReturnValue (
150+ // @ts -ignore
151+ {
152+ mutate : jest . fn ( ) ,
153+ mutateAsync : jest . fn ( ) ,
154+ status : 'pending' ,
155+ } ,
156+ ) ;
157+
158+ render ( ) ;
159+
160+ expect ( await screen . findByText ( libraryData . org ) ) . toBeInTheDocument ( ) ;
161+
162+ const publishButton = screen . getByRole ( 'button' , { name : / p u b l i s h / i } ) ;
163+ fireEvent . click ( publishButton ) ;
164+
165+ await waitFor ( ( ) => {
166+ expect ( screen . getByText ( / p u b l i s h i n g / i) ) . toBeInTheDocument ( ) ;
167+ } ) ;
168+ useCommitLibraryChangesSpy . mockRestore ( ) ;
169+ } ) ;
170+
139171 it ( 'should show error on publish library' , async ( ) => {
140172 const url = getCommitLibraryChangesUrl ( libraryData . id ) ;
141173 axiosMock . onPost ( url ) . reply ( 500 ) ;
0 commit comments