Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit c6dcd2e

Browse files
authored
add share test
1 parent f6c8c4b commit c6dcd2e

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

packages/share/test/share_test.dart

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:io';
56
import 'dart:ui';
67

8+
import 'package:flutter/services.dart';
79
import 'package:mockito/mockito.dart';
810
import 'package:share/share.dart';
911
import 'package:test/test.dart';
1012

11-
import 'package:flutter/services.dart';
12-
1313
void main() {
1414
MockMethodChannel mockChannel;
1515

@@ -56,6 +56,58 @@ void main() {
5656
'originHeight': 4.0,
5757
}));
5858
});
59+
60+
test('sharing null file fails', () {
61+
expect(
62+
() => Share.shareFile(null),
63+
throwsA(const TypeMatcher<AssertionError>()),
64+
);
65+
verifyZeroInteractions(mockChannel);
66+
});
67+
68+
test('sharing empty file fails', () {
69+
expect(
70+
() => Share.shareFile(null),
71+
throwsA(const TypeMatcher<AssertionError>()),
72+
);
73+
verifyZeroInteractions(mockChannel);
74+
});
75+
76+
test('sharing non existing file fails', () {
77+
expect(
78+
() => Share.shareFile(File('/sdcard/nofile.txt')),
79+
throwsA(const TypeMatcher<AssertionError>()),
80+
);
81+
verifyZeroInteractions(mockChannel);
82+
});
83+
84+
test('sharing file sets correct mimeType', () async {
85+
final File file = File('tempfile-83649a.png');
86+
try {
87+
file.createSync();
88+
await Share.shareFile(file);
89+
verify(mockChannel.invokeMethod('shareFile', <String, dynamic>{
90+
'path': file.path,
91+
'mimeType': 'image/png',
92+
}));
93+
} finally {
94+
file.deleteSync();
95+
}
96+
});
97+
98+
test('sharing file sets passed mimeType', () async {
99+
final File file = File('tempfile-83649a.png');
100+
try {
101+
file.createSync();
102+
await Share.shareFile(file, mimeType: '*/*');
103+
verify(mockChannel.invokeMethod('shareFile', <String, dynamic>{
104+
'path': file.path,
105+
'mimeType': '*/*',
106+
}));
107+
} finally {
108+
file.deleteSync();
109+
}
110+
});
59111
}
60112

61113
class MockMethodChannel extends Mock implements MethodChannel {}

0 commit comments

Comments
 (0)