forked from fluttercommunity/plus_plugins
/
share_plus_windows_test.dart
94 lines (79 loc) · 2.68 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
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
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';
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,
);
}
class MockUrlLauncherPlatform extends UrlLauncherPlatform {
String? url;
bool canLaunchMockValue = true;
@override
LinkDelegate? get linkDelegate => throw UnimplementedError();
@override
Future<bool> canLaunch(String url) async {
return canLaunchMockValue;
}
@override
Future<bool> launch(
String url, {
required bool useSafariVC,
required bool useWebView,
required bool enableJavaScript,
required bool enableDomStorage,
required bool universalLinksOnly,
required Map<String, String> headers,
String? webOnlyWindowName,
}) async {
this.url = url;
return true;
}
}