|
| 1 | +import 'package:flutter/foundation.dart'; |
| 2 | +import 'package:flutter_test/flutter_test.dart'; |
| 3 | +import 'package:google_api_availability/google_api_availability.dart'; |
| 4 | + |
| 5 | +import 'method_channel_mock.dart'; |
| 6 | + |
| 7 | +void main() { |
| 8 | + TestWidgetsFlutterBinding.ensureInitialized(); |
| 9 | + |
| 10 | + test('Should receive notAvailableOnPlatform is not Android', () async { |
| 11 | + debugDefaultTargetPlatformOverride = TargetPlatform.iOS; |
| 12 | + |
| 13 | + final googlePlayServiceAvailability = await GoogleApiAvailability.private() |
| 14 | + .checkGooglePlayServicesAvailability(); |
| 15 | + |
| 16 | + expect(googlePlayServiceAvailability, |
| 17 | + GooglePlayServicesAvailability.notAvailableOnPlatform); |
| 18 | + |
| 19 | + debugDefaultTargetPlatformOverride = null; |
| 20 | + }); |
| 21 | + |
| 22 | + test('Should receive the corresponding GooglePlayServiceAvailability', |
| 23 | + () async { |
| 24 | + final availability = GooglePlayServicesAvailability.serviceDisabled; |
| 25 | + |
| 26 | + MethodChannelMock( |
| 27 | + channelName: 'flutter.baseflow.com/google_api_availability/methods', |
| 28 | + method: 'checkPlayServicesAvailability', |
| 29 | + result: availability.value, |
| 30 | + ); |
| 31 | + |
| 32 | + final googlePlayServiceAvailability = await GoogleApiAvailability.private() |
| 33 | + .checkGooglePlayServicesAvailability(); |
| 34 | + |
| 35 | + expect(googlePlayServiceAvailability, availability); |
| 36 | + }); |
| 37 | + |
| 38 | + test( |
| 39 | + 'Should receive GooglePlayServiceAvailability.unknown when availability is null', |
| 40 | + () async { |
| 41 | + final availability = null; |
| 42 | + |
| 43 | + MethodChannelMock( |
| 44 | + channelName: 'flutter.baseflow.com/google_api_availability/methods', |
| 45 | + method: 'checkPlayServicesAvailability', |
| 46 | + result: availability, |
| 47 | + ); |
| 48 | + |
| 49 | + final googlePlayServiceAvailability = await GoogleApiAvailability.private() |
| 50 | + .checkGooglePlayServicesAvailability(); |
| 51 | + |
| 52 | + expect( |
| 53 | + googlePlayServiceAvailability, GooglePlayServicesAvailability.unknown); |
| 54 | + }); |
| 55 | +} |
0 commit comments