first commit
This commit is contained in:
26
test/custom_social_share_method_channel_test.dart
Normal file
26
test/custom_social_share_method_channel_test.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:custom_social_share/src/custom_social_share_method_channel.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
MethodChannelCustomSocialShare platform = MethodChannelCustomSocialShare();
|
||||
const MethodChannel channel = MethodChannel('custom_social_share');
|
||||
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
setUp(() {
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
|
||||
return true;
|
||||
});
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, null);
|
||||
});
|
||||
|
||||
test('toAll', () async {
|
||||
expect(await platform.toAll('success'), true);
|
||||
});
|
||||
}
|
61
test/custom_social_share_test.dart
Normal file
61
test/custom_social_share_test.dart
Normal file
@@ -0,0 +1,61 @@
|
||||
import 'package:custom_social_share/src/custom_social_share.dart';
|
||||
import 'package:custom_social_share/src/custom_social_share_method_channel.dart';
|
||||
import 'package:custom_social_share/src/custom_social_share_platform_interface.dart';
|
||||
import 'package:custom_social_share/src/enums.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||
|
||||
class MockCustomSocialSharePlatform
|
||||
with MockPlatformInterfaceMixin
|
||||
implements CustomSocialSharePlatform {
|
||||
@override
|
||||
Future<bool> copy(String content) => Future.value(content == 'success');
|
||||
|
||||
@override
|
||||
Future<bool> toAll(String content) => Future.value(content == 'success');
|
||||
|
||||
@override
|
||||
Future<bool> to(ShareWith shareWith, String content) =>
|
||||
Future.value(ShareWith.sms == shareWith && content == 'success');
|
||||
|
||||
@override
|
||||
Future<List<ShareWith>> getInstalledAppsForShare() =>
|
||||
Future.value([ShareWith.sms, ShareWith.email]);
|
||||
|
||||
@override
|
||||
Future<bool> customApp(String package, String content) => Future.value(
|
||||
package == 'com.google.android.apps.dynamite' && content == 'success');
|
||||
}
|
||||
|
||||
void main() {
|
||||
final CustomSocialSharePlatform initialPlatform =
|
||||
CustomSocialSharePlatform.instance;
|
||||
|
||||
test('$MethodChannelCustomSocialShare is the default instance', () {
|
||||
expect(initialPlatform, isInstanceOf<MethodChannelCustomSocialShare>());
|
||||
});
|
||||
|
||||
test('getPlatformVersion', () async {
|
||||
CustomSocialShare customSocialSharePlugin = CustomSocialShare();
|
||||
MockCustomSocialSharePlatform fakePlatform =
|
||||
MockCustomSocialSharePlatform();
|
||||
CustomSocialSharePlatform.instance = fakePlatform;
|
||||
|
||||
expect(await customSocialSharePlugin.toAll('success'), true);
|
||||
expect(await customSocialSharePlugin.toAll('other'), false);
|
||||
|
||||
expect(await customSocialSharePlugin.to(ShareWith.sms, 'success'), true);
|
||||
expect(await customSocialSharePlugin.to(ShareWith.email, 'other'), false);
|
||||
|
||||
expect(await customSocialSharePlugin.getInstalledAppsForShare(),
|
||||
[ShareWith.sms, ShareWith.email]);
|
||||
|
||||
expect(
|
||||
await customSocialSharePlugin.customApp(
|
||||
'com.google.android.apps.dynamite', 'success'),
|
||||
true);
|
||||
expect(
|
||||
await customSocialSharePlugin.customApp('com.google.android', 'other'),
|
||||
false);
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user