forked from miguelpruivo/flutter_file_picker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_picker_utils_test.dart
157 lines (129 loc) · 4.78 KB
/
file_picker_utils_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
@TestOn('linux || mac-os')
import 'dart:io';
import 'package:file_picker/src/utils.dart';
import 'package:flutter_test/flutter_test.dart';
import 'common.dart';
void main() {
final appTestFilePath = '/tmp/test_utils.app';
final imageTestFile = '/tmp/test_utils.jpg';
final pdfTestFile = '/tmp/test_utils.pdf';
final yamlTestFile = '/tmp/test_utils.yml';
setUpAll(
() => setUpTestFiles(
appTestFilePath, imageTestFile, pdfTestFile, yamlTestFile),
);
tearDownAll(
() => tearDownTestFiles(
appTestFilePath, imageTestFile, pdfTestFile, yamlTestFile),
);
group('createPlatformFile()', () {
test('should return an instance of PlatformFile', () async {
final imageFile = File(imageTestFile);
final bytes = imageFile.readAsBytesSync();
final readStream = imageFile.openRead();
final platformFile =
await createPlatformFile(imageFile, bytes, readStream);
expect(platformFile.bytes, equals(bytes));
expect(platformFile.name, equals('test_utils.jpg'));
expect(platformFile.readStream, equals(readStream));
expect(platformFile.size, equals(bytes.length));
});
test(
'should not throw an exception when picking .app files on macOS (.app files on macOS are actually directories but they are treated as files, similar to .exe files on Windows)',
() async {
final appFile = File(appTestFilePath);
final platformFile = await createPlatformFile(appFile, null, null);
expect(platformFile.bytes, equals(null));
expect(platformFile.name, equals('test_utils.app'));
expect(platformFile.readStream, equals(null));
expect(
platformFile.size,
equals(0),
reason: 'Expect size to be 0 because .app files are directories.',
);
});
});
group('filePathsToPlatformFiles()', () {
test('should transform a list of file paths into a list of PlatformFiles',
() async {
final filePaths = [imageTestFile, pdfTestFile, yamlTestFile];
final platformFiles =
await filePathsToPlatformFiles(filePaths, false, false);
expect(platformFiles.length, equals(filePaths.length));
final imageFile = platformFiles.firstWhere(
(element) => element.name == 'test_utils.jpg',
);
expect(imageFile.extension, equals('jpg'));
expect(imageFile.name, equals('test_utils.jpg'));
expect(imageFile.path, equals(imageTestFile));
expect(imageFile.size, equals(4073378));
final pdfFile = platformFiles.firstWhere(
(element) => element.name == 'test_utils.pdf',
);
expect(pdfFile.extension, equals('pdf'));
expect(pdfFile.name, equals('test_utils.pdf'));
expect(pdfFile.path, equals(pdfTestFile));
expect(pdfFile.size, equals(7478));
final yamlFile = platformFiles.firstWhere(
(element) => element.name == 'test_utils.yml',
);
expect(yamlFile.extension, equals('yml'));
expect(yamlFile.name, equals('test_utils.yml'));
expect(yamlFile.path, equals(yamlTestFile));
expect(yamlFile.size, equals(213));
});
test(
'should transform an empty list of file paths into an empty list of PlatformFiles',
() async {
final filePaths = <String>[];
final platformFiles = await filePathsToPlatformFiles(
filePaths,
false,
false,
);
expect(platformFiles.length, equals(filePaths.length));
});
test(
'should tranform a list of file paths containing a path into a list of PlatformFiles',
() async {
final filePaths = <String>['test'];
final platformFiles = await filePathsToPlatformFiles(
filePaths,
true,
false,
);
expect(platformFiles.length, equals(filePaths.length));
});
test(
'should transform a list of file paths containing a valid path into a list of PlatformFiles',
() async {
final filePaths = <String>['test/test_files/test.pdf'];
final platformFiles = await filePathsToPlatformFiles(
filePaths,
false,
true,
);
expect(platformFiles.length, equals(filePaths.length));
});
});
group('runExecutableWithArguments()', () {
test('should catch an exception when sending an empty filepath', () async {
final filepath = '';
expect(
() async => await isExecutableOnPath(filepath),
throwsA(isA<Exception>()),
);
});
});
group('isAlpha()', () {
test('should identify alpha chars', () async {
expect(isAlpha('a'), equals(true));
expect(isAlpha('A'), equals(true));
expect(isAlpha('z'), equals(true));
expect(isAlpha('Z'), equals(true));
expect(isAlpha('.'), equals(false));
expect(isAlpha('*'), equals(false));
expect(isAlpha(' '), equals(false));
});
});
}