part of 'app_test.dart';

class ModularizationTest {
  static Future containLicense() async {
    patrolWidgetTest(
        'Os modulos de licença está sendo processados? (MultiLocais)',
        (PatrolTester tester) async {
      $ = tester;
      $.tester.printToConsole(
          'Modularization Test - Os modulos de licença está sendo processados?');

      await _loggedWithMultiLocalsAccount();
      await $.pumpWidgetAndSettle(const App());
      await $.waitUntilVisible($(MenuStaggeredView));

      final LicenseRepository licenseRepository = LicenseRepositoryImpl();
      final List<String> result = await licenseRepository.getLicense();
      expect(result, isNotEmpty);

      await $.pumpAndSettle();

      final List<MenuEntry> entries = MenuEntry.entries;
      final List<String> entriesKey = entries
          .where((entry) => entry.types.contains(MenuEntryType.Home))
          .map((entry) => '{key: ${entry.key}}')
          .toList();
      expect(result, containsAll(entriesKey));

      return;
    });
    patrolWidgetTest(
        'Os modulos de licença está sendo processados? (MonoLocal)',
        (PatrolTester tester) async {
      $ = tester;
      $.tester.printToConsole(
          'Modularization Test - Os modulos de licença está sendo processados?');

      await _loggedWithSomeoneLocalAccount();
      await $.pumpWidgetAndSettle(const App());
      await $.waitUntilVisible($(MenuStaggeredView));

      final LicenseRepository licenseRepository = LicenseRepositoryImpl();
      final List<String> result = await licenseRepository.getLicense();
      expect(result, isNotEmpty);

      await $.pumpAndSettle();

      final List<MenuEntry> entries = MenuEntry.entries;
      final List<String> entriesKey = entries
          .where((entry) => entry.types.contains(MenuEntryType.Home))
          .map((entry) => '{key: ${entry.key}}')
          .toList();
      expect(result, containsAll(entriesKey));

      return;
    });
  }

  static Future switchLicense() async {
    patrolWidgetTest(
      'Licença está sendo atualizada?',
      (PatrolTester tester) async {
        $ = tester;
        $.tester.printToConsole('Licença está sendo atualizada?');

        await _loggedWithMultiLocalsAccount();

        await $.pumpWidgetAndSettle(const App());
        await $.waitUntilVisible($(MenuStaggeredView));

        final PatrolFinder profile =
            $(const Key('AsyncLocalProfileComponentWidget_InkWell'));
        await $(profile)
            .waitUntilVisible()
            .tap(settlePolicy: SettlePolicy.noSettle);
        await $.waitUntilVisible($(BottomArrowLinkedLocalsComponentWidget));

        final PatrolFinder local = $('FRE ACCESS DEMO');
        await $(local)
            .waitUntilVisible()
            .tap(settlePolicy: SettlePolicy.trySettle);
      },
    );
  }
}
