forked from fluttercommunity/plus_plugins
/
share_plus_windows_test.dart
68 lines (56 loc) · 2.09 KB
/
share_plus_windows_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
import 'package:flutter_test/flutter_test.dart';
import 'package:share_plus/src/share_plus_windows.dart';
import 'package:share_plus/src/windows_version_helper.dart';
import 'package:share_plus_platform_interface/method_channel/method_channel_share.dart';
import 'package:share_plus_platform_interface/share_plus_platform_interface.dart';
import 'package:url_launcher_platform_interface/link.dart';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
import 'url_launcher_mock.dart';
void main() {
test(
'registered instance',
() {
SharePlusWindowsPlugin.registerWith();
expect(SharePlatform.instance, isA<SharePlusWindowsPlugin>());
},
skip: VersionHelper.instance.isWindows10RS5OrGreater,
);
test(
'registered instance',
() {
SharePlusWindowsPlugin.registerWith();
expect(SharePlatform.instance, isA<MethodChannelShare>());
},
skip: !VersionHelper.instance.isWindows10RS5OrGreater,
);
// These tests are only valid on Windows versions lower than 10.0.17763.0.
test(
'url encoding is correct for &',
() async {
final mock = MockUrlLauncherPlatform();
await SharePlusWindowsPlugin(mock).share('foo&bar', subject: 'bar&foo');
expect(mock.url, 'mailto:?subject=bar%26foo&body=foo%26bar');
},
skip: VersionHelper.instance.isWindows10RS5OrGreater,
);
// see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891
test(
'url encoding is correct for spaces',
() async {
final mock = MockUrlLauncherPlatform();
await SharePlusWindowsPlugin(mock).share('foo bar', subject: 'bar foo');
expect(mock.url, 'mailto:?subject=bar%20foo&body=foo%20bar');
},
skip: VersionHelper.instance.isWindows10RS5OrGreater,
);
test(
'throws when url_launcher can\'t launch uri',
() async {
final mock = MockUrlLauncherPlatform();
mock.canLaunchMockValue = false;
expect(() async => await SharePlusWindowsPlugin(mock).share('foo bar'),
throwsException);
},
skip: VersionHelper.instance.isWindows10RS5OrGreater,
);
}