Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 用Mockito和Cubit模拟上下文_Flutter - Fatal编程技术网

Flutter 用Mockito和Cubit模拟上下文

Flutter 用Mockito和Cubit模拟上下文,flutter,Flutter,我有以下代码 Widget _mapContainer(BuildContext context, bool isMapGesturesEnabled) { var coordinates = LatLng(0, 0); var state = context.bloc<AuthenticationCubit>().state; // ignore: todo // TODO: Improve how props are handled var user = (sta

我有以下代码

  Widget _mapContainer(BuildContext context, bool isMapGesturesEnabled) {
var coordinates = LatLng(0, 0);
var state = context.bloc<AuthenticationCubit>().state;
  // ignore: todo
  // TODO: Improve how props are handled
  var user = (state.props[0] as User);
  var factoryName = user.factoryName;

  if (factoryName != null) {
    var factories = context.bloc<ApiCubit>().fetchFactories();
    var userFactory = factories.firstWhere(
        (Factory userFactory) => userFactory.name == factoryName);
    coordinates = userFactory.coordinates;
  }
}
class _MockAuthenticationCubit extends Mock implements AuthenticationCubit {}

void main() {
  group('Dashboard', () {
    _createDashboard() {
      return MultiBlocProvider(
        providers: [
          BlocProvider<AuthenticationCubit>(
            create: (context) => _MockAuthenticationCubit(),
          ),
        ],
        child: MediaQuery(
          data: MediaQueryData(),
          child: MaterialApp(
            localizationsDelegates: [
              S.delegate,
            ],
            supportedLocales: S.delegate.supportedLocales,
            home: Dashboard(),
          ),
        ),
      );
    }

    group('MapLegend', () {
      testWidgets('should display a map',
          (WidgetTester tester) async {
        User user = User(Role.MANAGER, "my_factory");

        await tester.pumpWidget(_createBoard());
        when(_MockAuthenticationCubit().state)
            .thenReturn(AuthenticationSuccess(user: user));
        await tester.pump();

        expect(
          find.byType(MapLegend),
          findsOneWidget,
        );
      });
    });
  });
}