ensureLabEnabled method

Future<void> ensureLabEnabled(
  1. dynamic feat
)

Implementation

Future<void> ensureLabEnabled(LabsFeature feat) async {
  if (!rootNavKey.currentContext!.read(isActiveProvider(feat))) {
    // ensure we do actually have access to the main nav.
    await find.byKey(Keys.mainNav).should(findsOneWidget);
    final quickJumpKey = find.byKey(MainNavKeys.quickJump);
    await quickJumpKey.should(findsOneWidget);
    await quickJumpKey.tap();

    final profileKey = find.byKey(QuickJumpKeys.settings);
    await profileKey.should(findsOneWidget);
    await profileKey.tap();

    final labsKey = find.byKey(SettingsMenu.labs);
    await labsKey.should(findsOneWidget);
    await labsKey.tap();

    final confirmKey = find.byKey(Key('labs-${feat.name}'));
    await confirmKey.should(findsOneWidget);
    // let's read again
    if (!rootNavKey.currentContext!.read(isActiveProvider(feat))) {
      await confirmKey.tap();
    }

    await tester.pump(const Duration(seconds: 1));

    // ensure we are active
    assert(
      rootNavKey.currentContext!.read(isActiveProvider(feat)),
      'Could not activate $feat',
    );
  }
  // either way, go to home.
  await find.byKey(Keys.mainNav).should(findsOneWidget);
  final homeKey = find.byKey(MainNavKeys.dashboardHome);
  await homeKey.should(findsOneWidget);
  await homeKey.tap();
}