Commit eb1d61ce authored by yangwu.jia's avatar yangwu.jia

Add test case

parent 26e82a00
...@@ -16,6 +16,7 @@ dev_dependencies: ...@@ -16,6 +16,7 @@ dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter
mockito: 4.1.1
# For information on the generic Dart part of this file, see the # For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec # following page: https://www.dartlang.org/tools/pub/pubspec
......
import 'package:flutter_boost/container/container_coordinator.dart'; import 'dart:ui';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:flutter_boost/channel/boost_channel.dart';
import 'package:flutter_boost/container/container_coordinator.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'dart:typed_data';
class MockBoostChannel extends BoostChannel implements Mock {
MethodHandler get testHandler => _testHandler;
EventListener get testEventListener => _testEventListener;
MethodHandler _testHandler;
EventListener _testEventListener;
VoidCallback addEventListener(String name, EventListener listener) {
_testEventListener = listener;
super.addEventListener(name, listener);
}
VoidCallback addMethodHandler(MethodHandler handler) {
_testHandler = handler;
super.addMethodHandler(handler);
}
}
void main() { void main() {
TestWidgetsFlutterBinding.ensureInitialized(); TestWidgetsFlutterBinding.ensureInitialized();
const MessageCodec<dynamic> jsonMessage = JSONMessageCodec();
test('test onMethodCall', () async {
// Initialize all bindings because defaultBinaryMessenger.send() needs a window.
TestWidgetsFlutterBinding.ensureInitialized();
MockBoostChannel boostChannel = MockBoostChannel();
ContainerCoordinator(boostChannel);
final Map arguments = {};
arguments["pageName"] = "pageName";
arguments["params"] = {};
arguments["uniqueId"] = "xxxxx";
MethodCall call = MethodCall('didInitPageContainer', arguments);
try {
boostChannel.testHandler(call);
} catch (e) {
expect(e, isAssertionError);
}
MethodCall call2 = MethodCall('willShowPageContainer', arguments);
try {
boostChannel.testHandler(call2);
} catch (e) {
expect(e, isNoSuchMethodError);
}
MethodCall call3 = MethodCall('didShowPageContainer', arguments);
try {
boostChannel.testHandler(call3);
} catch (e) {
expect(e, isNoSuchMethodError);
}
MethodCall call4 = MethodCall('willDisappearPageContainer', arguments);
try {
boostChannel.testHandler(call4);
} catch (e) {
expect(e, isNoSuchMethodError);
}
MethodCall call5 = MethodCall('onNativePageResult', arguments);
try {
boostChannel.testHandler(call5);
} catch (e) {
expect(e, isNoSuchMethodError);
}
Map arg = {'type': 'backPressedCallback'};
try {
boostChannel.testEventListener("lifecycle", arg);
} catch (e) {
expect(e, isNoSuchMethodError);
}
Map arg2 = {'type': 'foreground'};
try {
boostChannel.testEventListener("lifecycle", arg2);
} catch (e) {
expect(e, isNoSuchMethodError);
}
group('container_coordinator', () { Map arg3 = {'type': 'background'};
try {
boostChannel.testEventListener("lifecycle", arg3);
} catch (e) {
expect(e, isNoSuchMethodError);
}
Map arg4 = {'type': 'scheduleFrame'};
try {
boostChannel.testEventListener("lifecycle", arg4);
} catch (e) {
expect(e, isNoSuchMethodError);
}
}); });
} }
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment