loadScreen method

Future<EnsembleConfig> loadScreen({
  1. required WidgetTester tester,
  2. required EnsembleTestCase testCase,
  3. EnsembleConfig? existingConfig,
  4. EnsembleTestContext? context,
  5. EnsembleTestConfig suiteConfig = const EnsembleTestConfig(),
  6. Future<void> beforeBootstrap()?,
  7. Locale? forcedLocale,
})

Implementation

Future<EnsembleConfig> loadScreen({
  required WidgetTester tester,
  required EnsembleTestCase testCase,
  EnsembleConfig? existingConfig,
  EnsembleTestContext? context,
  EnsembleTestConfig suiteConfig = const EnsembleTestConfig(),
  Future<void> Function()? beforeBootstrap,
  Locale? forcedLocale,
}) async {
  // Independent tests need a new EnsembleApp state. Pumping another
  // EnsembleApp of the same type would otherwise reuse the prior route.
  await tester.pumpWidget(const SizedBox.shrink());
  await tester.pump();
  resetTestRuntime();
  ScreenTracker().clearAll();
  YamlTestSession.navigationFlow.clear();
  await beforeBootstrap?.call();

  final ctx = context ??
      EnsembleTestContext.fromTestCase(
        testCase,
        config: suiteConfig,
      );
  final screenshotDevice = screenshotDeviceForTestCase(testCase, ctx.config);
  if (screenshotDevice != null) {
    await _setViewportForDevice(tester, ctx, screenshotDevice);
  }
  await _ensureDefaultViewport(tester, ctx);
  var config = existingConfig ?? await buildConfig();
  final bootstrapped = await tester.runAsync(() async {
    return bootstrapRuntime(
      config,
      ctx.setup,
      apiOverlay: ctx.apiOverlay,
    );
  });
  config = bootstrapped!;

  final startScreen = testCase.startScreen;
  if (startScreen == null || startScreen.isEmpty) {
    throw EnsembleTestFailure(
      'loadScreen requires startScreen on test "${testCase.id}"',
    );
  }

  final deviceTheme = testCase.deviceTarget?.theme;
  await tester.runAsync(() => seedEnsembleTestTheme(deviceTheme));

  // Skip re-initializing providers in EnsembleApp.initApp; bootstrapRuntime
  // already installed real providers and mock overlays.
  config.appBundle = null;
  await tester.pumpWidget(
    EnsembleApp(
      ensembleConfig: config,
      screenPayload: ScreenPayload(
        screenId: startScreen,
        arguments: testCase.startScreenInputs,
      ),
      forcedLocale: forcedLocale,
    ),
  );

  await waitForInitialWidgets(tester, testCase: testCase);
  final appliedTheme = applyDeviceThemeForTestCase(testCase);
  if (appliedTheme != null) {
    ctx.runtime.themeMode = appliedTheme;
    await tester.pump();
  }
  return config;
}