@@ -64,6 +64,7 @@ const mockFileStats: FileStats = {
6464 type : BrowserViewType . file
6565} ;
6666const mockFileName = 'file.txt' ;
67+ const mockReload = jest . fn ( ) ;
6768
6869describe ( 'StorageFilePage' , ( ) => {
6970 let oldShowDownloadButton : boolean ;
@@ -80,7 +81,9 @@ describe('StorageFilePage', () => {
8081 } ) ;
8182
8283 it ( 'should render file metadata and content' , ( ) => {
83- render ( < StorageFilePage fileName = { mockFileName } fileStats = { mockFileStats } /> ) ;
84+ render (
85+ < StorageFilePage fileName = { mockFileName } fileStats = { mockFileStats } onReload = { mockReload } />
86+ ) ;
8487
8588 expect ( screen . getByText ( 'Size' ) ) . toBeInTheDocument ( ) ;
8689 expect ( screen . getByText ( '120.56 KB' ) ) . toBeInTheDocument ( ) ;
@@ -100,7 +103,9 @@ describe('StorageFilePage', () => {
100103
101104 // TODO: fix this test when mocking of useLoadData onSuccess callback is mproperly mocked
102105 it . skip ( 'should show edit button and hides save/cancel buttons initially' , ( ) => {
103- render ( < StorageFilePage fileName = { mockFileName } fileStats = { mockFileStats } /> ) ;
106+ render (
107+ < StorageFilePage fileName = { mockFileName } fileStats = { mockFileStats } onReload = { mockReload } />
108+ ) ;
104109
105110 expect ( screen . getByRole ( 'button' , { name : 'Edit' } ) ) . toBeVisible ( ) ;
106111 expect ( screen . queryByRole ( 'button' , { name : 'Save' } ) ) . toBeNull ( ) ;
@@ -113,14 +118,18 @@ describe('StorageFilePage', () => {
113118 contents : 'Initial file content' ,
114119 compression : 'zip'
115120 } ) ) ;
116- render ( < StorageFilePage fileName = { mockFileName } fileStats = { mockFileStats } /> ) ;
121+ render (
122+ < StorageFilePage fileName = { mockFileName } fileStats = { mockFileStats } onReload = { mockReload } />
123+ ) ;
117124
118125 expect ( screen . queryByRole ( 'button' , { name : 'Edit' } ) ) . toBeNull ( ) ;
119126 } ) ;
120127
121128 it ( 'should show save and cancel buttons when editing' , async ( ) => {
122129 const user = userEvent . setup ( ) ;
123- render ( < StorageFilePage fileName = { mockFileName } fileStats = { mockFileStats } /> ) ;
130+ render (
131+ < StorageFilePage fileName = { mockFileName } fileStats = { mockFileStats } onReload = { mockReload } />
132+ ) ;
124133
125134 expect ( screen . getByRole ( 'button' , { name : 'Edit' } ) ) . toBeVisible ( ) ;
126135 expect ( screen . queryByRole ( 'button' , { name : 'Save' } ) ) . toBeNull ( ) ;
@@ -138,7 +147,9 @@ describe('StorageFilePage', () => {
138147
139148 it ( 'should update textarea value and calls handleSave' , async ( ) => {
140149 const user = userEvent . setup ( ) ;
141- render ( < StorageFilePage fileName = { mockFileName } fileStats = { mockFileStats } /> ) ;
150+ render (
151+ < StorageFilePage fileName = { mockFileName } fileStats = { mockFileStats } onReload = { mockReload } />
152+ ) ;
142153
143154 await user . click ( screen . getByRole ( 'button' , { name : 'Edit' } ) ) ;
144155
@@ -160,7 +171,9 @@ describe('StorageFilePage', () => {
160171
161172 it ( 'should cancel editing and reverts textarea value' , async ( ) => {
162173 const user = userEvent . setup ( ) ;
163- render ( < StorageFilePage fileName = { mockFileName } fileStats = { mockFileStats } /> ) ;
174+ render (
175+ < StorageFilePage fileName = { mockFileName } fileStats = { mockFileStats } onReload = { mockReload } />
176+ ) ;
164177
165178 await user . click ( screen . getByRole ( 'button' , { name : 'Edit' } ) ) ;
166179
@@ -180,7 +193,9 @@ describe('StorageFilePage', () => {
180193
181194 it ( 'should download a file when download button is clicked' , async ( ) => {
182195 const user = userEvent . setup ( ) ;
183- render ( < StorageFilePage fileName = { mockFileName } fileStats = { mockFileStats } /> ) ;
196+ render (
197+ < StorageFilePage fileName = { mockFileName } fileStats = { mockFileStats } onReload = { mockReload } />
198+ ) ;
184199
185200 await user . click ( screen . getByRole ( 'button' , { name : 'Download' } ) ) ;
186201
@@ -194,7 +209,9 @@ describe('StorageFilePage', () => {
194209
195210 it ( 'should download a file when download button is clicked' , async ( ) => {
196211 const user = userEvent . setup ( ) ;
197- render ( < StorageFilePage fileName = { mockFileName } fileStats = { mockFileStats } /> ) ;
212+ render (
213+ < StorageFilePage fileName = { mockFileName } fileStats = { mockFileStats } onReload = { mockReload } />
214+ ) ;
198215
199216 await user . click ( screen . getByRole ( 'button' , { name : 'Download' } ) ) ;
200217
@@ -209,15 +226,19 @@ describe('StorageFilePage', () => {
209226 it ( 'should not render the download button when show_download_button is false' , ( ) => {
210227 ( window as hueWindow ) . SHOW_DOWNLOAD_BUTTON = false ;
211228
212- render ( < StorageFilePage fileName = { mockFileName } fileStats = { mockFileStats } /> ) ;
229+ render (
230+ < StorageFilePage fileName = { mockFileName } fileStats = { mockFileStats } onReload = { mockReload } />
231+ ) ;
213232
214233 expect ( screen . queryByRole ( 'button' , { name : 'Download' } ) ) . toBeNull ( ) ;
215234 expect ( screen . queryByRole ( 'link' , { name : 'Download' } ) ) . toBeNull ( ) ;
216235 } ) ;
217236
218237 // TODO: fix this test when mocking of useLoadData onSuccess callback is mproperly mocked
219238 it . skip ( 'should render a textarea for text files' , ( ) => {
220- render ( < StorageFilePage fileName = { mockFileName } fileStats = { mockFileStats } /> ) ;
239+ render (
240+ < StorageFilePage fileName = { mockFileName } fileStats = { mockFileStats } onReload = { mockReload } />
241+ ) ;
221242
222243 const textarea = screen . getByRole ( 'textbox' ) ;
223244 expect ( textarea ) . toBeInTheDocument ( ) ;
@@ -229,6 +250,7 @@ describe('StorageFilePage', () => {
229250 < StorageFilePage
230251 fileName = "imagefile.png"
231252 fileStats = { { ...mockFileStats , path : '/path/to/imagefile.png' } }
253+ onReload = { mockReload }
232254 />
233255 ) ;
234256
@@ -242,6 +264,7 @@ describe('StorageFilePage', () => {
242264 < StorageFilePage
243265 fileName = "documentfile.pdf"
244266 fileStats = { { ...mockFileStats , path : '/path/to/documentfile.pdf' } }
267+ onReload = { mockReload }
245268 />
246269 ) ;
247270
@@ -253,6 +276,7 @@ describe('StorageFilePage', () => {
253276 < StorageFilePage
254277 fileName = "audiofile.mp3"
255278 fileStats = { { ...mockFileStats , path : '/path/to/audiofile.mp3' } }
279+ onReload = { mockReload }
256280 />
257281 ) ;
258282
@@ -266,6 +290,7 @@ describe('StorageFilePage', () => {
266290 < StorageFilePage
267291 fileName = "videofile.mp4"
268292 fileStats = { { ...mockFileStats , path : '/path/to/videofile.mp4' } }
293+ onReload = { mockReload }
269294 />
270295 ) ;
271296
@@ -282,6 +307,7 @@ describe('StorageFilePage', () => {
282307 path : '/path/to/unsupportedfile.xyz'
283308 } }
284309 fileName = "unsupportedfile.xyz"
310+ onReload = { mockReload }
285311 />
286312 ) ;
287313
0 commit comments