weibo_kit/test/weibo_kit_test.dart
沉默的湮灰 9514a79f6a
v2 (#22)
v2
2020-06-22 22:29:21 +08:00

80 lines
2.2 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:async';
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pedantic/pedantic.dart';
import 'package:weibo_kit/weibo_kit.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
const MethodChannel channel = MethodChannel('v7lin.github.io/weibo_kit');
final Weibo weibo = Weibo();
setUp(() {
channel.setMockMethodCallHandler((MethodCall call) async {
switch (call.method) {
case 'registerApp':
return null;
case 'isInstalled':
return true;
case 'auth':
unawaited(channel.binaryMessenger.handlePlatformMessage(
channel.name,
channel.codec.encodeMethodCall(
MethodCall('onAuthResp', json.decode('{"errorCode":-1}'))),
(ByteData data) {
// mock success
},
));
return null;
case 'shareText':
case 'shareImage':
case 'shareWebpage':
unawaited(channel.binaryMessenger.handlePlatformMessage(
channel.name,
channel.codec.encodeMethodCall(
MethodCall('onShareMsgResp', json.decode('{"errorCode":-1}'))),
(ByteData data) {
// mock success
},
));
return null;
}
throw PlatformException(code: '0', message: '想啥呢升级插件不想升级Mock');
});
});
tearDown(() {
channel.setMockMethodCallHandler(null);
});
test('isInstalled', () async {
expect(await weibo.isInstalled(), true);
});
test('auth', () async {
StreamSubscription<WeiboAuthResp> sub =
weibo.authResp().listen((WeiboAuthResp resp) {
expect(resp.errorCode, WeiboSdkResp.USERCANCEL);
});
await weibo.auth(
appKey: 'your weibo app key',
scope: <String>[WeiboScope.ALL],
);
await sub.cancel();
});
test('share', () async {
StreamSubscription<WeiboSdkResp> sub =
weibo.shareMsgResp().listen((WeiboSdkResp resp) {
expect(resp.errorCode, WeiboSdkResp.USERCANCEL);
});
await weibo.shareText(
text: 'share text',
);
await sub.cancel();
});
}