mirror of
https://github.com/RxReader/tencent_kit.git
synced 2025-07-03 03:42:47 +08:00
升级Flutter 3.0
This commit is contained in:
27
test/tencent_kit_method_channel_test.dart
Normal file
27
test/tencent_kit_method_channel_test.dart
Normal file
@ -0,0 +1,27 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tencent_kit/src/tencent_kit_method_channel.dart';
|
||||
|
||||
void main() {
|
||||
final MethodChannelTencentKit platform = MethodChannelTencentKit();
|
||||
const MethodChannel channel = MethodChannel('v7lin.github.io/tencent_kit');
|
||||
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
setUp(() {
|
||||
channel.setMockMethodCallHandler((MethodCall methodCall) async {
|
||||
switch(methodCall.method) {
|
||||
case 'isQQInstalled':
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
channel.setMockMethodCallHandler(null);
|
||||
});
|
||||
|
||||
test('getPlatformVersion', () async {
|
||||
expect(await platform.isQQInstalled(), true);
|
||||
});
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
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:tencent_kit/tencent_kit.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
const MethodChannel channel = MethodChannel('v7lin.github.io/tencent_kit');
|
||||
|
||||
setUp(() {
|
||||
channel.setMockMethodCallHandler((MethodCall call) async {
|
||||
switch (call.method) {
|
||||
case 'registerApp':
|
||||
return null;
|
||||
case 'isQQInstalled':
|
||||
return true;
|
||||
case 'isTIMInstalled':
|
||||
return true;
|
||||
case 'login':
|
||||
unawaited(channel.binaryMessenger.handlePlatformMessage(
|
||||
channel.name,
|
||||
channel.codec.encodeMethodCall(
|
||||
MethodCall('onLoginResp', json.decode('{"ret":-2}'))),
|
||||
(ByteData? data) {
|
||||
// mock success
|
||||
},
|
||||
));
|
||||
return null;
|
||||
case 'logout':
|
||||
return null;
|
||||
case 'shareMood':
|
||||
case 'shareText':
|
||||
case 'shareImage':
|
||||
case 'shareMusic':
|
||||
case 'shareWebpage':
|
||||
unawaited(channel.binaryMessenger.handlePlatformMessage(
|
||||
channel.name,
|
||||
channel.codec.encodeMethodCall(
|
||||
MethodCall('onShareResp', json.decode('{"ret":0}'))),
|
||||
(ByteData? data) {
|
||||
// mock success
|
||||
},
|
||||
));
|
||||
return null;
|
||||
}
|
||||
throw PlatformException(code: '0', message: '想啥呢,升级插件不想升级Mock?');
|
||||
});
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
channel.setMockMethodCallHandler(null);
|
||||
});
|
||||
|
||||
test('isQQInstalled', () async {
|
||||
expect(await Tencent.instance.isQQInstalled(), true);
|
||||
});
|
||||
|
||||
test('isTIMInstalled', () async {
|
||||
expect(await Tencent.instance.isTIMInstalled(), true);
|
||||
});
|
||||
|
||||
test('login', () async {
|
||||
final StreamSubscription<BaseResp> subs =
|
||||
Tencent.instance.respStream().listen((BaseResp resp) {
|
||||
expect(resp.runtimeType, LoginResp);
|
||||
expect(resp.ret, BaseResp.RET_USERCANCEL);
|
||||
});
|
||||
await Tencent.instance.login(
|
||||
scope: <String>[
|
||||
TencentScope.GET_SIMPLE_USERINFO,
|
||||
],
|
||||
);
|
||||
await Future<void>.delayed(const Duration(seconds: 1));
|
||||
await subs.cancel();
|
||||
});
|
||||
|
||||
test('share', () async {
|
||||
final StreamSubscription<BaseResp> subs =
|
||||
Tencent.instance.respStream().listen((BaseResp resp) {
|
||||
expect(resp.runtimeType, ShareMsgResp);
|
||||
expect(resp.ret, BaseResp.RET_SUCCESS);
|
||||
});
|
||||
await Tencent.instance.shareMood(
|
||||
scene: TencentScene.SCENE_QZONE,
|
||||
summary: 'share text',
|
||||
);
|
||||
await Future<void>.delayed(const Duration(seconds: 1));
|
||||
await subs.cancel();
|
||||
});
|
||||
}
|
123
test/tencent_test.dart
Normal file
123
test/tencent_test.dart
Normal file
@ -0,0 +1,123 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||
import 'package:tencent_kit/src/tencent_constant.dart';
|
||||
import 'package:tencent_kit/src/tencent_kit_method_channel.dart';
|
||||
import 'package:tencent_kit/src/tencent_kit_platform_interface.dart';
|
||||
import 'package:tencent_kit/tencent_kit.dart';
|
||||
|
||||
class MockTencentKitPlatform with MockPlatformInterfaceMixin implements TencentKitPlatform {
|
||||
@override
|
||||
Future<void> setIsPermissionGranted({
|
||||
required bool granted,
|
||||
String? buildModel,
|
||||
}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> registerApp({
|
||||
required String appId,
|
||||
String? universalLink,
|
||||
}) async {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> isQQInstalled() {
|
||||
return Future<bool>.value(true);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> isTIMInstalled() {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<BaseResp> respStream() {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> login({
|
||||
required List<String> scope,
|
||||
}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> logout() {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> shareImage({
|
||||
required int scene,
|
||||
required Uri imageUri,
|
||||
String? appName,
|
||||
int extInt = TencentQZoneFlag.DEFAULT,
|
||||
}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> shareMood({
|
||||
required int scene,
|
||||
String? summary,
|
||||
List<Uri>? imageUris,
|
||||
Uri? videoUri,
|
||||
}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> shareMusic({
|
||||
required int scene,
|
||||
required String title,
|
||||
String? summary,
|
||||
Uri? imageUri,
|
||||
required String musicUrl,
|
||||
required String targetUrl,
|
||||
String? appName,
|
||||
int extInt = TencentQZoneFlag.DEFAULT,
|
||||
}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> shareText({
|
||||
required int scene,
|
||||
required String summary,
|
||||
}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> shareWebpage({
|
||||
required int scene,
|
||||
required String title,
|
||||
String? summary,
|
||||
Uri? imageUri,
|
||||
required String targetUrl,
|
||||
String? appName,
|
||||
int extInt = TencentQZoneFlag.DEFAULT,
|
||||
}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
final TencentKitPlatform initialPlatform = TencentKitPlatform.instance;
|
||||
|
||||
test('$MethodChannelTencentKit is the default instance', () {
|
||||
expect(initialPlatform, isInstanceOf<MethodChannelTencentKit>());
|
||||
});
|
||||
|
||||
test('getPlatformVersion', () async {
|
||||
final MockTencentKitPlatform fakePlatform = MockTencentKitPlatform();
|
||||
TencentKitPlatform.instance = fakePlatform;
|
||||
|
||||
expect(await Tencent.isQQInstalled(), true);
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user