mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-13 20:03:46 +00:00
refactor: share async invoke bridge across native platforms
This commit is contained in:
1 parent
d12122ea86
commit
607d1729e6
17 files changed
+464
-222
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:gopeed/core/common/libgopeed_channel.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
const channel = MethodChannel('gopeed.com/libgopeed');
|
||||
final messenger = TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
||||
|
||||
tearDown(() {
|
||||
messenger.setMockMethodCallHandler(channel, null);
|
||||
});
|
||||
|
||||
test('mobile invokes carry unique request IDs for async callbacks', () async {
|
||||
final requestIDs = <int>[];
|
||||
messenger.setMockMethodCallHandler(channel, (call) async {
|
||||
expect(call.method, 'invoke');
|
||||
final arguments = (call.arguments as Map<Object?, Object?>).cast<String, Object?>();
|
||||
requestIDs.add(arguments['requestID']! as int);
|
||||
return '{"code":0}';
|
||||
});
|
||||
|
||||
final bridge = LibgopeedChannel();
|
||||
await Future.wait([bridge.invoke('GET', '/api/v1/info'), bridge.invoke('GET', '/api/v1/config')]);
|
||||
|
||||
expect(requestIDs, [0, 1]);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user