| 
1 | 1 | import 'package:flutter_test/flutter_test.dart';  | 
2 |  | -import 'package:share_plus_platform_interface/share_plus_platform_interface.dart';  | 
3 | 2 | import 'package:share_plus_windows/share_plus_windows.dart';  | 
 | 3 | +import 'package:share_plus_windows/src/version_helper.dart';  | 
 | 4 | +import 'package:share_plus_platform_interface/share_plus_platform_interface.dart';  | 
 | 5 | +import 'package:share_plus_platform_interface/method_channel/method_channel_share.dart';  | 
 | 6 | + | 
4 | 7 | import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';  | 
5 | 8 | import 'package:url_launcher_platform_interface/link.dart';  | 
6 | 9 | 
 
  | 
7 | 10 | void main() {  | 
8 |  | -  test('registered instance', () {  | 
9 |  | -    ShareWindows.registerWith();  | 
10 |  | -    expect(SharePlatform.instance, isA<ShareWindows>());  | 
11 |  | -  });  | 
12 |  | -  test('url encoding is correct for &', () async {  | 
13 |  | -    final mock = MockUrlLauncherPlatform();  | 
14 |  | -    UrlLauncherPlatform.instance = mock;  | 
 | 11 | +  test(  | 
 | 12 | +    'registered instance',  | 
 | 13 | +    () {  | 
 | 14 | +      ShareWindows.registerWith();  | 
 | 15 | +      expect(SharePlatform.instance, isA<ShareWindows>());  | 
 | 16 | +    },  | 
 | 17 | +    skip: VersionHelper.instance.isWindows10RS5OrGreater,  | 
 | 18 | +  );  | 
 | 19 | + | 
 | 20 | +  test(  | 
 | 21 | +    'registered instance',  | 
 | 22 | +    () {  | 
 | 23 | +      ShareWindows.registerWith();  | 
 | 24 | +      expect(SharePlatform.instance, isA<MethodChannelShare>());  | 
 | 25 | +    },  | 
 | 26 | +    skip: !VersionHelper.instance.isWindows10RS5OrGreater,  | 
 | 27 | +  );  | 
 | 28 | + | 
 | 29 | +  // These tests are only valid on Windows versions lower than 10.0.17763.0.  | 
 | 30 | + | 
 | 31 | +  test(  | 
 | 32 | +    'url encoding is correct for &',  | 
 | 33 | +    () async {  | 
 | 34 | +      final mock = MockUrlLauncherPlatform();  | 
 | 35 | +      UrlLauncherPlatform.instance = mock;  | 
15 | 36 | 
 
  | 
16 |  | -    await ShareWindows().share('foo&bar', subject: 'bar&foo');  | 
 | 37 | +      await ShareWindows().share('foo&bar', subject: 'bar&foo');  | 
17 | 38 | 
 
  | 
18 |  | -    expect(mock.url, 'mailto:?subject=bar%26foo&body=foo%26bar');  | 
19 |  | -  });  | 
 | 39 | +      expect(mock.url, 'mailto:?subject=bar%26foo&body=foo%26bar');  | 
 | 40 | +    },  | 
 | 41 | +    skip: VersionHelper.instance.isWindows10RS5OrGreater,  | 
 | 42 | +  );  | 
20 | 43 | 
 
  | 
21 | 44 |   // see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891  | 
22 |  | -  test('url encoding is correct for spaces', () async {  | 
23 |  | -    final mock = MockUrlLauncherPlatform();  | 
24 |  | -    UrlLauncherPlatform.instance = mock;  | 
 | 45 | +  test(  | 
 | 46 | +    'url encoding is correct for spaces',  | 
 | 47 | +    () async {  | 
 | 48 | +      final mock = MockUrlLauncherPlatform();  | 
 | 49 | +      UrlLauncherPlatform.instance = mock;  | 
25 | 50 | 
 
  | 
26 |  | -    await ShareWindows().share('foo bar', subject: 'bar foo');  | 
 | 51 | +      await ShareWindows().share('foo bar', subject: 'bar foo');  | 
27 | 52 | 
 
  | 
28 |  | -    expect(mock.url, 'mailto:?subject=bar%20foo&body=foo%20bar');  | 
29 |  | -  });  | 
 | 53 | +      expect(mock.url, 'mailto:?subject=bar%20foo&body=foo%20bar');  | 
 | 54 | +    },  | 
 | 55 | +    skip: VersionHelper.instance.isWindows10RS5OrGreater,  | 
 | 56 | +  );  | 
30 | 57 | 
 
  | 
31 |  | -  test('throws when url_launcher can\'t launch uri', () async {  | 
32 |  | -    final mock = MockUrlLauncherPlatform();  | 
33 |  | -    mock.canLaunchMockValue = false;  | 
34 |  | -    UrlLauncherPlatform.instance = mock;  | 
 | 58 | +  test(  | 
 | 59 | +    'throws when url_launcher can\'t launch uri',  | 
 | 60 | +    () async {  | 
 | 61 | +      final mock = MockUrlLauncherPlatform();  | 
 | 62 | +      mock.canLaunchMockValue = false;  | 
 | 63 | +      UrlLauncherPlatform.instance = mock;  | 
35 | 64 | 
 
  | 
36 |  | -    expect(() async => await ShareWindows().share('foo bar'), throwsException);  | 
37 |  | -  });  | 
 | 65 | +      expect(  | 
 | 66 | +          () async => await ShareWindows().share('foo bar'), throwsException);  | 
 | 67 | +    },  | 
 | 68 | +    skip: VersionHelper.instance.isWindows10RS5OrGreater,  | 
 | 69 | +  );  | 
38 | 70 | }  | 
39 | 71 | 
 
  | 
40 | 72 | class MockUrlLauncherPlatform extends UrlLauncherPlatform {  | 
 | 
0 commit comments