add_activity_test

 avatar
unknown
plain_text
12 hours ago
3.1 kB
2
Indexable
in 3 days
void main() {

  IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  setUp((){
    registerDbDependencies();
    GetIt.I.get<SqliteDatabaseHelper>().deleteDatabase();
    registerAllOtherDependencies();
  });

  tearDown((){
    GetIt.I.get<SqliteDatabaseHelper>().closeDatabase();
    GetIt.I.get<SqliteDatabaseHelper>().deleteDatabase();
    GetIt.I.reset();
  });
  group('end to end activity testing',
      (){
    testWidgets('verify adding activity shows on list',
            (tester) async {
      await tester.pumpWidget(app.MyApp(onBoarding: false));
      await tester.pumpAndSettle();
      await addActivity(tester, 'Test Activity', 'Test Tag');
            });

      });
}
extension on WidgetTester {
  Future<void> pumpUntil(
      Finder finder, {
        Duration timeout = const Duration(seconds: 10),
      }) async {
    bool timerDone = false;
    final timer = Timer(timeout, () => timerDone = true);
    while (!timerDone) {
      await pump();
      if (finder.evaluate().isNotEmpty) {
        timer.cancel();
        return;
      }
    }
    // If we reach here, the timeout was reached.
    fail('Timed out waiting for widget with finder: ${finder.description}');
  }
}

Future<void> addActivity(WidgetTester tester, String title, String tag) async {
  expect(find.byKey(const Key('listNeedPage')), findsOneWidget);
  await tester.tap(find.byKey(const Key('activityNavItem')));
  await tester.pumpAndSettle();
  expect(find.byKey(const Key('listActivityPage')), findsOneWidget);
  await tester.tap(find.byKey(const Key('list_activity_fab_key')));
  await tester.pumpAndSettle();
  expect(find.byKey(const Key('add_activity_page')), findsOneWidget);
  expect(find.byKey(const Key('add_activity_title')), findsOneWidget);
  expect(find.byKey(const Key('add_activity_description')), findsOneWidget);
  expect(find.byKey(const Key('add_activity_tag_search_key')), findsOneWidget);
  await tester.enterText(find.byKey(const Key('add_activity_title')), title);
  await tester.enterText(find.byKey(const Key('add_activity_tag_search_key')), tag);
  await tester.pumpAndSettle();
  expect(find.byKey(const Key('add_activity_suffix_icon')), findsOneWidget);
  await tester.tap(find.byKey(const Key('add_activity_suffix_icon')));
  await tester.pumpAndSettle();
  expect(find.byKey(const Key('Test Tag_tag_remove_button')), findsOneWidget,
      reason: 'either the copyWith method is not working, or the initial tags are not being used '
          'from model to display'
  );
  await tester.pumpAndSettle();
  expect(find.byKey(const Key('add_activity_save_button')), findsOneWidget);
  await tester.tap(find.byKey(const Key('add_activity_save_button')));
  await tester.pumpUntil(
    find.byKey(const Key('Test Activity_list_activity_list_item_title')),
    timeout: const Duration(seconds: 10), // Set a reasonable timeout
  );
  await tester.pumpAndSettle();
  expect(find.byKey(const Key('listActivityPage')), findsOneWidget);
  expect(find.byKey(const Key('Test Activity_list_activity_list_item_title')), findsOneWidget);

}
Editor is loading...
Leave a Comment