|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | 3 | // found in the LICENSE file. |
4 | 4 |
|
5 | | -import 'dart:io'; |
6 | | - |
7 | 5 | import 'package:android_intent/flag.dart'; |
8 | 6 | import 'package:flutter/services.dart'; |
9 | 7 | import 'package:flutter_test/flutter_test.dart'; |
10 | 8 | import 'package:android_intent/android_intent.dart'; |
| 9 | +import 'package:mockito/mockito.dart'; |
| 10 | +import 'package:platform/platform.dart'; |
11 | 11 |
|
12 | 12 | void main() { |
13 | 13 | AndroidIntent androidIntent; |
14 | | - const MethodChannel channel = |
15 | | - MethodChannel('plugins.flutter.io/android_intent'); |
16 | | - final List<MethodCall> log = <MethodCall>[]; |
| 14 | + MockMethodChannel mockChannel; |
17 | 15 | setUp(() { |
18 | | - channel.setMockMethodCallHandler((MethodCall methodCall) async { |
19 | | - log.add(methodCall); |
20 | | - return ''; |
21 | | - }); |
22 | | - log.clear(); |
| 16 | + mockChannel = MockMethodChannel(); |
23 | 17 | }); |
24 | 18 | group('AndroidIntent', () { |
25 | 19 | test('pass right params', () async { |
26 | | - if (Platform.isIOS) { |
27 | | - } else if (Platform.isAndroid) { |
28 | | - androidIntent = AndroidIntent( |
| 20 | + androidIntent = AndroidIntent.private( |
29 | 21 | action: 'action_view', |
30 | 22 | data: Uri.encodeFull('https://flutter.io'), |
31 | 23 | flags: <int>[Flag.FLAG_ACTIVITY_NEW_TASK], |
32 | | - ); |
33 | | - androidIntent.launch(); |
34 | | - expect( |
35 | | - log, |
36 | | - <Matcher>[ |
37 | | - isMethodCall('launch', arguments: <String, Object>{ |
38 | | - 'action': 'action_view', |
39 | | - 'data': Uri.encodeFull('https://flutter.io'), |
40 | | - 'flags': androidIntent |
41 | | - .convertFlags(<int>[Flag.FLAG_ACTIVITY_NEW_TASK]), |
42 | | - }) |
43 | | - ], |
44 | | - ); |
45 | | - } |
| 24 | + channel: mockChannel, |
| 25 | + platform: FakePlatform(operatingSystem: 'android')); |
| 26 | + androidIntent.launch(); |
| 27 | + verify(mockChannel.invokeMethod<void>('launch', <String, Object>{ |
| 28 | + 'action': 'action_view', |
| 29 | + 'data': Uri.encodeFull('https://flutter.io'), |
| 30 | + 'flags': androidIntent.convertFlags(<int>[Flag.FLAG_ACTIVITY_NEW_TASK]), |
| 31 | + })); |
| 32 | + }); |
| 33 | + test('pass null value to action param', () async { |
| 34 | + androidIntent = AndroidIntent.private( |
| 35 | + action: null, |
| 36 | + channel: mockChannel, |
| 37 | + platform: FakePlatform(operatingSystem: 'android')); |
| 38 | + androidIntent.launch(); |
| 39 | + verify(mockChannel.invokeMethod<void>('launch', <String, Object>{ |
| 40 | + 'action': null, |
| 41 | + })); |
46 | 42 | }); |
47 | | - test('pass wrong params', () async { |
48 | | - if (Platform.isIOS) { |
49 | | - } else if (Platform.isAndroid) { |
50 | | - androidIntent = AndroidIntent( |
| 43 | + |
| 44 | + test('call in ios platform', () async { |
| 45 | + androidIntent = AndroidIntent.private( |
51 | 46 | action: null, |
52 | | - ); |
53 | | - androidIntent.launch(); |
54 | | - expect( |
55 | | - log, |
56 | | - <Matcher>[ |
57 | | - isMethodCall('launch', arguments: <String, Object>{ |
58 | | - 'action': null, |
59 | | - }) |
60 | | - ], |
61 | | - ); |
62 | | - } |
| 47 | + channel: mockChannel, |
| 48 | + platform: FakePlatform(operatingSystem: 'ios')); |
| 49 | + androidIntent.launch(); |
| 50 | + verifyZeroInteractions(mockChannel); |
63 | 51 | }); |
64 | 52 | }); |
65 | | - group('Flags: ', () { |
66 | | - androidIntent = AndroidIntent( |
| 53 | + group('convertFlags ', () { |
| 54 | + androidIntent = const AndroidIntent( |
67 | 55 | action: 'action_view', |
68 | 56 | ); |
69 | 57 | test('add filled flag list', () async { |
@@ -93,3 +81,5 @@ void main() { |
93 | 81 | }); |
94 | 82 | }); |
95 | 83 | } |
| 84 | + |
| 85 | +class MockMethodChannel extends Mock implements MethodChannel {} |
0 commit comments