/
share_plus_linux_test.dart
67 lines (55 loc) · 1.96 KB
/
share_plus_linux_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
import 'package:flutter_test/flutter_test.dart';
import 'package:share_plus/share_plus.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', () {
SharePlusLinuxPlugin.registerWith();
expect(SharePlatform.instance, isA<SharePlusLinuxPlugin>());
});
test('url encoding is correct for &', () async {
final mock = MockUrlLauncherPlatform();
await SharePlusLinuxPlugin(mock).share('foo&bar', subject: 'bar&foo');
expect(mock.url, 'mailto:?subject=bar%26foo&body=foo%26bar');
});
// see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891
test('url encoding is correct for spaces', () async {
final mock = MockUrlLauncherPlatform();
await SharePlusLinuxPlugin(mock).share('foo bar', subject: 'bar foo');
expect(mock.url, 'mailto:?subject=bar%20foo&body=foo%20bar');
});
test('throws when url_launcher can\'t launch uri', () async {
final mock = MockUrlLauncherPlatform();
mock.canLaunchMockValue = false;
expect(() async => await SharePlusLinuxPlugin(mock).share('foo bar'),
throwsException);
});
}
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;
if (!canLaunchMockValue) {
throw Exception();
}
return true;
}
}