This repository was archived by the owner on Feb 22, 2023. It is now read-only.
forked from flutter-team-archive/plugins
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathshare_test.dart
More file actions
117 lines (100 loc) · 2.82 KB
/
Copy pathshare_test.dart
File metadata and controls
117 lines (100 loc) · 2.82 KB
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
// Copyright 2019 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:io';
import 'dart:ui';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:share/share.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized(); // Required for MethodChannels
late FakeMethodChannel fakeChannel;
setUp(() {
fakeChannel = FakeMethodChannel();
// Re-pipe to our fake to verify invocations.
Share.channel.setMockMethodCallHandler((MethodCall call) async {
// The explicit type can be void as the only method call has a return type of void.
await fakeChannel.invokeMethod<void>(call.method, call.arguments);
});
});
test('sharing empty fails', () {
expect(
() => Share.share(''),
throwsA(isA<AssertionError>()),
);
expect(fakeChannel.invocation, isNull);
});
test('sharing origin sets the right params', () async {
await Share.share(
'some text to share',
subject: 'some subject to share',
sharePositionOrigin: const Rect.fromLTWH(1.0, 2.0, 3.0, 4.0),
);
expect(
fakeChannel.invocation,
equals({
'share': {
'text': 'some text to share',
'subject': 'some subject to share',
'originX': 1.0,
'originY': 2.0,
'originWidth': 3.0,
'originHeight': 4.0,
}
}),
);
});
test('sharing empty file fails', () {
expect(
() => Share.shareFiles(['']),
throwsA(isA<AssertionError>()),
);
expect(fakeChannel.invocation, isNull);
});
test('sharing file sets correct mimeType', () async {
final String path = 'tempfile-83649a.png';
final File file = File(path);
try {
file.createSync();
await Share.shareFiles([path]);
expect(
fakeChannel.invocation,
equals({
'shareFiles': {
'paths': [path],
'mimeTypes': ['image/png'],
}
}),
);
} finally {
file.deleteSync();
}
});
test('sharing file sets passed mimeType', () async {
final String path = 'tempfile-83649a.png';
final File file = File(path);
try {
file.createSync();
await Share.shareFiles([path], mimeTypes: ['*/*']);
expect(
fakeChannel.invocation,
equals({
'shareFiles': {
'paths': [file.path],
'mimeTypes': ['*/*'],
}
}),
);
} finally {
file.deleteSync();
}
});
}
class FakeMethodChannel extends Fake implements MethodChannel {
Map<String, dynamic>? invocation;
@override
Future<T?> invokeMethod<T>(String method, [dynamic arguments]) async {
this.invocation = {method: arguments};
return null;
}
}