LCOV - code coverage report
Current view: top level - utils - app_widget_harness.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 34 0.0 %
Date: 2022-03-03 12:15:14 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:fast_immutable_collections/fast_immutable_collections.dart';
       2             : import 'package:flutter/material.dart';
       3             : import 'package:redfire/extensions.dart';
       4             : import 'package:redfire/redfire.dart';
       5             : import 'package:redfire/services.dart';
       6             : import 'package:redfire/types.dart';
       7             : import 'package:redfire/widgets.dart';
       8             : import 'package:redux/redux.dart';
       9             : 
      10             : import '../../redfire_test.dart';
      11             : import '../test-doubles/config/redfire_config.dart';
      12             : import '../test-doubles/config/redfire_config.mocks.dart';
      13             : 
      14             : /// A test harness to wrap the widget under test, (in this case the
      15             : /// AppWidget), and provide all the functionality
      16             : /// that a test may want in order to interact with the widget.
      17             : ///
      18             : class AppWidgetHarness<T extends RedFireState> {
      19             :   final Store<T> _store;
      20             :   final FirebaseWrapper _firebase;
      21             :   late final AppWidget _appWidget;
      22             : 
      23             :   /// Expects an [initialState], which is used to create a [FakeStore],
      24             :   /// which is then used to create the [AppWidget].
      25           0 :   AppWidgetHarness.withFakeStore({required T initialState})
      26           0 :       : _store = FakeStore(initialState),
      27           0 :         _firebase = FakeFirebaseWrapper() {
      28           0 :     _appWidget = AppWidget.fromStore(
      29           0 :       config: RedFireConfigTestDouble.basic,
      30           0 :       logins: ISet(),
      31             :       homePage: const EmptyHomePage(),
      32           0 :       initializedStore: _store,
      33           0 :       firebaseWrapper: FakeFirebaseWrapper(),
      34           0 :       pageTransforms: ISet(),
      35             :     );
      36             :   }
      37             : 
      38             :   /// Expects a [Store] that has already been initialized, which is used to
      39             :   /// create the [AppWidget].
      40           0 :   AppWidgetHarness.withStore({
      41             :     required Store<T> initializedStore,
      42             :     List<ReduxAction>? initialActions,
      43             :     FirebaseWrapper? firebaseWrapper,
      44             :   })  : _store = initializedStore,
      45           0 :         _firebase = firebaseWrapper ?? FakeFirebaseWrapper() {
      46           0 :     _appWidget = AppWidget.fromStore(
      47           0 :       config: MockRedFireConfig(),
      48           0 :       logins: ISet(),
      49             :       homePage: const EmptyHomePage(),
      50           0 :       initializedStore: _store,
      51           0 :       firebaseWrapper: _firebase,
      52           0 :       pageTransforms: ISet(),
      53             :     );
      54             :   }
      55             : 
      56             :   /// Provides the services and their mock plugins to the Locator.
      57             :   /// Also creates a store, initialized with default reducers/middleware and
      58             :   /// dispatches the default actions.
      59           0 :   AppWidgetHarness.withMockedPlugins(T initialState, ServicesHarness services)
      60           0 :       : _firebase = FakeFirebaseWrapper(),
      61           0 :         _store = Store<T>(redfireReducers<T>().combine(),
      62           0 :             initialState: initialState, middleware: redfireMiddlewares()) {
      63           0 :     RedFireLocator.provide(
      64           0 :         authService: services.auth,
      65           0 :         databaseService: services.database,
      66           0 :         platformService: services.platform);
      67           0 :     _appWidget = AppWidget.fromStore(
      68           0 :       config: MockRedFireConfig(),
      69           0 :       logins: ISet(),
      70             :       homePage: const EmptyHomePage(),
      71           0 :       initializedStore: _store,
      72           0 :       firebaseWrapper: _firebase,
      73           0 :       pageTransforms: ISet(),
      74             :     );
      75           0 :     for (var action in redfireInitialActions) {
      76           0 :       _store.dispatch(action);
      77             :     }
      78             :   }
      79             : 
      80           0 :   Widget get widget => _appWidget;
      81             : }

Generated by: LCOV version 1.13