Skip to content

Commit

Permalink
Merge pull request #394 from rohansen856/routes_test
Browse files Browse the repository at this point in the history
tests: added tests for files under lib/routes folder
  • Loading branch information
BrawlerXull authored Dec 12, 2024
2 parents 6512b65 + c0614a4 commit f474487
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 0 deletions.
109 changes: 109 additions & 0 deletions test/routes/app_pages_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:taskwarrior/app/modules/about/bindings/about_binding.dart';
import 'package:taskwarrior/app/modules/about/views/about_view.dart';
import 'package:taskwarrior/app/modules/home/bindings/home_binding.dart';
import 'package:taskwarrior/app/modules/splash/bindings/splash_binding.dart';

import 'package:taskwarrior/app/routes/app_pages.dart';
import 'package:taskwarrior/app/modules/home/views/home_view.dart';
import 'package:taskwarrior/app/modules/splash/views/splash_view.dart';

import 'package:taskwarrior/app/modules/detailRoute/views/detail_route_view.dart';
import 'package:taskwarrior/app/modules/detailRoute/bindings/detail_route_binding.dart';
import 'package:taskwarrior/app/modules/manageTaskServer/views/manage_task_server_view.dart';
import 'package:taskwarrior/app/modules/manageTaskServer/bindings/manage_task_server_binding.dart';
import 'package:taskwarrior/app/modules/onboarding/views/onboarding_view.dart';
import 'package:taskwarrior/app/modules/onboarding/bindings/onboarding_binding.dart';
import 'package:taskwarrior/app/modules/profile/views/profile_view.dart';
import 'package:taskwarrior/app/modules/profile/bindings/profile_binding.dart';
import 'package:taskwarrior/app/modules/reports/views/reports_view.dart';
import 'package:taskwarrior/app/modules/reports/bindings/reports_binding.dart';
import 'package:taskwarrior/app/modules/settings/views/settings_view.dart';
import 'package:taskwarrior/app/modules/settings/bindings/settings_binding.dart';

void main() {
group('AppPages Test', () {
test('Initial route is correct', () {
expect(AppPages.INITIAL, Routes.SPLASH);
});

test('All routes should be defined correctly', () {
final routes = AppPages.routes;

expect(routes.length, 9);

expect(
routes.any((route) =>
route.name == Routes.HOME &&
route.page() is HomeView &&
route.binding is HomeBinding),
true,
);
expect(
routes.any((route) =>
route.name == Routes.SPLASH &&
route.page() is SplashView &&
route.binding is SplashBinding),
true,
);
expect(
routes.any((route) =>
route.name == Routes.ABOUT &&
route.page() is AboutView &&
route.binding is AboutBinding),
true,
);
expect(
routes.any((route) =>
route.name == Routes.DETAIL_ROUTE &&
route.page() is DetailRouteView &&
route.binding is DetailRouteBinding),
true,
);
expect(
routes.any((route) =>
route.name == Routes.MANAGE_TASK_SERVER &&
route.page() is ManageTaskServerView &&
route.binding is ManageTaskServerBinding),
true,
);
expect(
routes.any((route) =>
route.name == Routes.ONBOARDING &&
route.page() is OnboardingView &&
route.binding is OnboardingBinding),
true,
);
expect(
routes.any((route) =>
route.name == Routes.PROFILE &&
route.page() is ProfileView &&
route.binding is ProfileBinding),
true,
);
expect(
routes.any((route) =>
route.name == Routes.REPORTS &&
route.page() is ReportsView &&
route.binding is ReportsBinding),
true,
);
expect(
routes.any((route) =>
route.name == Routes.SETTINGS &&
route.page() is SettingsView &&
route.binding is SettingsBinding),
true,
);
});

test('All routes are accessible without crashing', () {
final routes = AppPages.routes;

for (var route in routes) {
expect(() => route.page(), returnsNormally,
reason: 'Route ${route.name} should not throw errors');
}
});
});
}
16 changes: 16 additions & 0 deletions test/routes/app_routes_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:taskwarrior/app/routes/app_pages.dart';

void main() {
test('Routes should be defined correctly', () {
expect(Routes.HOME, '/home');
expect(Routes.ONBOARDING, '/onboarding');
expect(Routes.SPLASH, '/splash');
expect(Routes.MANAGE_TASK_SERVER, '/manage-task-server');
expect(Routes.DETAIL_ROUTE, '/detail-route');
expect(Routes.PROFILE, '/profile');
expect(Routes.ABOUT, '/about');
expect(Routes.REPORTS, '/reports');
expect(Routes.SETTINGS, '/settings');
});
}

0 comments on commit f474487

Please sign in to comment.