1
1
import { FileWithPath } from './file' ;
2
2
import { fromEvent } from './file-selector' ;
3
3
4
-
5
4
it ( 'returns a Promise' , async ( ) => {
6
5
const evt = new Event ( 'test' ) ;
7
6
expect ( fromEvent ( evt ) ) . toBeInstanceOf ( Promise ) ;
@@ -34,7 +33,7 @@ it('should return the evt {target} {files} if the passed event is an input evt',
34
33
expect ( file . type ) . toBe ( mockFile . type ) ;
35
34
expect ( file . size ) . toBe ( mockFile . size ) ;
36
35
expect ( file . lastModified ) . toBe ( mockFile . lastModified ) ;
37
- expect ( file . path ) . toBe ( name ) ;
36
+ expect ( file . path ) . toBe ( `./ ${ name } ` ) ;
38
37
} ) ;
39
38
40
39
it ( '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 ()
59
58
expect ( file . type ) . toBe ( mockFile . type ) ;
60
59
expect ( file . size ) . toBe ( mockFile . size ) ;
61
60
expect ( file . lastModified ) . toBe ( mockFile . lastModified ) ;
62
- expect ( file . path ) . toBe ( name ) ;
61
+ expect ( file . path ) . toBe ( `./ ${ name } ` ) ;
63
62
} ) ;
64
63
65
64
it ( '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
85
84
expect ( file . type ) . toBe ( mockFile . type ) ;
86
85
expect ( file . size ) . toBe ( mockFile . size ) ;
87
86
expect ( file . lastModified ) . toBe ( mockFile . lastModified ) ;
88
- expect ( file . path ) . toBe ( name ) ;
87
+ expect ( file . path ) . toBe ( `./ ${ name } ` ) ;
89
88
} ) ;
90
89
91
90
it ( '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
106
105
expect ( file . type ) . toBe ( mockFile . type ) ;
107
106
expect ( file . size ) . toBe ( mockFile . size ) ;
108
107
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 ) ;
110
134
} ) ;
111
135
112
136
it ( 'skips DataTransfer {items} that are of kind "string"' , async ( ) => {
@@ -127,7 +151,7 @@ it('skips DataTransfer {items} that are of kind "string"', async () => {
127
151
expect ( file . type ) . toBe ( mockFile . type ) ;
128
152
expect ( file . size ) . toBe ( mockFile . size ) ;
129
153
expect ( file . lastModified ) . toBe ( mockFile . lastModified ) ;
130
- expect ( file . path ) . toBe ( name ) ;
154
+ expect ( file . path ) . toBe ( `./ ${ name } ` ) ;
131
155
} ) ;
132
156
133
157
it ( '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 () => {
277
301
expect ( file . type ) . toBe ( f . type ) ;
278
302
expect ( file . size ) . toBe ( f . size ) ;
279
303
expect ( file . lastModified ) . toBe ( f . lastModified ) ;
280
- expect ( file . path ) . toBe ( name ) ;
304
+ expect ( file . path ) . toBe ( `./ ${ name } ` ) ;
281
305
} ) ;
282
306
283
307
function dragEvtFromItems ( items : DataTransferItem | DataTransferItem [ ] , type : string = 'drop' ) : DragEvent {
@@ -477,6 +501,7 @@ interface DirEntry extends Entry {
477
501
interface Entry {
478
502
isDirectory : boolean ;
479
503
isFile : boolean ;
504
+ fullPath ?: string ;
480
505
}
481
506
482
507
interface DirReader {
0 commit comments