|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be
|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
| 5 | +import 'dart:io'; |
5 | 6 | import 'dart:ui';
|
6 | 7 |
|
| 8 | +import 'package:flutter/services.dart'; |
7 | 9 | import 'package:mockito/mockito.dart';
|
8 | 10 | import 'package:share/share.dart';
|
9 | 11 | import 'package:test/test.dart';
|
10 | 12 |
|
11 |
| -import 'package:flutter/services.dart'; |
12 |
| - |
13 | 13 | void main() {
|
14 | 14 | MockMethodChannel mockChannel;
|
15 | 15 |
|
@@ -56,6 +56,58 @@ void main() {
|
56 | 56 | 'originHeight': 4.0,
|
57 | 57 | }));
|
58 | 58 | });
|
| 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 | + }); |
59 | 111 | }
|
60 | 112 |
|
61 | 113 | class MockMethodChannel extends Mock implements MethodChannel {}
|
0 commit comments