@@ -2,7 +2,9 @@ import { fireEvent, render, waitFor } from "@testing-library/react";
22import userEvent from "@testing-library/user-event" ;
33import DxcFileInput from "./FileInput" ;
44
5- const file1 = new File ( [ "file1" ] , "file1.png" , { type : "image/png" } ) ;
5+ const file1 = new File ( [ new Uint8Array ( [ 137 , 80 , 78 , 71 ] ) ] , "file1.png" , {
6+ type : "image/png" ,
7+ } ) ;
68const file2 = new File ( [ "file2" ] , "file2.txt" , {
79 type : "text/plain" ,
810} ) ;
@@ -17,6 +19,9 @@ const allFiles = [
1719] ;
1820
1921describe ( "FileInput component tests" , ( ) => {
22+ beforeAll ( ( ) => {
23+ global . URL . createObjectURL = jest . fn ( ( ) => "blob:mock-url" ) ;
24+ } ) ;
2025 test ( "Renders with correct labels and helper text in file mode" , ( ) => {
2126 const callbackFile = jest . fn ( ) ;
2227 const { getByText } = render (
@@ -208,7 +213,7 @@ describe("FileInput component tests", () => {
208213 expect ( callbackFile ) . toHaveBeenCalledWith ( [
209214 {
210215 file : file1 ,
211- preview : "data:image/png;base64,ZmlsZTE= " ,
216+ preview : "blob:mock-url " ,
212217 } ,
213218 {
214219 error : "Error message" ,
@@ -307,7 +312,7 @@ describe("FileInput component tests", () => {
307312 expect ( callbackFile ) . toHaveBeenCalledWith ( [
308313 {
309314 file : file1 ,
310- preview : "data:image/png;base64,ZmlsZTE= " ,
315+ preview : "blob:mock-url " ,
311316 } ,
312317 {
313318 error : "Error message" ,
@@ -334,6 +339,7 @@ describe("FileInput component tests", () => {
334339 maxSize = { 20000 }
335340 value = { allFiles }
336341 callbackFile = { callbackFile }
342+ showPreview
337343 />
338344 ) ;
339345 await waitFor ( ( ) => {
@@ -343,7 +349,7 @@ describe("FileInput component tests", () => {
343349 const inputFile = getByLabelText ( "File input label" ) ;
344350 fireEvent . change ( inputFile , { target : { files : [ newFile ] } } ) ;
345351 expect ( callbackFile ) . toHaveBeenCalledWith ( [
346- { file : file1 , preview : "data:image/png;base64,ZmlsZTE= " } ,
352+ { file : file1 , preview : "blob:mock-url " } ,
347353 {
348354 error : "Error message" ,
349355 file : file2 ,
0 commit comments