Commit 54d0c22e authored by Vadaski's avatar Vadaski

add container manager test

- test `of` method, try to get the ContainerManagerState in the ancestor node
- test `tryOf` method, try to get the ContainerManagerState in the ancestor node
parent 787c847a
...@@ -3,6 +3,7 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -3,6 +3,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_boost/flutter_boost.dart'; import 'package:flutter_boost/flutter_boost.dart';
import 'package:flutter_boost/container/container_coordinator.dart';
final GlobalKey scaffoldKey = GlobalKey(); final GlobalKey scaffoldKey = GlobalKey();
...@@ -112,66 +113,86 @@ void main() { ...@@ -112,66 +113,86 @@ void main() {
testWidgets( testWidgets(
'through the `BoostContainerManager.of(context)` method', 'through the `BoostContainerManager.of(context)` method',
(WidgetTester tester) async { (WidgetTester tester) async {
var findBoostContainerManagerByOfMethod; var builderContext;
await tester.pumpWidget( FlutterBoost.singleton.registerPageBuilders({
MaterialApp( 'context': (pageName, params, _) => Builder(
builder: (BuildContext context, Widget child) { builder: (context) {
final BoostContainerManager manager = BoostContainerManager( return FloatingActionButton(
initNavigator: child, onPressed: () {
); builderContext = context;
return manager;
}, },
home: Builder( );
builder: (BuildContext context) {
return FloatingActionButton(onPressed: () {
findBoostContainerManagerByOfMethod = context;
});
}, },
), ),
});
await tester.pumpWidget(
MaterialApp(
builder: FlutterBoost.init(),
home: Container(),
), ),
); );
//open context page
ContainerCoordinator.singleton
.nativeContainerDidShow("context", {}, "1000000");
await tester.pump(Duration(seconds: 1));
expect(find.byType(FloatingActionButton), findsOneWidget);
//get the context of the Builder
await tester.tap(find.byType(FloatingActionButton)); await tester.tap(find.byType(FloatingActionButton));
expect( final isFind = BoostContainerManager.of(builderContext) != null;
BoostContainerManager.of(findBoostContainerManagerByOfMethod),
const TypeMatcher<ContainerManagerState>(), expect(isFind, true,
); reason: '`BoostContainerManager.of` should be able to '
'find `ContainerManagerState` in `FlutterBoost.init()` based on the context of the `Builder`');
}, },
); );
testWidgets( testWidgets(
'through the `BoostContainerManager.tryOf(context)` method', 'through the `BoostContainerManager.tryOf(context)` method',
(WidgetTester tester) async { (WidgetTester tester) async {
var findBoostContainerManagerByOfMethod; var builderContext;
await tester.pumpWidget( FlutterBoost.singleton.registerPageBuilders({
MaterialApp( 'context': (pageName, params, _) => Builder(
builder: (BuildContext context, Widget child) { builder: (context) {
final BoostContainerManager manager = BoostContainerManager( return FloatingActionButton(
initNavigator: child, onPressed: () {
); builderContext = context;
return manager;
}, },
home: Builder( );
builder: (BuildContext context) {
return FloatingActionButton(onPressed: () {
findBoostContainerManagerByOfMethod = context;
});
}, },
), ),
});
await tester.pumpWidget(
MaterialApp(
builder: FlutterBoost.init(),
home: Container(),
), ),
); );
//open context page
ContainerCoordinator.singleton
.nativeContainerDidShow("context", {}, "1000000");
await tester.pump(Duration(seconds: 1));
expect(find.byType(FloatingActionButton), findsOneWidget);
//get the context of the Builder
await tester.tap(find.byType(FloatingActionButton)); await tester.tap(find.byType(FloatingActionButton));
expect( final isFind = BoostContainerManager.tryOf(builderContext) != null;
BoostContainerManager.tryOf(findBoostContainerManagerByOfMethod),
const TypeMatcher<ContainerManagerState>(), expect(isFind, true,
); reason: '`BoostContainerManager.tryOf` should be able to '
'find `ContainerManagerState` in `FlutterBoost.init()` based on the context of the `Builder`');
}, },
); );
}, },
......
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