11import { FileWithPath } from './file' ;
22import { fromEvent } from './file-selector' ;
33
4-
54it ( 'returns a Promise' , async ( ) => {
65 const evt = new Event ( 'test' ) ;
76 expect ( fromEvent ( evt ) ) . toBeInstanceOf ( Promise ) ;
@@ -34,7 +33,7 @@ it('should return the evt {target} {files} if the passed event is an input evt',
3433 expect ( file . type ) . toBe ( mockFile . type ) ;
3534 expect ( file . size ) . toBe ( mockFile . size ) ;
3635 expect ( file . lastModified ) . toBe ( mockFile . lastModified ) ;
37- expect ( file . path ) . toBe ( name ) ;
36+ expect ( file . path ) . toBe ( `./ ${ name } ` ) ;
3837} ) ;
3938
4039it ( 'should return an empty array if the evt {target} has no {files} prop' , async ( ) => {
@@ -59,7 +58,7 @@ it('should return files if the arg is a list of FileSystemFileHandle', async ()
5958 expect ( file . type ) . toBe ( mockFile . type ) ;
6059 expect ( file . size ) . toBe ( mockFile . size ) ;
6160 expect ( file . lastModified ) . toBe ( mockFile . lastModified ) ;
62- expect ( file . path ) . toBe ( name ) ;
61+ expect ( file . path ) . toBe ( `./ ${ name } ` ) ;
6362} ) ;
6463
6564it ( 'should return an empty array if the passed event is not a DragEvent' , async ( ) => {
@@ -85,7 +84,7 @@ it('should return {files} from DataTransfer if {items} is not defined (e.g. IE11
8584 expect ( file . type ) . toBe ( mockFile . type ) ;
8685 expect ( file . size ) . toBe ( mockFile . size ) ;
8786 expect ( file . lastModified ) . toBe ( mockFile . lastModified ) ;
88- expect ( file . path ) . toBe ( name ) ;
87+ expect ( file . path ) . toBe ( `./ ${ name } ` ) ;
8988} ) ;
9089
9190it ( 'should return files from DataTransfer {items} if the passed event is a DragEvent' , async ( ) => {
@@ -106,7 +105,32 @@ it('should return files from DataTransfer {items} if the passed event is a DragE
106105 expect ( file . type ) . toBe ( mockFile . type ) ;
107106 expect ( file . size ) . toBe ( mockFile . size ) ;
108107 expect ( file . lastModified ) . toBe ( mockFile . lastModified ) ;
109- expect ( file . path ) . toBe ( name ) ;
108+ expect ( file . path ) . toBe ( `./${ name } ` ) ;
109+ } ) ;
110+
111+ it ( 'should use the {fullPath} for {path} if {webkitGetAsEntry} is supported and the items are FileSystemFileEntry' , async ( ) => {
112+ const name = 'test.json' ;
113+ const fullPath = '/testfolder/test.json'
114+ const mockFile = createFile ( name , { ping : true } , {
115+ type : 'application/json'
116+ } ) ;
117+
118+ const file = fileSystemFileEntryFromFile ( mockFile ) ;
119+ file . fullPath = fullPath
120+ const item = dataTransferItemFromEntry ( file , mockFile ) ;
121+ const evt = dragEvtFromFilesAndItems ( [ ] , [ item ] ) ;
122+
123+ const files = await fromEvent ( evt ) ;
124+ expect ( files ) . toHaveLength ( 1 ) ;
125+ expect ( files . every ( file => file instanceof File ) ) . toBe ( true ) ;
126+
127+ const [ f ] = files as FileWithPath [ ] ;
128+
129+ expect ( f . name ) . toBe ( mockFile . name ) ;
130+ expect ( f . type ) . toBe ( mockFile . type ) ;
131+ expect ( f . size ) . toBe ( mockFile . size ) ;
132+ expect ( f . lastModified ) . toBe ( mockFile . lastModified ) ;
133+ expect ( f . path ) . toBe ( fullPath ) ;
110134} ) ;
111135
112136it ( 'skips DataTransfer {items} that are of kind "string"' , async ( ) => {
@@ -127,7 +151,7 @@ it('skips DataTransfer {items} that are of kind "string"', async () => {
127151 expect ( file . type ) . toBe ( mockFile . type ) ;
128152 expect ( file . size ) . toBe ( mockFile . size ) ;
129153 expect ( file . lastModified ) . toBe ( mockFile . lastModified ) ;
130- expect ( file . path ) . toBe ( name ) ;
154+ expect ( file . path ) . toBe ( `./ ${ name } ` ) ;
131155} ) ;
132156
133157it ( 'can read a tree of directories recursively and return a flat list of FileWithPath objects' , async ( ) => {
@@ -277,7 +301,7 @@ it('should use getAsFileSystemHandle when available', async () => {
277301 expect ( file . type ) . toBe ( f . type ) ;
278302 expect ( file . size ) . toBe ( f . size ) ;
279303 expect ( file . lastModified ) . toBe ( f . lastModified ) ;
280- expect ( file . path ) . toBe ( name ) ;
304+ expect ( file . path ) . toBe ( `./ ${ name } ` ) ;
281305} ) ;
282306
283307function dragEvtFromItems ( items : DataTransferItem | DataTransferItem [ ] , type : string = 'drop' ) : DragEvent {
@@ -477,6 +501,7 @@ interface DirEntry extends Entry {
477501interface Entry {
478502 isDirectory : boolean ;
479503 isFile : boolean ;
504+ fullPath ?: string ;
480505}
481506
482507interface DirReader {
0 commit comments