initializeMultiscreenPrototype static method

void initializeMultiscreenPrototype(
  1. AFDispatcher dispatcher,
  2. AFWorkflowStatePrototype test
)

Implementation

static void initializeMultiscreenPrototype(AFDispatcher dispatcher, AFWorkflowStatePrototype test) {
  AFibF.g.isInteractiveStateTestContext = false;
  dispatcher.dispatch(AFResetToInitialStateAction());
  dispatcher.dispatch(AFUpdateActivePrototypeAction(prototypeId: test.id));

  final screenMap = AFibF.g.screenMap;
  dispatcher.dispatch(AFNavigatePushAction(
    launchParam: screenMap.trueCreateStartupScreenParam!.call()
  ));
  dispatcher.dispatch(AFStartPrototypeScreenTestAction(test, navigate: test.navigate));

  // lookup the test.
  final testImpl = AFibF.g.stateTests.findById(test.stateTestId);
  if(testImpl == null) throw AFException("Test with ID ${test.stateTestId} not found");

  // then, execute the desired state test to bring us to our desired state.
  final store = AFibF.g.internalOnlyActiveStore;
  //final mainDispatcher = AFStoreDispatcher(store);
  //final stateDispatcher = AFStateScreenTestDispatcher(mainDispatcher);

  final stateTestContext = AFStateTestContextForState(testImpl,  AFConceptualStore.appStore, isTrueTestContext: false);
  testImpl.execute(stateTestContext);
  //stateTestContext.dispatcher = mainDispatcher;


  if(stateTestContext.errors.hasErrors) {
    // TODO: this has errors, need to investigate why!
  }

  // now, perform an action that navigates to the specified path, only in flutter.
  final route = store.state.public.route;
  dispatcher.dispatch(AFNavigateSyncNavigatorStateWithRoute(route));
  final showingScreens = route.activeShowingScreens;
  if(showingScreens.length > 1) {
    throw AFException("Currently, you cannot jump into a state test at a point where more than one transient UI element (dialog, drawer, bottomsheet) is simultaneously showing");
  }
  if(showingScreens.isNotEmpty) {
    final showingScreen = showingScreens.first;
    // this occurs when a dialog, bottomsheet, or drawer is actively displayed
    // in the current route.   In this scenario, we have already executed the
    // state part of opening the dialog, etc, but we haven't actually done the open
    // because we didn't have a BuildContext at the time.   So, below, we do the
    // actual open, then make sure to route the result through the expected code-path
    // as though it had been opened the normal way.
    Future.delayed(const Duration(seconds: 1), () async {
      final uiType = showingScreen.kind;
      final showScreenId = showingScreen.screenId;

      final builder = AFibF.g.screenMap.findBy(showScreenId);
      final ctx = AFibF.g.testOnlyScreenBuildContextMap[route.activeScreenId];
      assert(builder != null && ctx != null);
      if(builder != null && ctx != null) {
        var result;
        if(uiType == AFUIType.dialog) {
          result = await material.showDialog(
            context: ctx,
            builder: builder
          );
        } else if(uiType == AFUIType.bottomSheet) {
          result = await material.showModalBottomSheet(
            context: ctx,
            builder: builder
          );
        } else if(uiType == AFUIType.drawer) {
          final scaffold = material.Scaffold.of(ctx);
          scaffold.openDrawer();
        } else {
          assert(false, "Unsupposed UI type");
        }

        if(uiType == AFUIType.dialog || uiType == AFUIType.bottomSheet) {
          AFibF.g.testOnlySimulateCloseDialogOrSheet(showScreenId, result);
        }
      }
    });
  }
  AFibF.g.isInteractiveStateTestContext = true;
}