@@ -256,15 +256,25 @@ describe('FileInput', function () {
256256 describe ( 'when a file is chosen' , function ( ) {
257257 beforeEach ( async function ( ) {
258258 render (
259- < FileInput
260- id = "file-input"
261- label = "Select something"
262- dataTestId = "test-file-input"
263- onChange = { spy }
264- error = { true }
265- errorMessage = { 'Error' }
266- mode = "open"
267- />
259+ < FileInputBackendProvider
260+ createFileInputBackend = { ( ) =>
261+ ( {
262+ getPathForFile ( ) {
263+ return 'a/b/c' ;
264+ } ,
265+ } as any )
266+ }
267+ >
268+ < FileInput
269+ id = "file-input"
270+ label = "Select something"
271+ dataTestId = "test-file-input"
272+ onChange = { spy }
273+ error = { true }
274+ errorMessage = { 'Error' }
275+ mode = "open"
276+ />
277+ </ FileInputBackendProvider >
268278 ) ;
269279
270280 const fileInput = screen . getByTestId ( 'test-file-input' ) ;
@@ -284,7 +294,7 @@ describe('FileInput', function () {
284294
285295 it ( 'calls onChange with the chosen file' , function ( ) {
286296 expect ( spy . callCount ) . to . equal ( 1 ) ;
287- expect ( spy . firstCall . args [ 0 ] ) . to . deep . equal ( [ undefined ] ) ; // cannot get the actual path without electron
297+ expect ( spy . firstCall . args [ 0 ] ) . to . deep . equal ( [ 'a/b/c' ] ) ;
288298 } ) ;
289299 } ) ;
290300
@@ -343,13 +353,19 @@ describe('FileInput', function () {
343353 showOpenDialog : sinon . stub ( ) ,
344354 } ,
345355 } ;
346- return { fakeElectron, fakeWindow } ;
356+ const fakeWebUtils = {
357+ getPathForFile : sinon . stub ( ) . returns ( 'a/b/c' ) ,
358+ } ;
359+ return { fakeElectron, fakeWindow, fakeWebUtils } ;
347360 }
348361
349362 it ( 'allows using electron-style APIs for file updates' , async function ( ) {
350- const { fakeElectron, fakeWindow } = createFakeElectron ( ) ;
363+ const { fakeElectron, fakeWindow, fakeWebUtils } = createFakeElectron ( ) ;
351364
352- const backend = createElectronFileInputBackend ( fakeElectron ) ( ) ;
365+ const backend = createElectronFileInputBackend (
366+ fakeElectron ,
367+ fakeWebUtils
368+ ) ( ) ;
353369 const listener = sinon . stub ( ) ;
354370 const unsubscribe = backend . onFilesChosen ( listener ) ;
355371
@@ -378,10 +394,24 @@ describe('FileInput', function () {
378394 expect ( fakeElectron . dialog . showSaveDialog ) . to . have . been . calledTwice ;
379395 } ) ;
380396
397+ it ( 'passes through getPathForFile calls' , function ( ) {
398+ const { fakeElectron, fakeWebUtils } = createFakeElectron ( ) ;
399+
400+ const backend = createElectronFileInputBackend (
401+ fakeElectron ,
402+ fakeWebUtils
403+ ) ( ) ;
404+
405+ expect ( backend . getPathForFile ( { } as any ) ) . to . equal ( 'a/b/c' ) ;
406+ } ) ;
407+
381408 it ( 'can partially handle browser-compatible accept values' , function ( ) {
382- const { fakeElectron, fakeWindow } = createFakeElectron ( ) ;
409+ const { fakeElectron, fakeWindow, fakeWebUtils } = createFakeElectron ( ) ;
383410
384- const backend = createElectronFileInputBackend ( fakeElectron ) ( ) ;
411+ const backend = createElectronFileInputBackend (
412+ fakeElectron ,
413+ fakeWebUtils
414+ ) ( ) ;
385415
386416 fakeElectron . dialog . showSaveDialog . resolves ( {
387417 canceled : true ,
@@ -404,9 +434,12 @@ describe('FileInput', function () {
404434 } ) ;
405435
406436 it ( 'does not override existing file filters' , function ( ) {
407- const { fakeElectron, fakeWindow } = createFakeElectron ( ) ;
437+ const { fakeElectron, fakeWindow, fakeWebUtils } = createFakeElectron ( ) ;
408438
409- const backend = createElectronFileInputBackend ( fakeElectron ) ( ) ;
439+ const backend = createElectronFileInputBackend (
440+ fakeElectron ,
441+ fakeWebUtils
442+ ) ( ) ;
410443
411444 fakeElectron . dialog . showSaveDialog . resolves ( {
412445 canceled : true ,
@@ -430,9 +463,12 @@ describe('FileInput', function () {
430463 } ) ;
431464
432465 it ( 'handles multi:false' , function ( ) {
433- const { fakeElectron, fakeWindow } = createFakeElectron ( ) ;
466+ const { fakeElectron, fakeWindow, fakeWebUtils } = createFakeElectron ( ) ;
434467
435- const backend = createElectronFileInputBackend ( fakeElectron ) ( ) ;
468+ const backend = createElectronFileInputBackend (
469+ fakeElectron ,
470+ fakeWebUtils
471+ ) ( ) ;
436472
437473 fakeElectron . dialog . showSaveDialog . resolves ( {
438474 canceled : true ,
@@ -452,9 +488,12 @@ describe('FileInput', function () {
452488 } ) ;
453489
454490 it ( 'handles multi:true' , function ( ) {
455- const { fakeElectron, fakeWindow } = createFakeElectron ( ) ;
491+ const { fakeElectron, fakeWindow, fakeWebUtils } = createFakeElectron ( ) ;
456492
457- const backend = createElectronFileInputBackend ( fakeElectron ) ( ) ;
493+ const backend = createElectronFileInputBackend (
494+ fakeElectron ,
495+ fakeWebUtils
496+ ) ( ) ;
458497
459498 fakeElectron . dialog . showSaveDialog . resolves ( {
460499 canceled : true ,
@@ -473,9 +512,12 @@ describe('FileInput', function () {
473512 } ) ;
474513
475514 it ( 'can call showOpenDialog if requested' , async function ( ) {
476- const { fakeElectron, fakeWindow } = createFakeElectron ( ) ;
515+ const { fakeElectron, fakeWindow, fakeWebUtils } = createFakeElectron ( ) ;
477516
478- const backend = createElectronFileInputBackend ( fakeElectron ) ( ) ;
517+ const backend = createElectronFileInputBackend (
518+ fakeElectron ,
519+ fakeWebUtils
520+ ) ( ) ;
479521 const listener = sinon . stub ( ) ;
480522 backend . onFilesChosen ( listener ) ;
481523
@@ -501,9 +543,12 @@ describe('FileInput', function () {
501543 } ) ;
502544
503545 it ( 'calls the listener with an empty array if the user canceled the request' , async function ( ) {
504- const { fakeElectron } = createFakeElectron ( ) ;
546+ const { fakeElectron, fakeWebUtils } = createFakeElectron ( ) ;
505547
506- const backend = createElectronFileInputBackend ( fakeElectron ) ( ) ;
548+ const backend = createElectronFileInputBackend (
549+ fakeElectron ,
550+ fakeWebUtils
551+ ) ( ) ;
507552 const listener = sinon . stub ( ) ;
508553 backend . onFilesChosen ( listener ) ;
509554
@@ -521,8 +566,11 @@ describe('FileInput', function () {
521566 } ) ;
522567
523568 it ( 'handles autoOpen:true' , async function ( ) {
524- const { fakeElectron } = createFakeElectron ( ) ;
525- const backend = createElectronFileInputBackend ( fakeElectron ) ( ) ;
569+ const { fakeElectron, fakeWebUtils } = createFakeElectron ( ) ;
570+ const backend = createElectronFileInputBackend (
571+ fakeElectron ,
572+ fakeWebUtils
573+ ) ( ) ;
526574
527575 const listener = sinon . stub ( ) ;
528576 backend . onFilesChosen ( listener ) ;
@@ -577,8 +625,11 @@ describe('FileInput', function () {
577625 let openFileChooserSpy : sinon . SinonSpy ;
578626
579627 beforeEach ( async function ( ) {
580- const { fakeElectron } = createFakeElectron ( ) ;
581- const backend = createElectronFileInputBackend ( fakeElectron ) ( ) ;
628+ const { fakeElectron, fakeWebUtils } = createFakeElectron ( ) ;
629+ const backend = createElectronFileInputBackend (
630+ fakeElectron ,
631+ fakeWebUtils
632+ ) ( ) ;
582633
583634 listener = sinon . stub ( ) ;
584635 backend . onFilesChosen ( listener ) ;
0 commit comments