From 0e823a181ca6a5b5a775517bca06e3bb3c14df58 Mon Sep 17 00:00:00 2001 From: Antoine Martineau <47289926+Udito3@users.noreply.github.com> Date: Mon, 12 Feb 2024 09:38:24 -0500 Subject: [PATCH] =?UTF-8?q?Ajouter=20un=20skeleton=20pendant=20le=20charge?= =?UTF-8?q?ment=20des=20nouvelles=20dans=20=C3=89TSMobile=20(#927)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * WIP * Skeleton * Fixing tests WIP * Fix test * Skeleton test * Clean imports * [BOT] Applying version. * [BOT] Applying format. * Added nbSkeleton --------- Co-authored-by: Udito3 Co-authored-by: clubapplets-server --- lib/core/managers/course_repository.dart | 41 ++- lib/core/managers/news_repository.dart | 32 +- lib/core/managers/settings_manager.dart | 9 +- lib/core/managers/user_repository.dart | 21 +- lib/core/models/feedback_issue.dart | 2 +- lib/core/services/analytics_service.dart | 3 +- lib/core/services/navigation_service.dart | 16 +- lib/core/services/preferences_service.dart | 2 +- lib/core/viewmodels/dashboard_viewmodel.dart | 36 +- lib/core/viewmodels/feedback_viewmodel.dart | 3 +- .../viewmodels/grades_details_viewmodel.dart | 2 +- lib/core/viewmodels/grades_viewmodel.dart | 2 +- lib/core/viewmodels/login_viewmodel.dart | 6 +- lib/core/viewmodels/more_viewmodel.dart | 2 +- lib/core/viewmodels/news_viewmodel.dart | 14 +- lib/core/viewmodels/not_found_viewmodel.dart | 2 +- .../schedule_settings_viewmodel.dart | 9 +- lib/core/viewmodels/schedule_viewmodel.dart | 15 +- lib/core/viewmodels/settings_viewmodel.dart | 2 +- lib/locator.dart | 2 +- lib/ui/router.dart | 4 +- lib/ui/utils/discovery_components.dart | 23 +- lib/ui/views/contributors_view.dart | 7 +- lib/ui/views/dashboard_view.dart | 16 +- lib/ui/views/emergency_view.dart | 4 +- lib/ui/views/ets_view.dart | 6 +- lib/ui/views/faq_view.dart | 4 +- lib/ui/views/feedback_view.dart | 40 +-- lib/ui/views/grade_details_view.dart | 28 +- lib/ui/views/grades_view.dart | 3 +- lib/ui/views/login_view.dart | 8 +- lib/ui/views/more_view.dart | 4 +- lib/ui/views/news_view.dart | 46 ++- lib/ui/views/not_found_view.dart | 4 +- lib/ui/views/outage_view.dart | 6 +- lib/ui/views/profile_view.dart | 8 +- lib/ui/views/quick_links_view.dart | 8 - lib/ui/widgets/base_scaffold.dart | 2 +- lib/ui/widgets/grade_button.dart | 7 +- lib/ui/widgets/grade_circular_progress.dart | 4 +- lib/ui/widgets/grade_evaluation_tile.dart | 4 +- lib/ui/widgets/grade_not_available.dart | 4 +- lib/ui/widgets/news_card.dart | 82 ++++- lib/ui/widgets/news_card_skeleton.dart | 98 +++++ lib/ui/widgets/password_text_field.dart | 3 +- lib/ui/widgets/scaffold_safe_area.dart | 4 +- lib/ui/widgets/schedule_settings.dart | 3 +- pubspec.lock | 7 + pubspec.yaml | 3 +- test/helpers.dart | 2 +- test/managers/course_repository_test.dart | 207 +++++------ test/managers/news_repository_test.dart | 16 +- test/managers/quick_link_repository_test.dart | 8 +- test/managers/settings_manager_test.dart | 102 +++--- test/managers/user_repository_test.dart | 134 +++---- test/mock/managers/cache_manager_mock.dart | 1 - .../mock/managers/course_repository_mock.dart | 23 +- test/mock/managers/news_repository_mock.dart | 27 +- .../managers/quick_links_repository_mock.dart | 1 - test/mock/managers/settings_manager_mock.dart | 6 +- test/mock/managers/user_repository_mock.dart | 1 - .../mock/services/analytics_service_mock.dart | 1 - .../services/app_widget_service_mock.dart | 1 - .../services/flutter_secure_storage_mock.dart | 1 + test/mock/services/github_api_mock.dart | 9 +- test/mock/services/home_widget_mock.dart | 1 - .../services/in_app_review_service_mock.dart | 1 - .../services/internal_info_service_mock.dart | 1 - .../services/launch_url_service_mock.dart | 1 - .../services/navigation_service_mock.dart | 1 - .../services/networking_service_mock.dart | 1 - .../services/preferences_service_mock.dart | 1 - .../services/remote_config_service_mock.dart | 1 - .../services/rive_animation_service_mock.dart | 1 - .../services/siren_flutter_service_mock.dart | 1 - test/models/news_test.dart | 50 +-- test/services/app_widget_service_test.dart | 2 +- test/ui/views/dashboard_view_test.dart | 280 +++++++-------- test/ui/views/ets_view_test.dart | 27 +- test/ui/views/faq_view_test.dart | 4 +- test/ui/views/goldenFiles/etsView_1.png | Bin 0 -> 3378 bytes test/ui/views/goldenFiles/newsView_1.png | Bin 0 -> 1534 bytes test/ui/views/goldenFiles/newsView_2.png | Bin 0 -> 2461 bytes test/ui/views/grades_details_view_test.dart | 12 +- test/ui/views/grades_view_test.dart | 42 +-- test/ui/views/more_view_test.dart | 9 +- test/ui/views/news_view_test.dart | 29 +- test/ui/views/not_found_view_test.dart | 5 +- test/ui/views/profile_view_test.dart | 3 +- test/ui/views/quick_links_view_test.dart | 3 +- test/ui/views/schedule_view_test.dart | 133 +++---- test/ui/views/student_view_test.dart | 9 +- test/ui/widgets/bottom_bar_test.dart | 10 +- test/ui/widgets/grade_button_test.dart | 33 +- .../widgets/grade_evaluation_tile_test.dart | 6 +- test/ui/widgets/news_card_test.dart | 17 +- test/ui/widgets/news_skeleton_test.dart | 21 ++ test/ui/widgets/password_text_field_test.dart | 9 +- test/ui/widgets/schedule_settings_test.dart | 50 +-- .../choose_language_viewmodel_test.dart | 6 +- test/viewmodels/dashboard_viewmodel_test.dart | 339 ++++++------------ test/viewmodels/feedback_viewmodel_test.dart | 3 +- .../grades_details_viewmodel_test.dart | 2 +- test/viewmodels/grades_viewmodel_test.dart | 66 ++-- test/viewmodels/login_viewmodel_test.dart | 4 +- test/viewmodels/more_viewmodel_test.dart | 3 +- test/viewmodels/news_viewmodel_test.dart | 77 ++-- test/viewmodels/not_found_viewmodel_test.dart | 15 +- test/viewmodels/profile_viewmodel_test.dart | 30 +- .../schedule_settings_viewmodel_test.dart | 56 ++- test/viewmodels/schedule_viewmodel_test.dart | 138 +++---- test/viewmodels/settings_viewmodel_test.dart | 3 +- test/viewmodels/startup_viewmodel_test.dart | 9 +- .../web_link_card_viewmodel_test.dart | 8 +- 114 files changed, 1237 insertions(+), 1487 deletions(-) create mode 100644 lib/ui/widgets/news_card_skeleton.dart create mode 100644 test/ui/views/goldenFiles/etsView_1.png create mode 100644 test/ui/views/goldenFiles/newsView_1.png create mode 100644 test/ui/views/goldenFiles/newsView_2.png create mode 100644 test/ui/widgets/news_skeleton_test.dart diff --git a/lib/core/managers/course_repository.dart b/lib/core/managers/course_repository.dart index cf963dd6b..9b747ab3f 100644 --- a/lib/core/managers/course_repository.dart +++ b/lib/core/managers/course_repository.dart @@ -128,7 +128,7 @@ class CourseRepository { await getSessions(); } - if(_userRepository.monETSUser != null) { + if (_userRepository.monETSUser != null) { final String password = await _userRepository.getPassword(); for (final Session session in activeSessions) { fetchedCoursesActivities.addAll( @@ -159,7 +159,8 @@ class CourseRepository { // Update the list of activities to avoid duplicate activities for (final CourseActivity activity in fetchedCoursesActivities) { - if (_coursesActivities != null && !_coursesActivities!.contains(activity)) { + if (_coursesActivities != null && + !_coursesActivities!.contains(activity)) { _coursesActivities!.add(activity); } } @@ -220,7 +221,7 @@ class CourseRepository { await getSessions(); } - if(_userRepository.monETSUser != null) { + if (_userRepository.monETSUser != null) { final String password = await _userRepository.getPassword(); for (final Session session in activeSessions) { @@ -243,7 +244,8 @@ class CourseRepository { // Update the list of activities to avoid duplicate activities for (final ScheduleActivity activity in fetchedScheduleActivities) { - if (_scheduleActivities != null && !_scheduleActivities!.contains(activity)) { + if (_scheduleActivities != null && + !_scheduleActivities!.contains(activity)) { _scheduleActivities!.add(activity); } } @@ -290,15 +292,16 @@ class CourseRepository { } try { - if(_userRepository.monETSUser != null) { + if (_userRepository.monETSUser != null) { // getPassword will try to authenticate the user if not authenticated. final String password = await _userRepository.getPassword(); - final List fetchedSession = await _signetsApiClient.getSessions( - username: _userRepository.monETSUser!.universalCode, - password: password); - _logger - .d("$tag - getSessions: ${fetchedSession.length} sessions fetched."); + final List fetchedSession = + await _signetsApiClient.getSessions( + username: _userRepository.monETSUser!.universalCode, + password: password); + _logger.d( + "$tag - getSessions: ${fetchedSession.length} sessions fetched."); for (final Session session in fetchedSession) { if (!_sessions!.contains(session)) { _sessions!.add(session); @@ -358,13 +361,14 @@ class CourseRepository { final Map> fetchedCourseReviews = {}; try { - if(_userRepository.monETSUser != null) { + if (_userRepository.monETSUser != null) { final String password = await _userRepository.getPassword(); fetchedCourses.addAll(await _signetsApiClient.getCourses( username: _userRepository.monETSUser!.universalCode, password: password)); - _logger.d("$tag - getCourses: fetched ${fetchedCourses.length} courses."); + _logger + .d("$tag - getCourses: fetched ${fetchedCourses.length} courses."); } } on Exception catch (e, stacktrace) { _analyticsService.logError( @@ -423,14 +427,15 @@ class CourseRepository { } try { - if(_userRepository.monETSUser != null) { + if (_userRepository.monETSUser != null) { final String password = await _userRepository.getPassword(); summary = await _signetsApiClient.getCourseSummary( username: _userRepository.monETSUser!.universalCode, password: password, course: course); - _logger.d("$tag - getCourseSummary: fetched ${course.acronym} summary."); + _logger + .d("$tag - getCourseSummary: fetched ${course.acronym} summary."); } } on Exception catch (e, stacktrace) { if (e is ApiException) { @@ -481,7 +486,7 @@ class CourseRepository { await getSessions(); } - if(_userRepository.monETSUser != null) { + if (_userRepository.monETSUser != null) { for (final Session session in _sessions!) { sessionReviews = await _signetsApiClient.getCourseReviews( username: _userRepository.monETSUser!.universalCode, @@ -506,10 +511,8 @@ class CourseRepository { CourseReview? _getReviewForCourse( Course course, Map> reviews) { if (reviews.containsKey(course.session)) { - return reviews[course.session]!.firstWhere( - (element) => - element.acronym == course.acronym && - element.group == course.group); + return reviews[course.session]!.firstWhere((element) => + element.acronym == course.acronym && element.group == course.group); } return null; } diff --git a/lib/core/managers/news_repository.dart b/lib/core/managers/news_repository.dart index 72ae55d79..2bcfcb5d8 100644 --- a/lib/core/managers/news_repository.dart +++ b/lib/core/managers/news_repository.dart @@ -1,19 +1,17 @@ -// FLUTTER / DART / THIRD-PARTIES +// Dart imports: import 'dart:convert'; + +// Flutter imports: import 'package:flutter/material.dart'; + +// Package imports: import 'package:logger/logger.dart'; -// SERVICES -import 'package:notredame/core/services/networking_service.dart'; +// Project imports: import 'package:notredame/core/managers/cache_manager.dart'; - -// MODELS import 'package:notredame/core/models/news.dart'; - -// UTILS +import 'package:notredame/core/services/networking_service.dart'; import 'package:notredame/core/utils/cache_exception.dart'; - -// OTHER import 'package:notredame/locator.dart'; /// Repository to access all the news @@ -32,7 +30,7 @@ class NewsRepository { final NetworkingService _networkingService = locator(); /// List of the news with 3 test news. - List _news = [ + List? _news = [ News( id: 1, title: @@ -60,12 +58,12 @@ class NewsRepository { ), ]; - List get news => _news; + List? get news => _news; /// Get and update the list of news. /// After fetching the news from the [?] the [CacheManager] /// is updated with the latest version of the news. - Future> getNews({bool fromCacheOnly = false}) async { + Future?> getNews({bool fromCacheOnly = false}) async { // Force fromCacheOnly mode when user has no connectivity if (!(await _networkingService.hasConnectivity())) { // ignore: parameter_assignments @@ -83,10 +81,12 @@ class NewsRepository { final List fetchedNews = fetchNewsFromAPI(); + _news ??= []; + // Update the list of news to avoid duplicate news for (final News news in fetchedNews) { - if (!_news.contains(news)) { - _news.add(news); + if (_news?.contains(news) ?? false) { + _news?.add(news); } } @@ -113,8 +113,8 @@ class NewsRepository { .map((e) => News.fromJson(e as Map)) .toList(); - _logger - .d("$tag - getNewsFromCache: ${_news.length} news loaded from cache"); + _logger.d( + "$tag - getNewsFromCache: ${_news?.length} news loaded from cache"); } on CacheException catch (_) { _logger.e( "$tag - getNewsFromCache: exception raised will trying to load news from cache."); diff --git a/lib/core/managers/settings_manager.dart b/lib/core/managers/settings_manager.dart index 035ebd8bb..f414c1d42 100644 --- a/lib/core/managers/settings_manager.dart +++ b/lib/core/managers/settings_manager.dart @@ -151,8 +151,9 @@ class SettingsManager with ChangeNotifier { "${tag}_${EnumToString.convertToString(PreferencesFlag.locale)}", _locale?.languageCode ?? 'Not found'); - if(_locale != null) { - _preferencesService.setString(PreferencesFlag.locale, _locale!.languageCode); + if (_locale != null) { + _preferencesService.setString( + PreferencesFlag.locale, _locale!.languageCode); _locale = Locale(_locale!.languageCode); notifyListeners(); } @@ -166,8 +167,8 @@ class SettingsManager with ChangeNotifier { .getString(PreferencesFlag.scheduleCalendarFormat) .then((value) => value == null ? CalendarFormat.week - : EnumToString.fromString(CalendarFormat.values, value) - ?? CalendarFormat.week); + : EnumToString.fromString(CalendarFormat.values, value) ?? + CalendarFormat.week); settings.putIfAbsent( PreferencesFlag.scheduleCalendarFormat, () => calendarFormat); diff --git a/lib/core/managers/user_repository.dart b/lib/core/managers/user_repository.dart index f0da6fcf8..a4eae1e80 100644 --- a/lib/core/managers/user_repository.dart +++ b/lib/core/managers/user_repository.dart @@ -133,11 +133,10 @@ class UserRepository { final username = await _secureStorage.read(key: usernameSecureKey); if (username != null) { final password = await _secureStorage.read(key: passwordSecureKey); - if(password == null) { + if (password == null) { await _secureStorage.deleteAll(); - _analyticsService.logError( - tag, - "SilentAuthenticate - PlatformException(Handled) - $passwordSecureKey not found"); + _analyticsService.logError(tag, + "SilentAuthenticate - PlatformException(Handled) - $passwordSecureKey not found"); return false; } return await authenticate( @@ -185,7 +184,7 @@ class UserRepository { } try { final password = await _secureStorage.read(key: passwordSecureKey); - if(password == null) { + if (password == null) { throw const ApiException(prefix: tag, message: "Not authenticated"); } return password; @@ -236,10 +235,10 @@ class UserRepository { // getPassword will try to authenticate the user if not authenticated. final String password = await getPassword(); - if(_monETSUser != null) { + if (_monETSUser != null) { _programs = await _signetsApiClient.getPrograms( - username: _monETSUser!.universalCode, password: password); - + username: _monETSUser!.universalCode, password: password); + _logger.d("$tag - getPrograms: ${_programs!.length} programs fetched."); // Update cache @@ -291,7 +290,7 @@ class UserRepository { // getPassword will try to authenticate the user if not authenticated. final String password = await getPassword(); - if(_monETSUser != null) { + if (_monETSUser != null) { final fetchedInfo = await _signetsApiClient.getStudentInfo( username: _monETSUser!.universalCode, password: password); @@ -304,7 +303,6 @@ class UserRepository { _cacheManager.update(infoCacheKey, jsonEncode(_info)); } } - } on CacheException catch (_) { _logger.e( "$tag - getInfo: exception raised while trying to update the cache."); @@ -323,8 +321,7 @@ class UserRepository { try { final username = await _secureStorage.read(key: passwordSecureKey); if (username != null) { - final password = - await _secureStorage.read(key: passwordSecureKey); + final password = await _secureStorage.read(key: passwordSecureKey); return password != null && password.isNotEmpty; } } on PlatformException catch (e, stacktrace) { diff --git a/lib/core/models/feedback_issue.dart b/lib/core/models/feedback_issue.dart index 88d673b85..4ac56dc7f 100644 --- a/lib/core/models/feedback_issue.dart +++ b/lib/core/models/feedback_issue.dart @@ -9,7 +9,7 @@ class FeedbackIssue { late bool isOpen; late int number; late String createdAt; - + // Constructor FeedbackIssue(Issue issue) { id = issue.id; diff --git a/lib/core/services/analytics_service.dart b/lib/core/services/analytics_service.dart index 3ca534b4a..a9adea0bf 100644 --- a/lib/core/services/analytics_service.dart +++ b/lib/core/services/analytics_service.dart @@ -35,7 +35,8 @@ class AnalyticsService { } /// Set user properties to identify the user against firebase app. - Future setUserProperties({required String userId, required String domain}) async { + Future setUserProperties( + {required String userId, required String domain}) async { await _analytics.setUserId(id: userId); await _analytics.setUserProperty( name: _userPropertiesDomainKey, value: domain); diff --git a/lib/core/services/navigation_service.dart b/lib/core/services/navigation_service.dart index 1119fe311..a9e12f7c2 100644 --- a/lib/core/services/navigation_service.dart +++ b/lib/core/services/navigation_service.dart @@ -35,16 +35,15 @@ class NavigationService { Future pushNamed(String routeName, {dynamic arguments}) { final currentState = _navigatorKey.currentState; - if(currentState == null) { + if (currentState == null) { return Future.error("Navigator state is null"); } if (remoteConfigService.outage) { - return currentState - .pushNamedAndRemoveUntil(RouterPaths.serviceOutage, (route) => false); + return currentState.pushNamedAndRemoveUntil( + RouterPaths.serviceOutage, (route) => false); } - return currentState - .pushNamed(routeName, arguments: arguments); + return currentState.pushNamed(routeName, arguments: arguments); } /// Replace the current route of the navigator by pushing the route named @@ -52,15 +51,14 @@ class NavigationService { Future pushNamedAndRemoveUntil(String routeName, [String removeUntilRouteNamed = RouterPaths.dashboard, Object? arguments]) { - final currentState = _navigatorKey.currentState; - if(currentState == null) { + if (currentState == null) { return Future.error("Navigator state is null"); } if (remoteConfigService.outage) { - return currentState - .pushNamedAndRemoveUntil(RouterPaths.serviceOutage, (route) => false); + return currentState.pushNamedAndRemoveUntil( + RouterPaths.serviceOutage, (route) => false); } return currentState.pushNamedAndRemoveUntil( routeName, ModalRoute.withName(removeUntilRouteNamed), diff --git a/lib/core/services/preferences_service.dart b/lib/core/services/preferences_service.dart index 592d2f3fe..6320bfd94 100644 --- a/lib/core/services/preferences_service.dart +++ b/lib/core/services/preferences_service.dart @@ -126,7 +126,7 @@ class PreferencesService { final SharedPreferences prefs = await SharedPreferences.getInstance(); final flagPreference = prefs.getString(flag.toString()); - if(flagPreference != null) { + if (flagPreference != null) { return DateTime.parse(flagPreference); } diff --git a/lib/core/viewmodels/dashboard_viewmodel.dart b/lib/core/viewmodels/dashboard_viewmodel.dart index 45b57076b..0bcb01411 100644 --- a/lib/core/viewmodels/dashboard_viewmodel.dart +++ b/lib/core/viewmodels/dashboard_viewmodel.dart @@ -9,15 +9,13 @@ import 'package:ets_api_clients/models.dart'; import 'package:feature_discovery/feature_discovery.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:fluttertoast/fluttertoast.dart'; -import 'package:notredame/core/constants/router_paths.dart'; -import 'package:notredame/core/services/launch_url_service.dart'; -import 'package:notredame/core/services/navigation_service.dart'; import 'package:stacked/stacked.dart'; // Project imports: import 'package:notredame/core/constants/discovery_ids.dart'; import 'package:notredame/core/constants/preferences_flags.dart'; import 'package:notredame/core/constants/progress_bar_text_options.dart'; +import 'package:notredame/core/constants/router_paths.dart'; import 'package:notredame/core/constants/update_code.dart'; import 'package:notredame/core/constants/widget_helper.dart'; import 'package:notredame/core/managers/course_repository.dart'; @@ -26,6 +24,8 @@ import 'package:notredame/core/models/widget_models.dart'; import 'package:notredame/core/services/analytics_service.dart'; import 'package:notredame/core/services/app_widget_service.dart'; import 'package:notredame/core/services/in_app_review_service.dart'; +import 'package:notredame/core/services/launch_url_service.dart'; +import 'package:notredame/core/services/navigation_service.dart'; import 'package:notredame/core/services/preferences_service.dart'; import 'package:notredame/core/services/remote_config_service.dart'; import 'package:notredame/core/services/siren_flutter_service.dart'; @@ -254,9 +254,10 @@ class DashboardViewModel extends FutureViewModel> { return course.grade!; } else if (course.summary != null && course.summary!.markOutOf > 0 && - !(course.inReviewPeriod && (course.reviewCompleted != null && !course.reviewCompleted!))) { + !(course.inReviewPeriod && + (course.reviewCompleted != null && !course.reviewCompleted!))) { return _appIntl.grades_grade_in_percentage( - course.summary!.currentMarkInPercent.round()); + course.summary!.currentMarkInPercent.round()); } return _appIntl.grades_not_available; }).toList(); @@ -351,9 +352,7 @@ class DashboardViewModel extends FutureViewModel> { remoteConfigService.dashboardMessageEn); if (_cards != null && _cards![PreferencesFlag.broadcastCard]! < 0) { _cards?.updateAll((key, value) { - return value >= 0 - ? value + 1 - : value; + return value >= 0 ? value + 1 : value; }); _cards![PreferencesFlag.broadcastCard] = 0; } @@ -362,8 +361,8 @@ class DashboardViewModel extends FutureViewModel> { Future> futureToRunSessionProgressBar() async { final progressBarText = - await _settingsManager.getString(PreferencesFlag.progressBarText) - ?? ProgressBarText.daysElapsedWithTotalDays.toString(); + await _settingsManager.getString(PreferencesFlag.progressBarText) ?? + ProgressBarText.daysElapsedWithTotalDays.toString(); _currentProgressBarText = ProgressBarText.values .firstWhere((e) => e.toString() == progressBarText); @@ -395,7 +394,8 @@ class DashboardViewModel extends FutureViewModel> { // ignore: return_type_invalid_for_catch_error .catchError(onError) .whenComplete(() async { - if (_todayDateEvents.isEmpty && _courseRepository.coursesActivities != null) { + if (_todayDateEvents.isEmpty && + _courseRepository.coursesActivities != null) { final DateTime tomorrowDate = todayDate.add(const Duration(days: 1)); // Build the list for (final CourseActivity course @@ -451,7 +451,7 @@ class DashboardViewModel extends FutureViewModel> { /// Update cards order and display status in preferences void updatePreferences() { - if(_cards == null || _cardsToDisplay == null) { + if (_cards == null || _cardsToDisplay == null) { return; } for (final MapEntry element in _cards!.entries) { @@ -520,13 +520,13 @@ class DashboardViewModel extends FutureViewModel> { notifyListeners(); // ignore: return_type_invalid_for_catch_error _courseRepository.getCourses().catchError(onError).then((value) { - // Update the courses list - courses.clear(); - for (final Course course in value) { - if (course.session == currentSession.shortName) { - courses.add(course); - } + // Update the courses list + courses.clear(); + for (final Course course in value) { + if (course.session == currentSession.shortName) { + courses.add(course); } + } }).whenComplete(() { setBusyForObject(courses, false); }); diff --git a/lib/core/viewmodels/feedback_viewmodel.dart b/lib/core/viewmodels/feedback_viewmodel.dart index 94f16e438..279221e94 100644 --- a/lib/core/viewmodels/feedback_viewmodel.dart +++ b/lib/core/viewmodels/feedback_viewmodel.dart @@ -75,7 +75,8 @@ class FeedbackViewModel extends FutureViewModel { } List encodeScreenshotForGithub(Uint8List screenshot) { - return image.encodePng(image.copyResize(image.decodeImage(screenshot) ?? image.Image(0, 0), + return image.encodePng(image.copyResize( + image.decodeImage(screenshot) ?? image.Image(0, 0), width: _screenshotImageWidth)); } diff --git a/lib/core/viewmodels/grades_details_viewmodel.dart b/lib/core/viewmodels/grades_details_viewmodel.dart index ad17c6b39..89988a992 100644 --- a/lib/core/viewmodels/grades_details_viewmodel.dart +++ b/lib/core/viewmodels/grades_details_viewmodel.dart @@ -36,7 +36,7 @@ class GradesDetailsViewModel extends FutureViewModel { setBusyForObject(course, true); course = await _courseRepository.getCourseSummary(course); notifyListeners(); - } catch(e) { + } catch (e) { onError(e); } finally { setBusyForObject(course, false); diff --git a/lib/core/viewmodels/grades_viewmodel.dart b/lib/core/viewmodels/grades_viewmodel.dart index 635ad41e4..602fe657d 100644 --- a/lib/core/viewmodels/grades_viewmodel.dart +++ b/lib/core/viewmodels/grades_viewmodel.dart @@ -61,7 +61,7 @@ class GradesViewModel extends FutureViewModel>> { // ignore: return_type_invalid_for_catch_error try { await _courseRepository.getCourses(); - if(_courseRepository.courses != null) { + if (_courseRepository.courses != null) { _buildCoursesBySession(_courseRepository.courses!); } notifyListeners(); diff --git a/lib/core/viewmodels/login_viewmodel.dart b/lib/core/viewmodels/login_viewmodel.dart index e200a3365..12972eb08 100644 --- a/lib/core/viewmodels/login_viewmodel.dart +++ b/lib/core/viewmodels/login_viewmodel.dart @@ -1,9 +1,7 @@ -// Flutter imports: -import 'package:flutter_secure_storage/flutter_secure_storage.dart'; - // Package imports: -import 'package:stacked/stacked.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_secure_storage/flutter_secure_storage.dart'; +import 'package:stacked/stacked.dart'; // Project imports: import 'package:notredame/core/constants/preferences_flags.dart'; diff --git a/lib/core/viewmodels/more_viewmodel.dart b/lib/core/viewmodels/more_viewmodel.dart index 0be36a325..ea29c810e 100644 --- a/lib/core/viewmodels/more_viewmodel.dart +++ b/lib/core/viewmodels/more_viewmodel.dart @@ -5,7 +5,6 @@ import 'package:flutter/material.dart'; import 'package:feature_discovery/feature_discovery.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:fluttertoast/fluttertoast.dart'; -import 'package:notredame/core/services/launch_url_service.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:stacked/stacked.dart'; @@ -18,6 +17,7 @@ import 'package:notredame/core/managers/course_repository.dart'; import 'package:notredame/core/managers/settings_manager.dart'; import 'package:notredame/core/managers/user_repository.dart'; import 'package:notredame/core/services/in_app_review_service.dart'; +import 'package:notredame/core/services/launch_url_service.dart'; import 'package:notredame/core/services/navigation_service.dart'; import 'package:notredame/core/services/preferences_service.dart'; import 'package:notredame/core/services/remote_config_service.dart'; diff --git a/lib/core/viewmodels/news_viewmodel.dart b/lib/core/viewmodels/news_viewmodel.dart index 0db88a741..30544e7be 100644 --- a/lib/core/viewmodels/news_viewmodel.dart +++ b/lib/core/viewmodels/news_viewmodel.dart @@ -1,11 +1,11 @@ -// FLUTTER / DART / THIRD-PARTIES +// Package imports: +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:stacked/stacked.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +// Project imports: import 'package:notredame/core/managers/news_repository.dart'; import 'package:notredame/core/models/news.dart'; - import 'package:notredame/locator.dart'; class NewsViewModel extends FutureViewModel> { @@ -16,18 +16,16 @@ class NewsViewModel extends FutureViewModel> { final AppIntl _appIntl; /// News list - List _news = []; + List? _news = []; /// Return the list of all the news. List get news { _news = []; // Build the list of news - for (final n in _newsRepository.news) { - _news.add(n); - } + _news?.addAll(_newsRepository.news ?? []); - return _news; + return _news ?? []; } NewsViewModel({required AppIntl intl}) : _appIntl = intl; diff --git a/lib/core/viewmodels/not_found_viewmodel.dart b/lib/core/viewmodels/not_found_viewmodel.dart index c7068488f..98dc1c958 100644 --- a/lib/core/viewmodels/not_found_viewmodel.dart +++ b/lib/core/viewmodels/not_found_viewmodel.dart @@ -53,7 +53,7 @@ class NotFoundViewModel extends BaseViewModel { void startRiveAnimation() { try { - if(artboard != null) { + if (artboard != null) { _riveAnimationService.addControllerToAnimation(artboard: _artboard!); } } on Exception catch (e, stacktrace) { diff --git a/lib/core/viewmodels/schedule_settings_viewmodel.dart b/lib/core/viewmodels/schedule_settings_viewmodel.dart index 4ed525cfa..9f55ac077 100644 --- a/lib/core/viewmodels/schedule_settings_viewmodel.dart +++ b/lib/core/viewmodels/schedule_settings_viewmodel.dart @@ -1,8 +1,6 @@ -// Dart imports: -import 'package:collection/collection.dart'; - // Package imports: import 'package:calendar_view/calendar_view.dart'; +import 'package:collection/collection.dart'; import 'package:enum_to_string/enum_to_string.dart'; import 'package:ets_api_clients/models.dart'; import 'package:stacked/stacked.dart'; @@ -148,7 +146,7 @@ class ScheduleSettingsViewModel PreferencesFlag.scheduleLaboratoryGroup, courseAcronym, scheduleActivityToSave.activityCode); - _selectedScheduleActivity[courseAcronym] = scheduleActivityToSave; + _selectedScheduleActivity[courseAcronym] = scheduleActivityToSave; } setBusy(false); } @@ -191,7 +189,8 @@ class ScheduleSettingsViewModel final scheduleActivityCode = await _settingsManager.getDynamicString( PreferencesFlag.scheduleLaboratoryGroup, courseKey); final scheduleActivity = _scheduleActivitiesByCourse[courseKey] - ?.firstWhereOrNull((element) => element.activityCode == scheduleActivityCode); + ?.firstWhereOrNull( + (element) => element.activityCode == scheduleActivityCode); if (scheduleActivity != null) { _selectedScheduleActivity[courseKey] = scheduleActivity; } diff --git a/lib/core/viewmodels/schedule_viewmodel.dart b/lib/core/viewmodels/schedule_viewmodel.dart index 22c90f411..50a319b9f 100644 --- a/lib/core/viewmodels/schedule_viewmodel.dart +++ b/lib/core/viewmodels/schedule_viewmodel.dart @@ -176,11 +176,13 @@ class ScheduleViewModel extends FutureViewModel> { @override Future> futureToRun() async { - List? activities = await _courseRepository.getCoursesActivities(fromCacheOnly: true); + List? activities = + await _courseRepository.getCoursesActivities(fromCacheOnly: true); try { setBusyForObject(isLoadingEvents, true); - final fetchedCourseActivities = await _courseRepository.getCoursesActivities(); + final fetchedCourseActivities = + await _courseRepository.getCoursesActivities(); if (fetchedCourseActivities != null) { activities = fetchedCourseActivities; // Reload the list of activities @@ -196,9 +198,10 @@ class ScheduleViewModel extends FutureViewModel> { } } } - final scheduleActivities = await _courseRepository.getScheduleActivities(); + final scheduleActivities = + await _courseRepository.getScheduleActivities(); await assignScheduleActivities(scheduleActivities); - } catch(e) { + } catch (e) { onError(e); } finally { setBusyForObject(isLoadingEvents, false); @@ -206,7 +209,6 @@ class ScheduleViewModel extends FutureViewModel> { return activities ?? []; } - Future assignScheduleActivities( List listOfSchedules) async { if (listOfSchedules.isEmpty || @@ -273,7 +275,8 @@ class ScheduleViewModel extends FutureViewModel> { // Build the map if (_courseRepository.coursesActivities != null) { - for (final CourseActivity course in _courseRepository.coursesActivities!) { + for (final CourseActivity course + in _courseRepository.coursesActivities!) { final DateTime dateOnly = course.startDateTime.subtract(Duration( hours: course.startDateTime.hour, minutes: course.startDateTime.minute)); diff --git a/lib/core/viewmodels/settings_viewmodel.dart b/lib/core/viewmodels/settings_viewmodel.dart index 94e5fb740..6d01fbff1 100644 --- a/lib/core/viewmodels/settings_viewmodel.dart +++ b/lib/core/viewmodels/settings_viewmodel.dart @@ -26,7 +26,7 @@ class SettingsViewModel extends FutureViewModel { /// Set theme set selectedTheme(ThemeMode? value) { - if(value != null) { + if (value != null) { _settingsManager.setThemeMode(value); _selectedTheme = value; } diff --git a/lib/locator.dart b/lib/locator.dart index 20dc2fb74..3f2448107 100644 --- a/lib/locator.dart +++ b/lib/locator.dart @@ -7,6 +7,7 @@ import 'package:logger/logger.dart'; // Project imports: import 'package:notredame/core/managers/cache_manager.dart'; import 'package:notredame/core/managers/course_repository.dart'; +import 'package:notredame/core/managers/news_repository.dart'; import 'package:notredame/core/managers/quick_link_repository.dart'; import 'package:notredame/core/managers/settings_manager.dart'; import 'package:notredame/core/managers/user_repository.dart'; @@ -18,7 +19,6 @@ import 'package:notredame/core/services/internal_info_service.dart'; import 'package:notredame/core/services/launch_url_service.dart'; import 'package:notredame/core/services/navigation_service.dart'; import 'package:notredame/core/services/networking_service.dart'; -import 'package:notredame/core/managers/news_repository.dart'; import 'package:notredame/core/services/preferences_service.dart'; import 'package:notredame/core/services/remote_config_service.dart'; import 'package:notredame/core/services/rive_animation_service.dart'; diff --git a/lib/ui/router.dart b/lib/ui/router.dart index 5db6577e7..1aff16c30 100644 --- a/lib/ui/router.dart +++ b/lib/ui/router.dart @@ -12,13 +12,13 @@ import 'package:notredame/ui/views/about_view.dart'; import 'package:notredame/ui/views/choose_language_view.dart'; import 'package:notredame/ui/views/contributors_view.dart'; import 'package:notredame/ui/views/dashboard_view.dart'; -import 'package:notredame/ui/views/faq_view.dart'; import 'package:notredame/ui/views/ets_view.dart'; -import 'package:notredame/ui/views/news_view.dart'; +import 'package:notredame/ui/views/faq_view.dart'; import 'package:notredame/ui/views/feedback_view.dart'; import 'package:notredame/ui/views/grade_details_view.dart'; import 'package:notredame/ui/views/login_view.dart'; import 'package:notredame/ui/views/more_view.dart'; +import 'package:notredame/ui/views/news_view.dart'; import 'package:notredame/ui/views/not_found_view.dart'; import 'package:notredame/ui/views/outage_view.dart'; import 'package:notredame/ui/views/quick_links_view.dart'; diff --git a/lib/ui/utils/discovery_components.dart b/lib/ui/utils/discovery_components.dart index 5da5ecbbe..68a99f37e 100644 --- a/lib/ui/utils/discovery_components.dart +++ b/lib/ui/utils/discovery_components.dart @@ -27,14 +27,15 @@ List discoveryComponents(BuildContext context) { maxHeight: MediaQuery.of(context).size.height * 0.6), child: Column( children: [ - _buildHeader(AppIntl.of(context)!.discovery_navbar_dashboard_title, + _buildHeader( + AppIntl.of(context)!.discovery_navbar_dashboard_title, context), Expanded( child: ListView( padding: EdgeInsets.zero, children: [ - Text( - AppIntl.of(context)!.discovery_navbar_dashboard_details), + Text(AppIntl.of(context)! + .discovery_navbar_dashboard_details), const Text('\n'), if (AppIntl.of(context)!.localeName == "fr") Image.asset( @@ -89,8 +90,8 @@ List discoveryComponents(BuildContext context) { maxHeight: MediaQuery.of(context).size.height * 0.6), child: Column( children: [ - _buildHeader( - AppIntl.of(context)!.discovery_navbar_schedule_title, context), + _buildHeader(AppIntl.of(context)!.discovery_navbar_schedule_title, + context), Expanded( child: ListView( padding: EdgeInsets.zero, @@ -250,13 +251,13 @@ List discoveryComponents(BuildContext context) { children: [ _buildSkipDiscoveryButton(context), Text( - AppIntl.of(context) - !.discovery_page_student_grades_session, + AppIntl.of(context)! + .discovery_page_student_grades_session, textAlign: TextAlign.justify), const Text('\n'), Text( - AppIntl.of(context) - !.discovery_page_student_grades_grade_button, + AppIntl.of(context)! + .discovery_page_student_grades_grade_button, textAlign: TextAlign.justify), ], ), @@ -443,8 +444,8 @@ Padding _buildHeader(String title, BuildContext context) { Text(title, style: Theme.of(context) .textTheme - .headline6 - !.copyWith(color: Colors.white)), + .headline6! + .copyWith(color: Colors.white)), _buildSkipDiscoveryButton(context) ], ), diff --git a/lib/ui/views/contributors_view.dart b/lib/ui/views/contributors_view.dart index e93d26d38..1fcca95d5 100644 --- a/lib/ui/views/contributors_view.dart +++ b/lib/ui/views/contributors_view.dart @@ -34,10 +34,11 @@ class ContributorsView extends StatelessWidget { itemBuilder: (context, index) => ListTile( title: Text(snapshot.data![index].login ?? ''), leading: CircleAvatar( - backgroundImage: - NetworkImage(snapshot.data![index].avatarUrl ?? '')), + backgroundImage: NetworkImage( + snapshot.data![index].avatarUrl ?? '')), onTap: () => Utils.launchURL( - snapshot.data![index].htmlUrl ?? '', AppIntl.of(context)!), + snapshot.data![index].htmlUrl ?? '', + AppIntl.of(context)!), ), ); }, diff --git a/lib/ui/views/dashboard_view.dart b/lib/ui/views/dashboard_view.dart index 6ff34fbc7..77b66873e 100644 --- a/lib/ui/views/dashboard_view.dart +++ b/lib/ui/views/dashboard_view.dart @@ -158,7 +158,8 @@ class _DashboardViewState extends State IconButton( onPressed: () { _analyticsService.logEvent(tag, "Facebook clicked"); - Utils.launchURL(Urls.clubFacebook, AppIntl.of(context)!); + Utils.launchURL( + Urls.clubFacebook, AppIntl.of(context)!); }, icon: const FaIcon( FontAwesomeIcons.facebook, @@ -289,8 +290,8 @@ class _DashboardViewState extends State if (model.currentProgressBarText == ProgressBarText.daysElapsedWithTotalDays) { progressBarText = Text( - AppIntl.of(context) - !.progress_bar_message(model.sessionDays[0], model.sessionDays[1]), + AppIntl.of(context)! + .progress_bar_message(model.sessionDays[0], model.sessionDays[1]), style: const TextStyle(color: Colors.white), ); } else if (model.currentProgressBarText == ProgressBarText.percentage) { @@ -390,8 +391,8 @@ class _DashboardViewState extends State SizedBox( height: 100, child: Center( - child: Text(AppIntl.of(context) - !.grades_msg_no_grades + child: Text(AppIntl.of(context)! + .grades_msg_no_grades .split("\n") .first)), ) @@ -400,8 +401,7 @@ class _DashboardViewState extends State padding: const EdgeInsets.fromLTRB(17, 10, 15, 10), child: Wrap( children: model.courses - .map((course) => - GradeButton(course)) + .map((course) => GradeButton(course)) .toList(), ), ) @@ -492,7 +492,7 @@ class _DashboardViewState extends State } // Should not happen becase dismiss card will not be called if the card is null. - if(model.cards == null) { + if (model.cards == null) { throw Exception("Cards is null"); } diff --git a/lib/ui/views/emergency_view.dart b/lib/ui/views/emergency_view.dart index 005840382..da51d372c 100644 --- a/lib/ui/views/emergency_view.dart +++ b/lib/ui/views/emergency_view.dart @@ -49,8 +49,8 @@ class _EmergencyViewState extends State { ), body: WebView( onWebViewCreated: (WebViewController webViewController) async { - await model.loadHtmlFromAssets( - widget.description, Theme.of(context).brightness, webViewController); + await model.loadHtmlFromAssets(widget.description, + Theme.of(context).brightness, webViewController); }, ), ), diff --git a/lib/ui/views/ets_view.dart b/lib/ui/views/ets_view.dart index 5b8e0524c..f6c51149b 100644 --- a/lib/ui/views/ets_view.dart +++ b/lib/ui/views/ets_view.dart @@ -1,8 +1,10 @@ -// FLUTTER / DART / THIRD-PARTIES +// Flutter imports: import 'package:flutter/material.dart'; + +// Package imports: import 'package:flutter_gen/gen_l10n/app_localizations.dart'; -// WIDGET +// Project imports: import 'package:notredame/ui/views/news_view.dart'; import 'package:notredame/ui/views/quick_links_view.dart'; import 'package:notredame/ui/widgets/base_scaffold.dart'; diff --git a/lib/ui/views/faq_view.dart b/lib/ui/views/faq_view.dart index 56261591d..f6e377037 100644 --- a/lib/ui/views/faq_view.dart +++ b/lib/ui/views/faq_view.dart @@ -59,7 +59,9 @@ class _FaqViewState extends State { ), child: getQuestionCard( question.title[model.locale?.languageCode] ?? '', - question.description[model.locale?.languageCode] ?? '', + question.description[ + model.locale?.languageCode] ?? + '', ), ); }, diff --git a/lib/ui/views/feedback_view.dart b/lib/ui/views/feedback_view.dart index a52ab9e16..470b1e170 100644 --- a/lib/ui/views/feedback_view.dart +++ b/lib/ui/views/feedback_view.dart @@ -155,10 +155,10 @@ class _FeedbackViewState extends State { const SizedBox(width: 4), createListTag( model.myIssues[index].isOpen - ? AppIntl.of(context) - !.ticket_status_open - : AppIntl.of(context) - !.ticket_status_closed, + ? AppIntl.of(context)! + .ticket_status_open + : AppIntl.of(context)! + .ticket_status_closed, color: model.myIssues[index].state == 'open' ? Colors.green @@ -190,8 +190,8 @@ class _FeedbackViewState extends State { overflow: TextOverflow.ellipsis, style: Theme.of(context) .textTheme - .headline6 - !.copyWith( + .headline6! + .copyWith( color: isLightMode ? const Color.fromARGB( 168, 0, 0, 0) @@ -224,14 +224,14 @@ class _FeedbackViewState extends State { text: AppIntl.of(context)!.more_report_bug_step1, style: Theme.of(context) .textTheme - .bodyText2 - !.copyWith(fontSize: 18)), + .bodyText2! + .copyWith(fontSize: 18)), TextSpan( text: AppIntl.of(context)!.more_report_bug_step2, style: Theme.of(context) .textTheme - .bodyText2 - !.copyWith( + .bodyText2! + .copyWith( fontSize: 18, color: Theme.of(context).brightness == Brightness.light @@ -242,14 +242,14 @@ class _FeedbackViewState extends State { text: AppIntl.of(context)!.more_report_bug_step3, style: Theme.of(context) .textTheme - .bodyText2 - !.copyWith(fontSize: 18)), + .bodyText2! + .copyWith(fontSize: 18)), TextSpan( text: AppIntl.of(context)!.more_report_bug_step4, style: Theme.of(context) .textTheme - .bodyText2 - !.copyWith( + .bodyText2! + .copyWith( fontSize: 18, color: Theme.of(context).brightness == Brightness.light @@ -260,8 +260,8 @@ class _FeedbackViewState extends State { text: AppIntl.of(context)!.more_report_bug_step5, style: Theme.of(context) .textTheme - .bodyText2 - !.copyWith(fontSize: 18)), + .bodyText2! + .copyWith(fontSize: 18)), ], ), ), @@ -302,16 +302,16 @@ class _FeedbackViewState extends State { title, style: Theme.of(context) .textTheme - .bodyText2 - !.copyWith(fontSize: 19), + .bodyText2! + .copyWith(fontSize: 19), textAlign: TextAlign.left, ), Text( subtitle, style: Theme.of(context) .textTheme - .bodyText2 - !.copyWith(fontSize: 16), + .bodyText2! + .copyWith(fontSize: 16), textAlign: TextAlign.left, ) ], diff --git a/lib/ui/views/grade_details_view.dart b/lib/ui/views/grade_details_view.dart index bf0fad427..bf642dfb4 100644 --- a/lib/ui/views/grade_details_view.dart +++ b/lib/ui/views/grade_details_view.dart @@ -105,12 +105,12 @@ class _GradesDetailsViewState extends State children: [ _buildClassInfo(model.course.title), if (model.course.teacherName != null) - _buildClassInfo(AppIntl.of(context) - !.grades_teacher(model.course.teacherName!)), - _buildClassInfo(AppIntl.of(context) - !.grades_group_number(model.course.group)), - _buildClassInfo(AppIntl.of(context)!.credits_number( - model.course.numberOfCredits)), + _buildClassInfo(AppIntl.of(context)! + .grades_teacher(model.course.teacherName!)), + _buildClassInfo(AppIntl.of(context)! + .grades_group_number(model.course.group)), + _buildClassInfo(AppIntl.of(context)! + .credits_number(model.course.numberOfCredits)), ], ), ), @@ -129,7 +129,8 @@ class _GradesDetailsViewState extends State Widget _buildGradeEvaluations(GradesDetailsViewModel model) { if (model.isBusy) { return const Center(child: CircularProgressIndicator()); - } else if (model.course.inReviewPeriod && !(model.course.reviewCompleted ?? false)) { + } else if (model.course.inReviewPeriod && + !(model.course.reviewCompleted ?? false)) { return Center( child: GradeNotAvailable( key: const Key("EvaluationNotCompleted"), @@ -237,7 +238,8 @@ class _GradesDetailsViewState extends State ), ]), Column(children: [ - for (CourseEvaluation evaluation in model.course.summary?.evaluations ?? []) + for (CourseEvaluation evaluation + in model.course.summary?.evaluations ?? []) GradeEvaluationTile( evaluation, completed: _completed, @@ -267,8 +269,8 @@ class _GradesDetailsViewState extends State info, style: Theme.of(context) .textTheme - .bodyText1 - !.copyWith(color: Colors.white, fontSize: 16), + .bodyText1! + .copyWith(color: Colors.white, fontSize: 16), overflow: TextOverflow.ellipsis, ), ), @@ -291,8 +293,10 @@ class _GradesDetailsViewState extends State maxGrade, ), ), - style: - Theme.of(context).textTheme.headline6!.copyWith(color: color)), + style: Theme.of(context) + .textTheme + .headline6! + .copyWith(color: color)), ), Text(recipient, style: diff --git a/lib/ui/views/grades_view.dart b/lib/ui/views/grades_view.dart index d362f9eeb..a0e187b18 100644 --- a/lib/ui/views/grades_view.dart +++ b/lib/ui/views/grades_view.dart @@ -105,7 +105,8 @@ class _GradesViewState extends State { const SizedBox(height: 16.0), Wrap( children: courses - .map((course) => GradeButton(course, showDiscovery: index == 0)) + .map((course) => + GradeButton(course, showDiscovery: index == 0)) .toList(), ), ], diff --git a/lib/ui/views/login_view.dart b/lib/ui/views/login_view.dart index 9bf6c5075..3c1bd9ce0 100644 --- a/lib/ui/views/login_view.dart +++ b/lib/ui/views/login_view.dart @@ -103,16 +103,16 @@ class _LoginViewState extends State { borderSide: BorderSide( color: errorTextColor, width: borderRadiusOnFocus)), - labelText: AppIntl.of(context) - !.login_prompt_universal_code, + labelText: AppIntl.of(context)! + .login_prompt_universal_code, labelStyle: const TextStyle(color: Colors.white54), errorStyle: TextStyle(color: errorTextColor), suffixIcon: Tooltip( key: tooltipkey, triggerMode: TooltipTriggerMode.manual, - message: AppIntl.of(context) - !.universal_code_example, + message: AppIntl.of(context)! + .universal_code_example, preferBelow: true, child: IconButton( icon: const Icon(Icons.help, diff --git a/lib/ui/views/more_view.dart b/lib/ui/views/more_view.dart index 6fea01ad1..aa8002300 100644 --- a/lib/ui/views/more_view.dart +++ b/lib/ui/views/more_view.dart @@ -197,8 +197,8 @@ class _MoreViewState extends State { AppIntl.of(context)!.more_log_out, style: const TextStyle(color: Colors.red), ), - content: Text(AppIntl.of(context) - !.more_prompt_log_out_confirmation), + content: Text(AppIntl.of(context)! + .more_prompt_log_out_confirmation), actions: [ TextButton( onPressed: () async { diff --git a/lib/ui/views/news_view.dart b/lib/ui/views/news_view.dart index 8cfa8078c..a04297aea 100644 --- a/lib/ui/views/news_view.dart +++ b/lib/ui/views/news_view.dart @@ -1,13 +1,14 @@ -// FLUTTER / DART / THIRD-PARTIES +// Flutter imports: import 'package:flutter/material.dart'; -import 'package:stacked/stacked.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; -// WIDGET -import 'package:notredame/ui/widgets/news_card.dart'; +// Package imports: +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:stacked/stacked.dart'; -// VIEW-MODEL +// Project imports: import 'package:notredame/core/viewmodels/news_viewmodel.dart'; +import 'package:notredame/ui/widgets/news_card.dart'; +import 'package:notredame/ui/widgets/news_card_skeleton.dart'; class NewsView extends StatefulWidget { @override @@ -15,6 +16,8 @@ class NewsView extends StatefulWidget { } class _NewsViewState extends State { + int nbSkeletons = 3; + @override void initState() { super.initState(); @@ -26,17 +29,24 @@ class _NewsViewState extends State { viewModelBuilder: () => NewsViewModel(intl: AppIntl.of(context)!), builder: (context, model, child) { return RefreshIndicator( - child: Theme( - data: - Theme.of(context).copyWith(canvasColor: Colors.transparent), - child: model.isLoadingEvents - ? const Center(child: CircularProgressIndicator()) - : ListView( - padding: const EdgeInsets.fromLTRB(0, 4, 0, 8), - children: - model.news.map((news) => NewsCard(news)).toList()), - ), - onRefresh: () => model.refresh(), - ); + onRefresh: model.refresh, + child: Theme( + data: Theme.of(context) + .copyWith(canvasColor: Colors.transparent), + child: model.isLoadingEvents + ? _buildSkeletonLoader() + : ListView( + padding: const EdgeInsets.fromLTRB(0, 4, 0, 8), + children: + model.news.map((news) => NewsCard(news)).toList(), + ), + )); }); + + Widget _buildSkeletonLoader() { + return ListView.builder( + itemCount: nbSkeletons, + itemBuilder: (context, index) => NewsCardSkeleton(), + ); + } } diff --git a/lib/ui/views/not_found_view.dart b/lib/ui/views/not_found_view.dart index 85230cf5e..7027cc1f7 100644 --- a/lib/ui/views/not_found_view.dart +++ b/lib/ui/views/not_found_view.dart @@ -78,8 +78,8 @@ class _NotFoundState extends State { bottom: 70, ), child: Text( - AppIntl.of(context) - !.not_found_message(model.notFoundPageName), + AppIntl.of(context)! + .not_found_message(model.notFoundPageName), textAlign: TextAlign.center, style: const TextStyle( fontSize: 15, diff --git a/lib/ui/views/outage_view.dart b/lib/ui/views/outage_view.dart index 3e74df47b..3fb55e825 100644 --- a/lib/ui/views/outage_view.dart +++ b/lib/ui/views/outage_view.dart @@ -83,7 +83,8 @@ class OutageView extends StatelessWidget { color: Colors.white, ), onPressed: () => Utils.launchURL( - Urls.clubWebsite, AppIntl.of(context)!)), + Urls.clubWebsite, + AppIntl.of(context)!)), IconButton( icon: const FaIcon( FontAwesomeIcons.github, @@ -104,7 +105,8 @@ class OutageView extends StatelessWidget { color: Colors.white, ), onPressed: () => Utils.launchURL( - Urls.clubDiscord, AppIntl.of(context)!)), + Urls.clubDiscord, + AppIntl.of(context)!)), ], ), ], diff --git a/lib/ui/views/profile_view.dart b/lib/ui/views/profile_view.dart index b58ce7c00..45729deef 100644 --- a/lib/ui/views/profile_view.dart +++ b/lib/ui/views/profile_view.dart @@ -179,8 +179,8 @@ Card getMyInfosCard(ProfileViewModel model, BuildContext context) { Clipboard.setData( ClipboardData(text: model.profileStudent.permanentCode)); ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text(AppIntl.of(context) - !.profile_permanent_code_copied_to_clipboard), + content: Text(AppIntl.of(context)! + .profile_permanent_code_copied_to_clipboard), )); }, child: Column( @@ -208,8 +208,8 @@ Card getMyInfosCard(ProfileViewModel model, BuildContext context) { onTap: () { Clipboard.setData(ClipboardData(text: model.universalAccessCode)); ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text(AppIntl.of(context) - !.profile_universal_code_copied_to_clipboard), + content: Text(AppIntl.of(context)! + .profile_universal_code_copied_to_clipboard), )); }, child: Column( diff --git a/lib/ui/views/quick_links_view.dart b/lib/ui/views/quick_links_view.dart index 716ed8190..18197f18b 100644 --- a/lib/ui/views/quick_links_view.dart +++ b/lib/ui/views/quick_links_view.dart @@ -49,14 +49,6 @@ class _QuickLinksViewState extends State ), ); - AppBar _buildAppBar(BuildContext context, QuickLinksViewModel model) { - return AppBar( - title: Text(AppIntl.of(context)!.title_ets), - automaticallyImplyLeading: false, - actions: const [], - ); - } - Widget _buildBody(BuildContext context, QuickLinksViewModel model) { return GestureDetector( onTap: () { diff --git a/lib/ui/widgets/base_scaffold.dart b/lib/ui/widgets/base_scaffold.dart index 05b846b12..a423f4e18 100644 --- a/lib/ui/widgets/base_scaffold.dart +++ b/lib/ui/widgets/base_scaffold.dart @@ -13,8 +13,8 @@ import 'package:notredame/core/services/networking_service.dart'; import 'package:notredame/core/utils/utils.dart'; import 'package:notredame/locator.dart'; import 'package:notredame/ui/utils/app_theme.dart'; -import 'package:notredame/ui/widgets/scaffold_safe_area.dart'; import 'package:notredame/ui/widgets/bottom_bar.dart'; +import 'package:notredame/ui/widgets/scaffold_safe_area.dart'; /// Basic Scaffold to avoid boilerplate code in the application. /// Contains a loader controlled by [_isLoading] diff --git a/lib/ui/widgets/grade_button.dart b/lib/ui/widgets/grade_button.dart index 5dcdcaf57..e8b963d7b 100644 --- a/lib/ui/widgets/grade_button.dart +++ b/lib/ui/widgets/grade_button.dart @@ -32,7 +32,8 @@ class GradeButton extends StatelessWidget { Widget build(BuildContext context) => Card( child: InkWell( onTap: () async { - if (ModalRoute.of(context)!.settings.name == RouterPaths.dashboard || + if (ModalRoute.of(context)!.settings.name == + RouterPaths.dashboard || await _settingsManager .getBool(PreferencesFlag.discoveryStudentGrade) == true) { @@ -89,8 +90,8 @@ class GradeButton extends StatelessWidget { course.acronym, style: Theme.of(context) .textTheme - .bodyText1 - !.copyWith(color: Colors.white), + .bodyText1! + .copyWith(color: Colors.white), ), ), ), diff --git a/lib/ui/widgets/grade_circular_progress.dart b/lib/ui/widgets/grade_circular_progress.dart index 431045c94..3b8064617 100644 --- a/lib/ui/widgets/grade_circular_progress.dart +++ b/lib/ui/widgets/grade_circular_progress.dart @@ -96,8 +96,8 @@ class _GradeCircularProgressState extends State } if (widget.studentGrade != null) { - return AppIntl.of(context) - !.grades_grade_in_percentage(widget.studentGrade!.round()); + return AppIntl.of(context)! + .grades_grade_in_percentage(widget.studentGrade!.round()); } return AppIntl.of(context)!.grades_not_available; diff --git a/lib/ui/widgets/grade_evaluation_tile.dart b/lib/ui/widgets/grade_evaluation_tile.dart index 8b05bf832..f559ca71b 100644 --- a/lib/ui/widgets/grade_evaluation_tile.dart +++ b/lib/ui/widgets/grade_evaluation_tile.dart @@ -159,8 +159,8 @@ class _GradeEvaluationTileState extends State Padding( padding: const EdgeInsets.only(top: 10.0, bottom: 20.0), child: Text( - AppIntl.of(context) - !.grades_weight(widget.evaluation.weight), + AppIntl.of(context)! + .grades_weight(widget.evaluation.weight), style: TextStyle( fontSize: 14, color: Utils.getColorByBrightness( diff --git a/lib/ui/widgets/grade_not_available.dart b/lib/ui/widgets/grade_not_available.dart index 7b030fc99..a85f68759 100644 --- a/lib/ui/widgets/grade_not_available.dart +++ b/lib/ui/widgets/grade_not_available.dart @@ -30,8 +30,8 @@ class GradeNotAvailable extends StatelessWidget { const SizedBox(height: 25), Text( isEvaluationPeriod - ? AppIntl.of(context) - !.grades_error_course_evaluations_not_completed + ? AppIntl.of(context)! + .grades_error_course_evaluations_not_completed : AppIntl.of(context)!.grades_msg_no_grade, textAlign: TextAlign.center, softWrap: true, diff --git a/lib/ui/widgets/news_card.dart b/lib/ui/widgets/news_card.dart index 33c21db69..12d8bfa4f 100644 --- a/lib/ui/widgets/news_card.dart +++ b/lib/ui/widgets/news_card.dart @@ -1,15 +1,26 @@ -// FLUTTER / DART / THIRD-PARTIES +// Flutter imports: import 'package:flutter/material.dart'; + +// Package imports: import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:shimmer/shimmer.dart'; import 'package:timeago/timeago.dart' as timeago; -// MODEL +// Project imports: import 'package:notredame/core/models/news.dart'; +import 'package:notredame/ui/utils/app_theme.dart'; -class NewsCard extends StatelessWidget { +class NewsCard extends StatefulWidget { final News news; - const NewsCard(this.news); + const NewsCard(this.news, {Key? key}) : super(key: key); + + @override + _NewsCardState createState() => _NewsCardState(); +} + +class _NewsCardState extends State { + bool _isImageLoaded = false; @override Widget build(BuildContext context) { @@ -26,9 +37,9 @@ class NewsCard extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - _buildImage(news), + _buildImage(widget.news.image), const SizedBox(height: 8), - _buildTitleAndTime(news, context), + _buildTitleAndTime(widget.news, context) ], ), ), @@ -37,21 +48,39 @@ class NewsCard extends StatelessWidget { ); } - Widget _buildImage(News news) { + Widget _buildImage(String image) { + if (image == "") { + return const SizedBox(); + } return ClipRRect( borderRadius: BorderRadius.circular(16.0), - child: Image.network( - news.image, - fit: BoxFit.cover, + child: _isImageLoaded + ? Image.network(image, fit: BoxFit.cover) + : _shimmerEffect(), + ); + } + + Widget _shimmerEffect() { + return Shimmer.fromColors( + baseColor: Theme.of(context).brightness == Brightness.light + ? AppTheme.lightThemeBackground + : AppTheme.darkThemeBackground, + highlightColor: Theme.of(context).brightness == Brightness.light + ? AppTheme.lightThemeAccent + : AppTheme.darkThemeAccent, + child: Container( + height: 200, + decoration: BoxDecoration( + color: Colors.grey, + borderRadius: BorderRadius.circular(16), + ), ), ); } Widget _buildTitleAndTime(News news, BuildContext context) { final TextStyle textStyle = - Theme.of(context).textTheme.titleMedium!.copyWith( - fontSize: 16, - ); + Theme.of(context).textTheme.titleMedium!.copyWith(fontSize: 16); return Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, @@ -71,4 +100,31 @@ class NewsCard extends StatelessWidget { ], ); } + + @override + void initState() { + super.initState(); + _preloadImage(); + } + + void _preloadImage() { + Image.network(widget.news.image) + .image + // ignore: use_named_constants + .resolve(const ImageConfiguration()) + .addListener( + ImageStreamListener( + (ImageInfo image, bool synchronousCall) { + if (mounted) { + setState(() { + _isImageLoaded = true; + }); + } + }, + onError: (exception, stackTrace) { + // Handle image load error + }, + ), + ); + } } diff --git a/lib/ui/widgets/news_card_skeleton.dart b/lib/ui/widgets/news_card_skeleton.dart new file mode 100644 index 000000000..151d85168 --- /dev/null +++ b/lib/ui/widgets/news_card_skeleton.dart @@ -0,0 +1,98 @@ +// Flutter imports: +import 'package:flutter/material.dart'; + +// Package imports: +import 'package:shimmer/shimmer.dart'; + +// Project imports: +import 'package:notredame/ui/utils/app_theme.dart'; + +class NewsCardSkeleton extends StatelessWidget { + @override + Widget build(BuildContext context) { + return Card( + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Container( + padding: const EdgeInsets.fromLTRB(16, 16, 16, 16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + _shimmerEffect(context), + const SizedBox(height: 8), + _shimmerTextEffect(context), + ], + ), + ), + ], + ), + ); + } + + Widget _shimmerEffect(BuildContext context) { + return Shimmer.fromColors( + baseColor: Theme.of(context).brightness == Brightness.light + ? AppTheme.lightThemeBackground + : AppTheme.darkThemeBackground, + highlightColor: Theme.of(context).brightness == Brightness.light + ? AppTheme.lightThemeAccent + : AppTheme.darkThemeAccent, + child: Container( + height: 200, + decoration: BoxDecoration( + color: Colors.grey, + borderRadius: BorderRadius.circular(16), + ), + ), + ); + } + + Widget _shimmerTextEffect(BuildContext context) { + return Shimmer.fromColors( + baseColor: Theme.of(context).brightness == Brightness.light + ? AppTheme.lightThemeBackground + : AppTheme.darkThemeBackground, + highlightColor: Theme.of(context).brightness == Brightness.light + ? AppTheme.lightThemeAccent + : AppTheme.darkThemeAccent, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + width: double.infinity, + height: 20.0, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(12), + ), + ), + const SizedBox(height: 8), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Container( + width: 100, + height: 20.0, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(12), + ), + ), + Container( + width: 60, + height: 20.0, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(12), + ), + ), + ], + ), + ], + ), + ); + } +} diff --git a/lib/ui/widgets/password_text_field.dart b/lib/ui/widgets/password_text_field.dart index b8b2be6e9..70e472dbd 100644 --- a/lib/ui/widgets/password_text_field.dart +++ b/lib/ui/widgets/password_text_field.dart @@ -8,7 +8,8 @@ class PasswordFormField extends StatefulWidget { final FormFieldValidator validator; final VoidCallback onEditionComplete; - const PasswordFormField({Key? key, required this.validator, required this.onEditionComplete}) + const PasswordFormField( + {Key? key, required this.validator, required this.onEditionComplete}) : super(key: key); @override diff --git a/lib/ui/widgets/scaffold_safe_area.dart b/lib/ui/widgets/scaffold_safe_area.dart index 11253a2aa..963c639c6 100644 --- a/lib/ui/widgets/scaffold_safe_area.dart +++ b/lib/ui/widgets/scaffold_safe_area.dart @@ -1,7 +1,7 @@ -// FLUTTER / DART / THIRD-PARTIES +// Flutter imports: import 'package:flutter/material.dart'; -// UTILS +// Project imports: import 'package:notredame/ui/utils/loading.dart'; /// ScaffoldSafeArea to avoid boilerplate code in the application. diff --git a/lib/ui/widgets/schedule_settings.dart b/lib/ui/widgets/schedule_settings.dart index c3c57a0ea..5d14c457b 100644 --- a/lib/ui/widgets/schedule_settings.dart +++ b/lib/ui/widgets/schedule_settings.dart @@ -149,7 +149,7 @@ class _ScheduleSettingsState extends State { title: Text(AppIntl.of(context)!.course_activity_group_both), )); - if(model.scheduleActivitiesByCourse[courseActivitiesAcronym] != null) { + if (model.scheduleActivitiesByCourse[courseActivitiesAcronym] != null) { for (final course in model.scheduleActivitiesByCourse[courseActivitiesAcronym]!) { tiles.add(ListTile( @@ -162,7 +162,6 @@ class _ScheduleSettingsState extends State { )); } } - if (model.scheduleActivitiesByCourse.values.length > 1) { tiles.add(const Divider(endIndent: 50, thickness: 1.5)); diff --git a/pubspec.lock b/pubspec.lock index 95ce1b5e8..fa729ac83 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1115,6 +1115,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.4" + shimmer: + dependency: "direct main" + description: + name: shimmer + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" simple_gesture_detector: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 4241a7a4e..5910f8ab4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ description: The 4th generation of ÉTSMobile, the main gateway between the Éco # pub.dev using `pub publish`. This is preferred for private packages. publish_to: 'none' # Remove this line if you wish to publish to pub.dev -version: 4.33.1+1 +version: 4.34.0+1 environment: sdk: ">=2.12.0 <3.0.0" @@ -76,6 +76,7 @@ dependencies: reorderable_grid_view: ^2.2.6 import_sorter: ^4.6.0 flutter_keychain: ^2.4.0 + shimmer: ^3.0.0 dev_dependencies: flutter_test: diff --git a/test/helpers.dart b/test/helpers.dart index 72579a63c..c0ff352ab 100644 --- a/test/helpers.dart +++ b/test/helpers.dart @@ -14,9 +14,9 @@ import 'package:logger/logger.dart'; // Project imports: import 'package:notredame/core/managers/cache_manager.dart'; import 'package:notredame/core/managers/course_repository.dart'; +import 'package:notredame/core/managers/news_repository.dart'; import 'package:notredame/core/managers/quick_link_repository.dart'; import 'package:notredame/core/managers/settings_manager.dart'; -import 'package:notredame/core/managers/news_repository.dart'; import 'package:notredame/core/managers/user_repository.dart'; import 'package:notredame/core/services/analytics_service.dart'; import 'package:notredame/core/services/app_widget_service.dart'; diff --git a/test/managers/course_repository_test.dart b/test/managers/course_repository_test.dart index c712ce95c..b7cebb9e7 100644 --- a/test/managers/course_repository_test.dart +++ b/test/managers/course_repository_test.dart @@ -89,8 +89,7 @@ void main() { // Stub a user UserRepositoryMock.stubMonETSUser(userRepositoryMock, MonETSUser(domain: '', typeUsagerId: 0, username: username)); - UserRepositoryMock.stubGetPassword( - userRepositoryMock, "password"); + UserRepositoryMock.stubGetPassword(userRepositoryMock, "password"); // Stub some sessions CacheManagerMock.stubGet(cacheManagerMock, @@ -150,8 +149,8 @@ void main() { "Trying to recover activities from cache but an exception is raised.", () async { // Stub the cache to throw an exception - CacheManagerMock.stubGetException(cacheManagerMock, - CourseRepository.coursesActivitiesCacheKey); + CacheManagerMock.stubGetException( + cacheManagerMock, CourseRepository.coursesActivitiesCacheKey); // Stub the SignetsAPI to return 0 activities SignetsAPIClientMock.stubGetCoursesActivities( @@ -174,7 +173,8 @@ void main() { username: username, password: anyNamed("password"), session: session.shortName), - cacheManagerMock.update(CourseRepository.coursesActivitiesCacheKey, any) + cacheManagerMock.update( + CourseRepository.coursesActivitiesCacheKey, any) ]); verify(signetsApiMock.getSessions( @@ -215,7 +215,8 @@ void main() { username: username, password: anyNamed("password"), session: session.shortName), - cacheManagerMock.update(CourseRepository.coursesActivitiesCacheKey, any) + cacheManagerMock.update( + CourseRepository.coursesActivitiesCacheKey, any) ]); verifyNoMoreInteractions(signetsApiMock); @@ -224,8 +225,7 @@ void main() { test("getSessions fails", () async { // Stub SignetsApi to throw an exception reset(signetsApiMock); - SignetsAPIClientMock.stubGetSessionsException( - signetsApiMock, username); + SignetsAPIClientMock.stubGetSessionsException(signetsApiMock, username); // Stub the cache to return 1 activity CacheManagerMock.stubGet(cacheManagerMock, @@ -266,10 +266,9 @@ void main() { // Stub an authentication error reset(userRepositoryMock); - UserRepositoryMock.stubGetPasswordException( - userRepositoryMock); - UserRepositoryMock.stubMonETSUser( - userRepositoryMock, MonETSUser(domain: '', typeUsagerId: 0, username: username)); + UserRepositoryMock.stubGetPasswordException(userRepositoryMock); + UserRepositoryMock.stubMonETSUser(userRepositoryMock, + MonETSUser(domain: '', typeUsagerId: 0, username: username)); expect(manager.getCoursesActivities(), throwsA(isInstanceOf())); @@ -311,9 +310,7 @@ void main() { // Stub the SignetsAPI to return 2 activities SignetsAPIClientMock.stubGetCoursesActivities( - signetsApiMock, - session.shortName, - [activity, courseActivity]); + signetsApiMock, session.shortName, [activity, courseActivity]); expect(manager.coursesActivities, isNull); final List? results = @@ -395,9 +392,7 @@ void main() { // Stub the SignetsAPI to return the same activity as the cache SignetsAPIClientMock.stubGetCoursesActivities( - signetsApiMock, - session.shortName, - [changedActivity]); + signetsApiMock, session.shortName, [changedActivity]); expect(manager.coursesActivities, isNull); final List? results = @@ -465,8 +460,8 @@ void main() { SignetsAPIClientMock.stubGetCoursesActivities( signetsApiMock, session.shortName, activities); - CacheManagerMock.stubUpdateException(cacheManagerMock, - CourseRepository.coursesActivitiesCacheKey); + CacheManagerMock.stubUpdateException( + cacheManagerMock, CourseRepository.coursesActivitiesCacheKey); expect(manager.coursesActivities, isNull); final List? results = @@ -541,8 +536,7 @@ void main() { // Stub a user UserRepositoryMock.stubMonETSUser(userRepositoryMock, MonETSUser(domain: '', typeUsagerId: 0, username: username)); - UserRepositoryMock.stubGetPassword( - userRepositoryMock, "password"); + UserRepositoryMock.stubGetPassword(userRepositoryMock, "password"); // Stub some sessions CacheManagerMock.stubGet(cacheManagerMock, @@ -582,7 +576,8 @@ void main() { username: username, password: anyNamed("password"), session: session.shortName), - cacheManagerMock.update(CourseRepository.scheduleActivitiesCacheKey, any) + cacheManagerMock.update( + CourseRepository.scheduleActivitiesCacheKey, any) ]); }); @@ -614,8 +609,8 @@ void main() { "Trying to recover activities from cache but an exception is raised.", () async { // Stub the cache to throw an exception - CacheManagerMock.stubGetException(cacheManagerMock, - CourseRepository.scheduleActivitiesCacheKey); + CacheManagerMock.stubGetException( + cacheManagerMock, CourseRepository.scheduleActivitiesCacheKey); // Stub the SignetsAPI to return 0 activities SignetsAPIClientMock.stubGetScheduleActivities( @@ -638,7 +633,8 @@ void main() { username: username, password: anyNamed("password"), session: session.shortName), - cacheManagerMock.update(CourseRepository.scheduleActivitiesCacheKey, any) + cacheManagerMock.update( + CourseRepository.scheduleActivitiesCacheKey, any) ]); verify(signetsApiMock.getSessions( @@ -681,7 +677,8 @@ void main() { username: username, password: anyNamed("password"), session: session.shortName), - cacheManagerMock.update(CourseRepository.scheduleActivitiesCacheKey, any) + cacheManagerMock.update( + CourseRepository.scheduleActivitiesCacheKey, any) ]); verifyNoMoreInteractions(signetsApiMock); @@ -690,8 +687,7 @@ void main() { test("getSessions fails", () async { // Stub SignetsApi to throw an exception reset(signetsApiMock); - SignetsAPIClientMock.stubGetSessionsException( - signetsApiMock, username); + SignetsAPIClientMock.stubGetSessionsException(signetsApiMock, username); // Stub the cache to return 1 activity CacheManagerMock.stubGet( @@ -734,10 +730,9 @@ void main() { // Stub an authentication error reset(userRepositoryMock); - UserRepositoryMock.stubGetPasswordException( - userRepositoryMock); - UserRepositoryMock.stubMonETSUser( - userRepositoryMock, MonETSUser(domain: '', typeUsagerId: 0, username: username)); + UserRepositoryMock.stubGetPasswordException(userRepositoryMock); + UserRepositoryMock.stubMonETSUser(userRepositoryMock, + MonETSUser(domain: '', typeUsagerId: 0, username: username)); expect(manager.getScheduleActivities(), throwsA(isInstanceOf())); @@ -772,9 +767,7 @@ void main() { // Stub the SignetsAPI to return the same activity as the cache SignetsAPIClientMock.stubGetScheduleActivities( - signetsApiMock, - session.shortName, - scheduleActivities); + signetsApiMock, session.shortName, scheduleActivities); expect(manager.scheduleActivities, isNull); final List results = @@ -861,12 +854,9 @@ void main() { CourseRepository.sessionsCacheKey, jsonEncode(sessions)); // Stub SignetsApi answer to test only the cache retrieving - SignetsAPIClientMock.stubGetSessions( - signetsApiMock, username, []); - UserRepositoryMock.stubMonETSUser( - userRepositoryMock, user); - UserRepositoryMock.stubGetPassword( - userRepositoryMock, password); + SignetsAPIClientMock.stubGetSessions(signetsApiMock, username, []); + UserRepositoryMock.stubMonETSUser(userRepositoryMock, user); + UserRepositoryMock.stubGetPassword(userRepositoryMock, password); // Stub to simulate that the user has an active internet connection NetworkingServiceMock.stubHasConnectivity(networkingServiceMock); @@ -895,8 +885,8 @@ void main() { () async { // Stub to simulate an exception when trying to get the sessions from the cache reset(cacheManagerMock); - CacheManagerMock.stubGetException(cacheManagerMock, - CourseRepository.sessionsCacheKey); + CacheManagerMock.stubGetException( + cacheManagerMock, CourseRepository.sessionsCacheKey); expect(manager.sessions, isNull); final results = await manager.getSessions(); @@ -910,7 +900,8 @@ void main() { userRepositoryMock.getPassword(), userRepositoryMock.monETSUser, signetsApiMock.getSessions(username: username, password: password), - cacheManagerMock.update(CourseRepository.sessionsCacheKey, jsonEncode([])) + cacheManagerMock.update( + CourseRepository.sessionsCacheKey, jsonEncode([])) ]); }); @@ -974,8 +965,7 @@ void main() { CourseRepository.sessionsCacheKey, jsonEncode([])); // Stub SignetsApi answer to test only the cache retrieving - SignetsAPIClientMock.stubGetSessionsException( - signetsApiMock, username); + SignetsAPIClientMock.stubGetSessionsException(signetsApiMock, username); expect(manager.sessions, isNull); expect(manager.getSessions(), throwsA(isInstanceOf())); @@ -1004,8 +994,8 @@ void main() { CourseRepository.sessionsCacheKey, jsonEncode([])); // Stub to simulate exception when updating cache - CacheManagerMock.stubUpdateException(cacheManagerMock, - CourseRepository.sessionsCacheKey); + CacheManagerMock.stubUpdateException( + cacheManagerMock, CourseRepository.sessionsCacheKey); // Stub SignetsApi answer to test only the cache retrieving SignetsAPIClientMock.stubGetSessions( @@ -1035,8 +1025,7 @@ void main() { CourseRepository.sessionsCacheKey, jsonEncode([])); // Stub UserRepository to throw a exception - UserRepositoryMock.stubGetPasswordException( - userRepositoryMock); + UserRepositoryMock.stubGetPasswordException(userRepositoryMock); expect(manager.sessions, isNull); expect(manager.getSessions(), throwsA(isInstanceOf())); @@ -1117,8 +1106,7 @@ void main() { signetsApiMock, username, sessions); UserRepositoryMock.stubMonETSUser(userRepositoryMock, MonETSUser(domain: '', typeUsagerId: 0, username: username)); - UserRepositoryMock.stubGetPassword( - userRepositoryMock, password); + UserRepositoryMock.stubGetPassword(userRepositoryMock, password); CacheManagerMock.stubGet(cacheManagerMock, CourseRepository.sessionsCacheKey, jsonEncode(sessions)); NetworkingServiceMock.stubHasConnectivity(networkingServiceMock); @@ -1151,8 +1139,7 @@ void main() { signetsApiMock, username, sessions); UserRepositoryMock.stubMonETSUser(userRepositoryMock, MonETSUser(domain: '', typeUsagerId: 0, username: username)); - UserRepositoryMock.stubGetPassword( - userRepositoryMock, password); + UserRepositoryMock.stubGetPassword(userRepositoryMock, password); CacheManagerMock.stubGet(cacheManagerMock, CourseRepository.sessionsCacheKey, jsonEncode(sessions)); NetworkingServiceMock.stubHasConnectivity(networkingServiceMock); @@ -1185,8 +1172,7 @@ void main() { signetsApiMock, username, sessions); UserRepositoryMock.stubMonETSUser(userRepositoryMock, MonETSUser(domain: '', typeUsagerId: 0, username: username)); - UserRepositoryMock.stubGetPassword( - userRepositoryMock, password); + UserRepositoryMock.stubGetPassword(userRepositoryMock, password); CacheManagerMock.stubGet(cacheManagerMock, CourseRepository.sessionsCacheKey, jsonEncode(sessions)); NetworkingServiceMock.stubHasConnectivity(networkingServiceMock); @@ -1197,12 +1183,10 @@ void main() { }); test("there is no session", () async { - SignetsAPIClientMock.stubGetSessions( - signetsApiMock, username, []); + SignetsAPIClientMock.stubGetSessions(signetsApiMock, username, []); UserRepositoryMock.stubMonETSUser(userRepositoryMock, MonETSUser(domain: '', typeUsagerId: 0, username: username)); - UserRepositoryMock.stubGetPassword( - userRepositoryMock, password); + UserRepositoryMock.stubGetPassword(userRepositoryMock, password); CacheManagerMock.stubGet(cacheManagerMock, CourseRepository.sessionsCacheKey, jsonEncode([])); NetworkingServiceMock.stubHasConnectivity(networkingServiceMock); @@ -1283,8 +1267,7 @@ void main() { // Stub a user UserRepositoryMock.stubMonETSUser(userRepositoryMock, MonETSUser(domain: '', typeUsagerId: 0, username: username)); - UserRepositoryMock.stubGetPassword( - userRepositoryMock, "password"); + UserRepositoryMock.stubGetPassword(userRepositoryMock, "password"); // Stub some sessions SignetsAPIClientMock.stubGetSessions( @@ -1297,11 +1280,9 @@ void main() { }); test("Courses are loaded from cache and cache is updated", () async { - SignetsAPIClientMock.stubGetCourses( - signetsApiMock, username, + SignetsAPIClientMock.stubGetCourses(signetsApiMock, username, coursesToReturn: [courseWithGrade]); - SignetsAPIClientMock.stubGetCourseReviews( - signetsApiMock, username); + SignetsAPIClientMock.stubGetCourseReviews(signetsApiMock, username); CacheManagerMock.stubGet(cacheManagerMock, CourseRepository.coursesCacheKey, jsonEncode([courseWithGrade])); @@ -1371,11 +1352,9 @@ void main() { cacheManagerMock, CourseRepository.coursesCacheKey, jsonEncode([courseWithGrade, courseWithGradeDuplicate])); - SignetsAPIClientMock.stubGetCourses( - signetsApiMock, username, + SignetsAPIClientMock.stubGetCourses(signetsApiMock, username, coursesToReturn: [courseFetched, courseWithGradeDuplicate]); - SignetsAPIClientMock.stubGetCourseReviews( - signetsApiMock, username); + SignetsAPIClientMock.stubGetCourseReviews(signetsApiMock, username); expect(manager.courses, isNull); final results = await manager.getCourses(); @@ -1398,8 +1377,7 @@ void main() { test("Trying to recover courses from cache failed (exception raised)", () async { expect(manager.courses, isNull); - SignetsAPIClientMock.stubGetCourses( - signetsApiMock, username); + SignetsAPIClientMock.stubGetCourses(signetsApiMock, username); CacheManagerMock.stubGetException( cacheManagerMock, CourseRepository.coursesCacheKey); @@ -1420,10 +1398,9 @@ void main() { test("Signets raised an exception while trying to recover courses", () async { - CacheManagerMock.stubGet(cacheManagerMock, - CourseRepository.coursesCacheKey, jsonEncode([])); - SignetsAPIClientMock.stubGetCoursesException( - signetsApiMock, username); + CacheManagerMock.stubGet( + cacheManagerMock, CourseRepository.coursesCacheKey, jsonEncode([])); + SignetsAPIClientMock.stubGetCoursesException(signetsApiMock, username); expect(manager.courses, isNull); @@ -1453,8 +1430,7 @@ void main() { () async { CacheManagerMock.stubGet(cacheManagerMock, CourseRepository.coursesCacheKey, jsonEncode([courseWithoutGrade])); - SignetsAPIClientMock.stubGetCoursesException( - signetsApiMock, username); + SignetsAPIClientMock.stubGetCoursesException(signetsApiMock, username); expect(manager.courses, isNull); @@ -1506,16 +1482,14 @@ void main() { title: 'Cours générique', summary: summary); - SignetsAPIClientMock.stubGetCourses( - signetsApiMock, username, + SignetsAPIClientMock.stubGetCourses(signetsApiMock, username, coursesToReturn: [courseFetched]); - SignetsAPIClientMock.stubGetCourseReviews( - signetsApiMock, username); + SignetsAPIClientMock.stubGetCourseReviews(signetsApiMock, username); SignetsAPIClientMock.stubGetCourseSummary( signetsApiMock, username, courseFetched, summaryToReturn: summary); - CacheManagerMock.stubGet(cacheManagerMock, - CourseRepository.coursesCacheKey, jsonEncode([])); + CacheManagerMock.stubGet( + cacheManagerMock, CourseRepository.coursesCacheKey, jsonEncode([])); expect(manager.courses, isNull); final results = await manager.getCourses(); @@ -1546,15 +1520,13 @@ void main() { numberOfCredits: 3, title: 'Cours générique'); - SignetsAPIClientMock.stubGetCourses( - signetsApiMock, username, + SignetsAPIClientMock.stubGetCourses(signetsApiMock, username, coursesToReturn: [courseFetched]); - SignetsAPIClientMock.stubGetCourseReviews( - signetsApiMock, username); + SignetsAPIClientMock.stubGetCourseReviews(signetsApiMock, username); SignetsAPIClientMock.stubGetCourseSummaryException( signetsApiMock, username, courseFetched); - CacheManagerMock.stubGet(cacheManagerMock, - CourseRepository.coursesCacheKey, jsonEncode([])); + CacheManagerMock.stubGet( + cacheManagerMock, CourseRepository.coursesCacheKey, jsonEncode([])); expect(manager.courses, isNull); final results = await manager.getCourses(); @@ -1578,11 +1550,9 @@ void main() { test("Cache update fails, should still return the list of courses", () async { - SignetsAPIClientMock.stubGetCourses( - signetsApiMock, username, + SignetsAPIClientMock.stubGetCourses(signetsApiMock, username, coursesToReturn: [courseWithGrade]); - SignetsAPIClientMock.stubGetCourseReviews( - signetsApiMock, username); + SignetsAPIClientMock.stubGetCourseReviews(signetsApiMock, username); CacheManagerMock.stubGet(cacheManagerMock, CourseRepository.coursesCacheKey, jsonEncode([courseWithGrade])); CacheManagerMock.stubUpdateException( @@ -1610,12 +1580,11 @@ void main() { test("UserRepository return an exception", () async { // Stub to simulate presence of session cache reset(cacheManagerMock); - CacheManagerMock.stubGet(cacheManagerMock, - CourseRepository.coursesCacheKey, jsonEncode([])); + CacheManagerMock.stubGet( + cacheManagerMock, CourseRepository.coursesCacheKey, jsonEncode([])); // Stub UserRepository to throw a exception - UserRepositoryMock.stubGetPasswordException( - userRepositoryMock); + UserRepositoryMock.stubGetPasswordException(userRepositoryMock); expect(manager.sessions, isNull); expect(manager.getCourses(), throwsA(isInstanceOf())); @@ -1634,7 +1603,8 @@ void main() { verifyNever(signetsApiMock.getCourses( username: anyNamed("username"), password: anyNamed("password"))); - verifyNever(cacheManagerMock.update(CourseRepository.coursesCacheKey, any)); + verifyNever( + cacheManagerMock.update(CourseRepository.coursesCacheKey, any)); }); test("Should force fromCacheOnly mode when user has no connectivity", @@ -1662,14 +1632,12 @@ void main() { numberOfCredits: 3, title: 'Cours générique'); - SignetsAPIClientMock.stubGetCourses( - signetsApiMock, username, + SignetsAPIClientMock.stubGetCourses(signetsApiMock, username, coursesToReturn: [courseFetched]); - SignetsAPIClientMock.stubGetCourseReviews( - signetsApiMock, username, + SignetsAPIClientMock.stubGetCourseReviews(signetsApiMock, username, session: session); - CacheManagerMock.stubGet(cacheManagerMock, - CourseRepository.coursesCacheKey, jsonEncode([])); + CacheManagerMock.stubGet( + cacheManagerMock, CourseRepository.coursesCacheKey, jsonEncode([])); expect(manager.courses, isNull); final results = await manager.getCourses(); @@ -1721,14 +1689,12 @@ void main() { title: 'Cours générique', review: review); - SignetsAPIClientMock.stubGetCourses( - signetsApiMock, username, + SignetsAPIClientMock.stubGetCourses(signetsApiMock, username, coursesToReturn: [courseFetched]); - SignetsAPIClientMock.stubGetCourseReviews( - signetsApiMock, username, + SignetsAPIClientMock.stubGetCourseReviews(signetsApiMock, username, session: session, reviewsToReturn: [review]); - CacheManagerMock.stubGet(cacheManagerMock, - CourseRepository.coursesCacheKey, jsonEncode([])); + CacheManagerMock.stubGet( + cacheManagerMock, CourseRepository.coursesCacheKey, jsonEncode([])); expect(manager.courses, isNull); final results = await manager.getCourses(); @@ -1760,14 +1726,13 @@ void main() { numberOfCredits: 3, title: 'Cours générique'); - SignetsAPIClientMock.stubGetCourses( - signetsApiMock, username, + SignetsAPIClientMock.stubGetCourses(signetsApiMock, username, coursesToReturn: [courseFetched]); SignetsAPIClientMock.stubGetCourseReviewsException( signetsApiMock, username, session: session); - CacheManagerMock.stubGet(cacheManagerMock, - CourseRepository.coursesCacheKey, jsonEncode([])); + CacheManagerMock.stubGet( + cacheManagerMock, CourseRepository.coursesCacheKey, jsonEncode([])); expect(manager.courses, isNull); final results = await manager.getCourses(); @@ -1802,8 +1767,7 @@ void main() { // Stub a user UserRepositoryMock.stubMonETSUser(userRepositoryMock, MonETSUser(domain: '', typeUsagerId: 0, username: username)); - UserRepositoryMock.stubGetPassword( - userRepositoryMock, "password"); + UserRepositoryMock.stubGetPassword(userRepositoryMock, "password"); // Reset models course = Course( @@ -1958,12 +1922,11 @@ void main() { test("UserRepository return an exception", () async { // Stub to simulate presence of session cache reset(cacheManagerMock); - CacheManagerMock.stubGet(cacheManagerMock, - CourseRepository.coursesCacheKey, jsonEncode([])); + CacheManagerMock.stubGet( + cacheManagerMock, CourseRepository.coursesCacheKey, jsonEncode([])); // Stub UserRepository to throw a exception - UserRepositoryMock.stubGetPasswordException( - userRepositoryMock); + UserRepositoryMock.stubGetPasswordException(userRepositoryMock); expect(manager.sessions, isNull); expect(manager.getCourseSummary(course), diff --git a/test/managers/news_repository_test.dart b/test/managers/news_repository_test.dart index cb014abd1..c749a2c1a 100644 --- a/test/managers/news_repository_test.dart +++ b/test/managers/news_repository_test.dart @@ -1,18 +1,14 @@ -// FLUTTER / DART / THIRD-PARTIES +// Package imports: import 'package:flutter_test/flutter_test.dart'; -// MANAGER +// Project imports: import 'package:notredame/core/managers/news_repository.dart'; - -// MODEL import 'package:notredame/core/models/news.dart'; - -// UTILS import '../helpers.dart'; void main() { group('NewsRepository tests', () { - NewsRepository repository; + late NewsRepository repository; setUp(() { setupLogger(); @@ -26,7 +22,7 @@ void main() { // TODO : remove when the news will be empty by default without test news //expect(repository.news, isEmpty); - final List fetchedNews = + final List? fetchedNews = await repository.getNews(fromCacheOnly: true); expect(repository.news, isNotEmpty); @@ -39,7 +35,7 @@ void main() { await repository.getNews(fromCacheOnly: true); - final List newsFromCache = + final List? newsFromCache = await repository.getNews(fromCacheOnly: true); expect(newsFromCache, isNotEmpty); @@ -50,7 +46,7 @@ void main() { // TODO : remove when the news will be empty by default without test news //expect(repository.news, isEmpty); - final List fetchedNews = await repository.getNews(); + final List? fetchedNews = await repository.getNews(); expect(repository.news, isNotEmpty); expect(repository.news, equals(fetchedNews)); diff --git a/test/managers/quick_link_repository_test.dart b/test/managers/quick_link_repository_test.dart index 47f728d6b..b1bc3acdf 100644 --- a/test/managers/quick_link_repository_test.dart +++ b/test/managers/quick_link_repository_test.dart @@ -58,8 +58,8 @@ void main() { "Trying to recover QuickLinkData from cache but an exception is raised.", () async { // Stub the cache to throw an exception - CacheManagerMock.stubGetException(cacheManagerMock, - QuickLinkRepository.quickLinksCacheKey); + CacheManagerMock.stubGetException( + cacheManagerMock, QuickLinkRepository.quickLinksCacheKey); expect(quickLinkRepository.getQuickLinkDataFromCache(), throwsA(isInstanceOf())); @@ -83,8 +83,8 @@ void main() { "Trying to update QuickLinkData to cache but an exception is raised.", () async { // Stub the cache to throw an exception - CacheManagerMock.stubUpdateException(cacheManagerMock, - QuickLinkRepository.quickLinksCacheKey); + CacheManagerMock.stubUpdateException( + cacheManagerMock, QuickLinkRepository.quickLinksCacheKey); final quickLink = QuickLink(id: 1, image: const Text(""), name: 'name', link: 'url'); diff --git a/test/managers/settings_manager_test.dart b/test/managers/settings_manager_test.dart index 4a4b136d2..f0a806108 100644 --- a/test/managers/settings_manager_test.dart +++ b/test/managers/settings_manager_test.dart @@ -46,28 +46,22 @@ void main() { test("validate default behaviour", () async { // Stubs the answer of the preferences services PreferencesServiceMock.stubGetString( - preferencesServiceMock, - PreferencesFlag.scheduleStartWeekday, + preferencesServiceMock, PreferencesFlag.scheduleStartWeekday, toReturn: null); PreferencesServiceMock.stubGetString( - preferencesServiceMock, - PreferencesFlag.scheduleOtherWeekday, + preferencesServiceMock, PreferencesFlag.scheduleOtherWeekday, toReturn: null); PreferencesServiceMock.stubGetString( - preferencesServiceMock, - PreferencesFlag.scheduleCalendarFormat, + preferencesServiceMock, PreferencesFlag.scheduleCalendarFormat, toReturn: null); PreferencesServiceMock.stubGetBool( - preferencesServiceMock, - PreferencesFlag.scheduleShowTodayBtn, + preferencesServiceMock, PreferencesFlag.scheduleShowTodayBtn, toReturn: null); PreferencesServiceMock.stubGetBool( - preferencesServiceMock, - PreferencesFlag.scheduleListView, + preferencesServiceMock, PreferencesFlag.scheduleListView, toReturn: null); PreferencesServiceMock.stubGetBool( - preferencesServiceMock, - PreferencesFlag.scheduleShowWeekEvents, + preferencesServiceMock, PreferencesFlag.scheduleShowWeekEvents, toReturn: null); RemoteConfigServiceMock.stubGetCalendarViewEnabled( remoteConfigServiceMock); @@ -94,7 +88,8 @@ void main() { verify(preferencesServiceMock .getString(PreferencesFlag.scheduleCalendarFormat)) .called(1); - verify(preferencesServiceMock.getBool(PreferencesFlag.scheduleShowTodayBtn)) + verify(preferencesServiceMock + .getBool(PreferencesFlag.scheduleShowTodayBtn)) .called(1); verify(preferencesServiceMock.getBool(PreferencesFlag.scheduleListView)) .called(1); @@ -109,28 +104,22 @@ void main() { test("validate the loading of the settings", () async { // Stubs the answer of the preferences services PreferencesServiceMock.stubGetString( - preferencesServiceMock, - PreferencesFlag.scheduleStartWeekday, + preferencesServiceMock, PreferencesFlag.scheduleStartWeekday, toReturn: EnumToString.convertToString(StartingDayOfWeek.sunday)); PreferencesServiceMock.stubGetString( - preferencesServiceMock, - PreferencesFlag.scheduleOtherWeekday, + preferencesServiceMock, PreferencesFlag.scheduleOtherWeekday, toReturn: EnumToString.convertToString(WeekDays.monday)); PreferencesServiceMock.stubGetString( - preferencesServiceMock, - PreferencesFlag.scheduleCalendarFormat, + preferencesServiceMock, PreferencesFlag.scheduleCalendarFormat, toReturn: EnumToString.convertToString(CalendarFormat.month)); PreferencesServiceMock.stubGetBool( - preferencesServiceMock, - PreferencesFlag.scheduleShowTodayBtn, + preferencesServiceMock, PreferencesFlag.scheduleShowTodayBtn, toReturn: false); PreferencesServiceMock.stubGetBool( - preferencesServiceMock, - PreferencesFlag.scheduleListView, + preferencesServiceMock, PreferencesFlag.scheduleListView, toReturn: false); PreferencesServiceMock.stubGetBool( - preferencesServiceMock, - PreferencesFlag.scheduleShowWeekEvents, + preferencesServiceMock, PreferencesFlag.scheduleShowWeekEvents, toReturn: false); final expected = { @@ -155,7 +144,8 @@ void main() { verify(preferencesServiceMock .getString(PreferencesFlag.scheduleCalendarFormat)) .called(1); - verify(preferencesServiceMock.getBool(PreferencesFlag.scheduleShowTodayBtn)) + verify(preferencesServiceMock + .getBool(PreferencesFlag.scheduleShowTodayBtn)) .called(1); verify(preferencesServiceMock.getBool(PreferencesFlag.scheduleListView)) .called(1); @@ -210,8 +200,7 @@ void main() { test("validate default behaviour", () async { const flag = PreferencesFlag.theme; - PreferencesServiceMock.stubGetString( - preferencesServiceMock, flag, + PreferencesServiceMock.stubGetString(preferencesServiceMock, flag, toReturn: ThemeMode.light.toString()); manager.themeMode; @@ -229,8 +218,7 @@ void main() { test("validate default behaviour", () async { const flag = PreferencesFlag.locale; PreferencesServiceMock.stubGetString( - preferencesServiceMock, - PreferencesFlag.locale, + preferencesServiceMock, PreferencesFlag.locale, toReturn: const Locale('fr').toString()); manager.setLocale('fr'); @@ -238,7 +226,8 @@ void main() { verify(preferencesServiceMock.setString(PreferencesFlag.locale, 'fr')) .called(1); - verify(preferencesServiceMock.getString(PreferencesFlag.locale)).called(1); + verify(preferencesServiceMock.getString(PreferencesFlag.locale)) + .called(1); verify(analyticsServiceMock.logEvent( "${SettingsManager.tag}_${EnumToString.convertToString(flag)}", @@ -290,7 +279,8 @@ void main() { expect(manager.locale, const Locale('en')); - verify(preferencesServiceMock.getString(PreferencesFlag.locale)).called(1); + verify(preferencesServiceMock.getString(PreferencesFlag.locale)) + .called(1); verifyNoMoreInteractions(preferencesServiceMock); verifyNoMoreInteractions(analyticsServiceMock); @@ -308,7 +298,8 @@ void main() { await manager.fetchLanguageAndThemeMode(); verify(preferencesServiceMock.getString(PreferencesFlag.theme)).called(1); - verify(preferencesServiceMock.getString(PreferencesFlag.locale)).called(1); + verify(preferencesServiceMock.getString(PreferencesFlag.locale)) + .called(1); verifyNoMoreInteractions(preferencesServiceMock); verifyNoMoreInteractions(analyticsServiceMock); @@ -340,8 +331,7 @@ void main() { test("setString", () async { const flag = PreferencesFlag.scheduleCalendarFormat; - PreferencesServiceMock.stubSetString( - preferencesServiceMock, flag); + PreferencesServiceMock.stubSetString(preferencesServiceMock, flag); expect(await manager.setString(flag, "test"), true, reason: @@ -359,8 +349,7 @@ void main() { test("setInt", () async { const flag = PreferencesFlag.aboutUsCard; - PreferencesServiceMock.stubSetInt( - preferencesServiceMock, flag); + PreferencesServiceMock.stubSetInt(preferencesServiceMock, flag); expect(await manager.setInt(flag, 0), true, reason: @@ -378,8 +367,7 @@ void main() { test("getString", () async { const flag = PreferencesFlag.scheduleCalendarFormat; - PreferencesServiceMock.stubGetString( - preferencesServiceMock, flag); + PreferencesServiceMock.stubGetString(preferencesServiceMock, flag); expect(await manager.getString(flag), 'test', reason: @@ -397,8 +385,7 @@ void main() { test("setBool", () async { const flag = PreferencesFlag.scheduleCalendarFormat; - PreferencesServiceMock.stubSetBool( - preferencesServiceMock, flag); + PreferencesServiceMock.stubSetBool(preferencesServiceMock, flag); expect(await manager.setBool(flag, true), true, reason: @@ -417,20 +404,16 @@ void main() { group("Dashboard - ", () { test("validate default behaviour", () async { PreferencesServiceMock.stubGetInt( - preferencesServiceMock, - PreferencesFlag.aboutUsCard, + preferencesServiceMock, PreferencesFlag.aboutUsCard, toReturn: null); PreferencesServiceMock.stubGetInt( - preferencesServiceMock, - PreferencesFlag.scheduleCard, + preferencesServiceMock, PreferencesFlag.scheduleCard, toReturn: null); PreferencesServiceMock.stubGetInt( - preferencesServiceMock, - PreferencesFlag.progressBarCard, + preferencesServiceMock, PreferencesFlag.progressBarCard, toReturn: null); PreferencesServiceMock.stubGetInt( - preferencesServiceMock, - PreferencesFlag.gradesCard, + preferencesServiceMock, PreferencesFlag.gradesCard, toReturn: null); // Cards @@ -455,7 +438,8 @@ void main() { .called(1); verify(preferencesServiceMock.getInt(PreferencesFlag.progressBarCard)) .called(1); - verify(preferencesServiceMock.getInt(PreferencesFlag.gradesCard)).called(1); + verify(preferencesServiceMock.getInt(PreferencesFlag.gradesCard)) + .called(1); verifyNoMoreInteractions(preferencesServiceMock); verifyNoMoreInteractions(analyticsServiceMock); @@ -463,25 +447,20 @@ void main() { test("validate the loading of the cards", () async { PreferencesServiceMock.stubGetInt( - preferencesServiceMock, - PreferencesFlag.broadcastCard, + preferencesServiceMock, PreferencesFlag.broadcastCard, toReturn: 0); PreferencesServiceMock.stubGetInt( - preferencesServiceMock, - PreferencesFlag.aboutUsCard, + preferencesServiceMock, PreferencesFlag.aboutUsCard, toReturn: 2); PreferencesServiceMock.stubGetInt( - preferencesServiceMock, - PreferencesFlag.scheduleCard, + preferencesServiceMock, PreferencesFlag.scheduleCard, toReturn: 3); PreferencesServiceMock.stubGetInt( - preferencesServiceMock, - PreferencesFlag.progressBarCard, + preferencesServiceMock, PreferencesFlag.progressBarCard, // ignore: avoid_redundant_argument_values toReturn: 1); PreferencesServiceMock.stubGetInt( - preferencesServiceMock, - PreferencesFlag.gradesCard, + preferencesServiceMock, PreferencesFlag.gradesCard, toReturn: 4); // Cards @@ -506,7 +485,8 @@ void main() { .called(1); verify(preferencesServiceMock.getInt(PreferencesFlag.progressBarCard)) .called(1); - verify(preferencesServiceMock.getInt(PreferencesFlag.gradesCard)).called(1); + verify(preferencesServiceMock.getInt(PreferencesFlag.gradesCard)) + .called(1); verifyNoMoreInteractions(preferencesServiceMock); verifyNoMoreInteractions(analyticsServiceMock); diff --git a/test/managers/user_repository_test.dart b/test/managers/user_repository_test.dart index e55b8433f..b38974299 100644 --- a/test/managers/user_repository_test.dart +++ b/test/managers/user_repository_test.dart @@ -39,8 +39,7 @@ void main() { // Setup needed service analyticsServiceMock = setupAnalyticsServiceMock(); monETSApiMock = setupMonETSApiMock(); - secureStorageMock = - setupFlutterSecureStorageMock(); + secureStorageMock = setupFlutterSecureStorageMock(); cacheManagerMock = setupCacheManagerMock(); signetsApiMock = setupSignetsApiMock(); networkingServiceMock = setupNetworkingServiceMock(); @@ -66,8 +65,7 @@ void main() { final MonETSUser user = MonETSUser( domain: "ENS", typeUsagerId: 1, username: "right credentials"); - MonETSAPIClientMock.stubAuthenticate( - monETSApiMock, user); + MonETSAPIClientMock.stubAuthenticate(monETSApiMock, user); // Result is true expect( @@ -91,8 +89,7 @@ void main() { test('An exception is throw during the MonETSApi call', () async { const String username = "exceptionUser"; - MonETSAPIClientMock.stubException( - monETSApiMock, username); + MonETSAPIClientMock.stubException(monETSApiMock, username); expect(await manager.authenticate(username: username, password: ""), isFalse, @@ -121,8 +118,7 @@ void main() { final MonETSUser user = MonETSUser( domain: "ENS", typeUsagerId: 1, username: "right credentials"); - MonETSAPIClientMock.stubAuthenticate( - monETSApiMock, user); + MonETSAPIClientMock.stubAuthenticate(monETSApiMock, user); FlutterSecureStorageMock.stubWriteException(secureStorageMock, key: UserRepository.usernameSecureKey, exceptionToThrow: PlatformException(code: "bad key")); @@ -152,16 +148,13 @@ void main() { final MonETSUser user = MonETSUser(domain: "ENS", typeUsagerId: 1, username: "AAXXXXXX"); - MonETSAPIClientMock.stubException( - monETSApiMock, user.username, + MonETSAPIClientMock.stubException(monETSApiMock, user.username, exception: HttpException( prefix: "MonETSAPI", code: 415, message: "{ \"Message\": \"The request contains an entity body but no Content-Type header. The inferred media type 'application/octet-stream' is not supported for this resource.\"}")); - SignetsAPIClientMock.stubAuthenticate( - signetsApiMock, - connected: true); + SignetsAPIClientMock.stubAuthenticate(signetsApiMock, connected: true); // Result is true expect( @@ -183,15 +176,13 @@ void main() { test('MonETSAPI failed and SignetsAPI return false', () async { const String username = "exceptionUser"; - MonETSAPIClientMock.stubException( - monETSApiMock, username, + MonETSAPIClientMock.stubException(monETSApiMock, username, exception: HttpException( prefix: "MonETSAPI", code: 415, message: "{ \"Message\": \"The request contains an entity body but no Content-Type header. The inferred media type 'application/octet-stream' is not supported for this resource.\"}")); - SignetsAPIClientMock.stubAuthenticate( - signetsApiMock); + SignetsAPIClientMock.stubAuthenticate(signetsApiMock); expect(await manager.authenticate(username: username, password: ""), isFalse, @@ -230,8 +221,7 @@ void main() { FlutterSecureStorageMock.stubRead(secureStorageMock, key: UserRepository.passwordSecureKey, valueToReturn: password); - MonETSAPIClientMock.stubAuthenticate( - monETSApiMock, user); + MonETSAPIClientMock.stubAuthenticate(monETSApiMock, user); expect(await manager.silentAuthenticate(), isTrue, reason: "Result should be true"); @@ -257,8 +247,7 @@ void main() { FlutterSecureStorageMock.stubRead(secureStorageMock, key: UserRepository.passwordSecureKey, valueToReturn: password); - MonETSAPIClientMock.stubAuthenticateException( - monETSApiMock, username); + MonETSAPIClientMock.stubAuthenticateException(monETSApiMock, username); expect(await manager.silentAuthenticate(), isFalse, reason: "Result should be false"); @@ -301,8 +290,7 @@ void main() { final MonETSUser user = MonETSUser( domain: "ENS", typeUsagerId: 1, username: "right credentials"); - MonETSAPIClientMock.stubAuthenticate( - monETSApiMock, user); + MonETSAPIClientMock.stubAuthenticate(monETSApiMock, user); FlutterSecureStorageMock.stubReadException(secureStorageMock, key: UserRepository.usernameSecureKey, exceptionToThrow: PlatformException(code: "bad key")); @@ -346,7 +334,8 @@ void main() { verify(secureStorageMock.delete(key: UserRepository.usernameSecureKey)); verify(secureStorageMock.deleteAll()); - verify(analyticsServiceMock.logError(UserRepository.tag, any, any, any)); + verify( + analyticsServiceMock.logError(UserRepository.tag, any, any, any)); }); }); @@ -363,8 +352,7 @@ void main() { final MonETSUser user = MonETSUser(domain: "ENS", typeUsagerId: 1, username: username); - MonETSAPIClientMock.stubAuthenticate( - monETSApiMock, user); + MonETSAPIClientMock.stubAuthenticate(monETSApiMock, user); FlutterSecureStorageMock.stubRead(secureStorageMock, key: UserRepository.usernameSecureKey, valueToReturn: username); FlutterSecureStorageMock.stubRead(secureStorageMock, @@ -393,8 +381,7 @@ void main() { final MonETSUser user = MonETSUser(domain: "ENS", typeUsagerId: 1, username: username); - MonETSAPIClientMock.stubAuthenticate( - monETSApiMock, user); + MonETSAPIClientMock.stubAuthenticate(monETSApiMock, user); FlutterSecureStorageMock.stubRead(secureStorageMock, key: UserRepository.usernameSecureKey, valueToReturn: username); FlutterSecureStorageMock.stubRead(secureStorageMock, @@ -419,8 +406,7 @@ void main() { const String username = "username"; const String password = "password"; - MonETSAPIClientMock.stubAuthenticateException( - monETSApiMock, username); + MonETSAPIClientMock.stubAuthenticateException(monETSApiMock, username); FlutterSecureStorageMock.stubRead(secureStorageMock, key: UserRepository.usernameSecureKey, valueToReturn: username); FlutterSecureStorageMock.stubRead(secureStorageMock, @@ -447,8 +433,7 @@ void main() { final MonETSUser user = MonETSUser(domain: "ENS", typeUsagerId: 1, username: username); - MonETSAPIClientMock.stubAuthenticate( - monETSApiMock, user); + MonETSAPIClientMock.stubAuthenticate(monETSApiMock, user); FlutterSecureStorageMock.stubReadException(secureStorageMock, key: UserRepository.passwordSecureKey, exceptionToThrow: PlatformException(code: "bad key")); @@ -462,7 +447,8 @@ void main() { analyticsServiceMock.logError(UserRepository.tag, any, any, any)); verify(secureStorageMock.deleteAll()); - verify(analyticsServiceMock.logError(UserRepository.tag, any, any, any)); + verify( + analyticsServiceMock.logError(UserRepository.tag, any, any, any)); }); }); @@ -490,8 +476,7 @@ void main() { CacheManagerMock.stubGet(cacheManagerMock, UserRepository.programsCacheKey, jsonEncode(programs)); - MonETSAPIClientMock.stubAuthenticate( - monETSApiMock, user); + MonETSAPIClientMock.stubAuthenticate(monETSApiMock, user); // Result is true expect( @@ -500,8 +485,7 @@ void main() { reason: "Check the authentication is successful"); // Stub SignetsApi answer to test only the cache retrieving - SignetsAPIClientMock.stubGetPrograms( - signetsApiMock, username, []); + SignetsAPIClientMock.stubGetPrograms(signetsApiMock, username, []); // Stub to simulate that the user has an active internet connection NetworkingServiceMock.stubHasConnectivity(networkingServiceMock); @@ -545,8 +529,8 @@ void main() { test("SignetsAPI return another program", () async { // Stub to simulate presence of program cache reset(cacheManagerMock); - CacheManagerMock.stubGet(cacheManagerMock, - UserRepository.programsCacheKey, jsonEncode([])); + CacheManagerMock.stubGet( + cacheManagerMock, UserRepository.programsCacheKey, jsonEncode([])); FlutterSecureStorageMock.stubRead(secureStorageMock, key: UserRepository.passwordSecureKey, valueToReturn: ''); @@ -572,12 +556,11 @@ void main() { test("SignetsAPI return an exception", () async { // Stub to simulate presence of program cache reset(cacheManagerMock); - CacheManagerMock.stubGet(cacheManagerMock, - UserRepository.programsCacheKey, jsonEncode([])); + CacheManagerMock.stubGet( + cacheManagerMock, UserRepository.programsCacheKey, jsonEncode([])); // Stub SignetsApi answer to test only the cache retrieving - SignetsAPIClientMock.stubGetProgramsException( - signetsApiMock, username); + SignetsAPIClientMock.stubGetProgramsException(signetsApiMock, username); FlutterSecureStorageMock.stubRead(secureStorageMock, key: UserRepository.passwordSecureKey, valueToReturn: ''); @@ -593,16 +576,18 @@ void main() { verify(cacheManagerMock.get(UserRepository.programsCacheKey)); verify(secureStorageMock.read(key: UserRepository.passwordSecureKey)); - verify(analyticsServiceMock.logError(UserRepository.tag, any, any, any)); + verify( + analyticsServiceMock.logError(UserRepository.tag, any, any, any)); - verifyNever(cacheManagerMock.update(UserRepository.programsCacheKey, any)); + verifyNever( + cacheManagerMock.update(UserRepository.programsCacheKey, any)); }); test("Cache update fail", () async { // Stub to simulate presence of program cache reset(cacheManagerMock); - CacheManagerMock.stubGet(cacheManagerMock, - UserRepository.programsCacheKey, jsonEncode([])); + CacheManagerMock.stubGet( + cacheManagerMock, UserRepository.programsCacheKey, jsonEncode([])); // Stub to simulate exception when updating cache CacheManagerMock.stubUpdateException( @@ -643,10 +628,7 @@ void main() { lastName: 'Doe', permanentCode: 'DOEJ00000000'); final ProfileStudent defaultInfo = ProfileStudent( - balance: '', - firstName: '', - lastName: '', - permanentCode: ''); + balance: '', firstName: '', lastName: '', permanentCode: ''); const String username = "username"; @@ -655,12 +637,11 @@ void main() { setUp(() async { // Stub to simulate presence of info cache - CacheManagerMock.stubGet(cacheManagerMock, - UserRepository.infoCacheKey, jsonEncode(info)); + CacheManagerMock.stubGet( + cacheManagerMock, UserRepository.infoCacheKey, jsonEncode(info)); + + MonETSAPIClientMock.stubAuthenticate(monETSApiMock, user); - MonETSAPIClientMock.stubAuthenticate( - monETSApiMock, user); - FlutterSecureStorageMock.stubRead(secureStorageMock, key: UserRepository.passwordSecureKey, valueToReturn: ''); @@ -671,8 +652,7 @@ void main() { reason: "Check the authentication is successful"); // Stub SignetsApi answer to test only the cache retrieving - SignetsAPIClientMock.stubGetInfo( - signetsApiMock, username, defaultInfo); + SignetsAPIClientMock.stubGetInfo(signetsApiMock, username, defaultInfo); // Stub to simulate that the user has an active internet connection NetworkingServiceMock.stubHasConnectivity(networkingServiceMock); @@ -705,15 +685,15 @@ void main() { verify(cacheManagerMock.get(UserRepository.infoCacheKey)); verify(secureStorageMock.read(key: UserRepository.passwordSecureKey)); - verifyNever( - cacheManagerMock.update(UserRepository.infoCacheKey, jsonEncode(info))); + verifyNever(cacheManagerMock.update( + UserRepository.infoCacheKey, jsonEncode(info))); }); test("SignetsAPI return another info", () async { // Stub to simulate presence of info cache reset(cacheManagerMock); - CacheManagerMock.stubGet(cacheManagerMock, - UserRepository.infoCacheKey, jsonEncode(info)); + CacheManagerMock.stubGet( + cacheManagerMock, UserRepository.infoCacheKey, jsonEncode(info)); // Stub SignetsApi answer to test only the cache retrieving final ProfileStudent anotherInfo = ProfileStudent( @@ -722,8 +702,7 @@ void main() { lastName: 'Doe', permanentCode: 'DOEJ00000000'); reset(signetsApiMock); - SignetsAPIClientMock.stubGetInfo( - signetsApiMock, username, anotherInfo); + SignetsAPIClientMock.stubGetInfo(signetsApiMock, username, anotherInfo); expect(manager.info, isNull); final results = await manager.getInfo(); @@ -742,8 +721,7 @@ void main() { test("SignetsAPI return a info that already exists", () async { // Stub SignetsApi answer to test only the cache retrieving reset(signetsApiMock); - SignetsAPIClientMock.stubGetInfo( - signetsApiMock, username, info); + SignetsAPIClientMock.stubGetInfo(signetsApiMock, username, info); expect(manager.info, isNull); final results = await manager.getInfo(); @@ -755,19 +733,18 @@ void main() { verify(cacheManagerMock.get(UserRepository.infoCacheKey)); verify(secureStorageMock.read(key: UserRepository.passwordSecureKey)); - verifyNever( - cacheManagerMock.update(UserRepository.infoCacheKey, jsonEncode(info))); + verifyNever(cacheManagerMock.update( + UserRepository.infoCacheKey, jsonEncode(info))); }); test("SignetsAPI return an exception", () async { // Stub to simulate presence of info cache reset(cacheManagerMock); - CacheManagerMock.stubGet(cacheManagerMock, - UserRepository.infoCacheKey, jsonEncode(info)); + CacheManagerMock.stubGet( + cacheManagerMock, UserRepository.infoCacheKey, jsonEncode(info)); // Stub SignetsApi answer to test only the cache retrieving - SignetsAPIClientMock.stubGetInfoException( - signetsApiMock, username); + SignetsAPIClientMock.stubGetInfoException(signetsApiMock, username); expect(manager.info, isNull); expect(manager.getInfo(), throwsA(isInstanceOf())); @@ -778,7 +755,8 @@ void main() { verify(cacheManagerMock.get(UserRepository.infoCacheKey)); verify(secureStorageMock.read(key: UserRepository.passwordSecureKey)); - verify(analyticsServiceMock.logError(UserRepository.tag, any, any, any)); + verify( + analyticsServiceMock.logError(UserRepository.tag, any, any, any)); verifyNever(cacheManagerMock.update(UserRepository.infoCacheKey, any)); }); @@ -786,16 +764,15 @@ void main() { test("Cache update fail", () async { // Stub to simulate presence of session cache reset(cacheManagerMock); - CacheManagerMock.stubGet(cacheManagerMock, - UserRepository.infoCacheKey, jsonEncode(info)); + CacheManagerMock.stubGet( + cacheManagerMock, UserRepository.infoCacheKey, jsonEncode(info)); // Stub to simulate exception when updating cache CacheManagerMock.stubUpdateException( cacheManagerMock, UserRepository.infoCacheKey); // Stub SignetsApi answer to test only the cache retrieving - SignetsAPIClientMock.stubGetInfo( - signetsApiMock, username, info); + SignetsAPIClientMock.stubGetInfo(signetsApiMock, username, info); expect(manager.info, isNull); final results = await manager.getInfo(); @@ -856,7 +833,8 @@ void main() { expect(await manager.wasPreviouslyLoggedIn(), isFalse); verify(secureStorageMock.deleteAll()); - verify(analyticsServiceMock.logError(UserRepository.tag, any, any, any)); + verify( + analyticsServiceMock.logError(UserRepository.tag, any, any, any)); }); }); }); diff --git a/test/mock/managers/cache_manager_mock.dart b/test/mock/managers/cache_manager_mock.dart index 33e4923f5..9eb3a3840 100644 --- a/test/mock/managers/cache_manager_mock.dart +++ b/test/mock/managers/cache_manager_mock.dart @@ -5,7 +5,6 @@ import 'package:mockito/mockito.dart'; // Project imports: import 'package:notredame/core/managers/cache_manager.dart'; import 'package:notredame/core/utils/cache_exception.dart'; - import 'cache_manager_mock.mocks.dart'; /// Mock for the [CacheManager] diff --git a/test/mock/managers/course_repository_mock.dart b/test/mock/managers/course_repository_mock.dart index 498ddf505..f9807ad80 100644 --- a/test/mock/managers/course_repository_mock.dart +++ b/test/mock/managers/course_repository_mock.dart @@ -6,7 +6,6 @@ import 'package:mockito/mockito.dart'; // Project imports: import 'package:notredame/core/managers/course_repository.dart'; - import 'course_repository_mock.mocks.dart'; @GenerateNiceMocks([MockSpec()]) @@ -32,8 +31,7 @@ class CourseRepositoryMock extends MockCourseRepository { /// Stub the function [getCoursesActivities] of [mock] when called will return [toReturn]. static void stubGetCoursesActivities(CourseRepositoryMock mock, {List toReturn = const [], bool fromCacheOnly = false}) { - when(mock.getCoursesActivities( - fromCacheOnly: fromCacheOnly)) + when(mock.getCoursesActivities(fromCacheOnly: fromCacheOnly)) .thenAnswer((_) async => toReturn); } @@ -41,9 +39,8 @@ class CourseRepositoryMock extends MockCourseRepository { static void stubGetCoursesActivitiesException(CourseRepositoryMock mock, {Exception toThrow = const ApiException(prefix: 'ApiException'), bool fromCacheOnly = false}) { - when(mock.getCoursesActivities( - fromCacheOnly: fromCacheOnly)) - .thenAnswer((_) => Future.delayed(const Duration(milliseconds: 50)) + when(mock.getCoursesActivities(fromCacheOnly: fromCacheOnly)).thenAnswer( + (_) => Future.delayed(const Duration(milliseconds: 50)) .then((value) => throw toThrow)); } @@ -64,8 +61,7 @@ class CourseRepositoryMock extends MockCourseRepository { /// Stub the function [getCourses] of [mock] when called will return [toReturn]. static void stubGetCourses(CourseRepositoryMock mock, {List toReturn = const [], bool fromCacheOnly = false}) { - when(mock.getCourses( - fromCacheOnly: fromCacheOnly)) + when(mock.getCourses(fromCacheOnly: fromCacheOnly)) .thenAnswer((_) async => toReturn); } @@ -79,9 +75,8 @@ class CourseRepositoryMock extends MockCourseRepository { static void stubGetCoursesException(CourseRepositoryMock mock, {Exception toThrow = const ApiException(prefix: 'ApiException'), bool fromCacheOnly = false}) { - when(mock.getCourses( - fromCacheOnly: fromCacheOnly)) - .thenAnswer((_) => Future.delayed(const Duration(milliseconds: 50)) + when(mock.getCourses(fromCacheOnly: fromCacheOnly)).thenAnswer((_) => + Future.delayed(const Duration(milliseconds: 50)) .then((value) => throw toThrow)); } @@ -103,9 +98,9 @@ class CourseRepositoryMock extends MockCourseRepository { /// Stub the function [getScheduleActivities] of [mock] when called will return [toReturn]. static void stubGetScheduleActivities(CourseRepositoryMock mock, - {List toReturn = const [], bool fromCacheOnly = false}) { - when(mock.getScheduleActivities( - fromCacheOnly: fromCacheOnly)) + {List toReturn = const [], + bool fromCacheOnly = false}) { + when(mock.getScheduleActivities(fromCacheOnly: fromCacheOnly)) .thenAnswer((_) async => toReturn); } diff --git a/test/mock/managers/news_repository_mock.dart b/test/mock/managers/news_repository_mock.dart index 9c1ab1908..9cb4e7a60 100644 --- a/test/mock/managers/news_repository_mock.dart +++ b/test/mock/managers/news_repository_mock.dart @@ -1,16 +1,15 @@ -// FLUTTER / DART / THIRD-PARTIES +// Package imports: +import 'package:ets_api_clients/exceptions.dart'; +import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; -// MANAGER +// Project imports: import 'package:notredame/core/managers/news_repository.dart'; - -// MODELS import 'package:notredame/core/models/news.dart'; +import 'news_repository_mock.mocks.dart'; -// UTILS -import 'package:ets_api_clients/exceptions.dart'; - -class NewsRepositoryMock extends Mock implements NewsRepository { +@GenerateNiceMocks([MockSpec()]) +class NewsRepositoryMock extends MockNewsRepository { /// Stub the getter [news] of [mock] when called will return [toReturn]. static void stubNews(NewsRepositoryMock mock, {List toReturn = const []}) { @@ -19,19 +18,17 @@ class NewsRepositoryMock extends Mock implements NewsRepository { /// Stub the function [getNews] of [mock] when called will return [toReturn]. static void stubGetNews(NewsRepositoryMock mock, - {List toReturn = const [], bool fromCacheOnly}) { - when(mock.getNews( - fromCacheOnly: fromCacheOnly ?? anyNamed("fromCacheOnly"))) + {List toReturn = const [], bool fromCacheOnly = false}) { + when(mock.getNews(fromCacheOnly: fromCacheOnly)) .thenAnswer((_) async => toReturn); } /// Stub the function [getNews] of [mock] when called will throw [toThrow]. static void stubGetNewsException(NewsRepositoryMock mock, {Exception toThrow = const ApiException(prefix: 'ApiException'), - bool fromCacheOnly}) { - when(mock.getNews( - fromCacheOnly: fromCacheOnly ?? anyNamed("fromCacheOnly"))) - .thenAnswer((_) => Future.delayed(const Duration(milliseconds: 50)) + bool fromCacheOnly = false}) { + when(mock.getNews(fromCacheOnly: fromCacheOnly)).thenAnswer((_) => + Future.delayed(const Duration(milliseconds: 50)) .then((value) => throw toThrow)); } } diff --git a/test/mock/managers/quick_links_repository_mock.dart b/test/mock/managers/quick_links_repository_mock.dart index 485f8fa79..44affe215 100644 --- a/test/mock/managers/quick_links_repository_mock.dart +++ b/test/mock/managers/quick_links_repository_mock.dart @@ -7,7 +7,6 @@ import 'package:mockito/mockito.dart'; import 'package:notredame/core/managers/quick_link_repository.dart'; import 'package:notredame/core/models/quick_link.dart'; import 'package:notredame/core/models/quick_link_data.dart'; - import 'quick_links_repository_mock.mocks.dart'; @GenerateNiceMocks([MockSpec()]) diff --git a/test/mock/managers/settings_manager_mock.dart b/test/mock/managers/settings_manager_mock.dart index f4bc3c268..d0b4aa490 100644 --- a/test/mock/managers/settings_manager_mock.dart +++ b/test/mock/managers/settings_manager_mock.dart @@ -1,14 +1,13 @@ // Flutter imports: import 'package:flutter/material.dart'; -import 'package:mockito/annotations.dart'; // Package imports: +import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; // Project imports: import 'package:notredame/core/constants/preferences_flags.dart'; import 'package:notredame/core/managers/settings_manager.dart'; - import 'settings_manager_mock.mocks.dart'; @GenerateNiceMocks([MockSpec()]) @@ -75,7 +74,8 @@ class SettingsManagerMock extends MockSettingsManager { } /// Stub the [dateTimeNow] function of [mock], when called return [toReturn]. - static void stubDateTimeNow(SettingsManagerMock mock, {required DateTime toReturn}) { + static void stubDateTimeNow(SettingsManagerMock mock, + {required DateTime toReturn}) { // ignore: cast_nullable_to_non_nullable when(mock.dateTimeNow).thenReturn(toReturn); } diff --git a/test/mock/managers/user_repository_mock.dart b/test/mock/managers/user_repository_mock.dart index 4fdddd5d4..8ac31014c 100644 --- a/test/mock/managers/user_repository_mock.dart +++ b/test/mock/managers/user_repository_mock.dart @@ -6,7 +6,6 @@ import 'package:mockito/mockito.dart'; // Project imports: import 'package:notredame/core/managers/user_repository.dart'; - import 'user_repository_mock.mocks.dart'; /// Mock for the [UserRepository] diff --git a/test/mock/services/analytics_service_mock.dart b/test/mock/services/analytics_service_mock.dart index 4417498e6..883c9f4a7 100644 --- a/test/mock/services/analytics_service_mock.dart +++ b/test/mock/services/analytics_service_mock.dart @@ -3,7 +3,6 @@ import 'package:mockito/annotations.dart'; // Project imports: import 'package:notredame/core/services/analytics_service.dart'; - import 'analytics_service_mock.mocks.dart'; /// Mock for the [AnalyticsService] diff --git a/test/mock/services/app_widget_service_mock.dart b/test/mock/services/app_widget_service_mock.dart index d4799802e..3f7c461df 100644 --- a/test/mock/services/app_widget_service_mock.dart +++ b/test/mock/services/app_widget_service_mock.dart @@ -3,7 +3,6 @@ import 'package:mockito/annotations.dart'; // Project imports: import 'package:notredame/core/services/app_widget_service.dart'; - import 'app_widget_service_mock.mocks.dart'; /// Mock for the [AppWidgetService] diff --git a/test/mock/services/flutter_secure_storage_mock.dart b/test/mock/services/flutter_secure_storage_mock.dart index a3723bf4b..f51d7ee45 100644 --- a/test/mock/services/flutter_secure_storage_mock.dart +++ b/test/mock/services/flutter_secure_storage_mock.dart @@ -3,6 +3,7 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; +// Project imports: import 'flutter_secure_storage_mock.mocks.dart'; /// Mock for the [FlutterSecureStorage] diff --git a/test/mock/services/github_api_mock.dart b/test/mock/services/github_api_mock.dart index ee8f82130..0c2983309 100644 --- a/test/mock/services/github_api_mock.dart +++ b/test/mock/services/github_api_mock.dart @@ -10,7 +10,6 @@ import 'package:mockito/mockito.dart'; // Project imports: import 'package:notredame/core/models/feedback_issue.dart'; import 'package:notredame/core/services/github_api.dart'; - import 'github_api_mock.mocks.dart'; /// Mock for the [GithubApi] @@ -28,9 +27,11 @@ class GithubApiMock extends MockGithubApi { } static void stubCreateGithubIssue(GithubApiMock client, Issue toReturn) { - when(client.createGithubIssue(feedbackText: anyNamed("feedbackText"), - fileName: anyNamed("fileName"), feedbackType: anyNamed("feedbackType"), - email: anyNamed("email"))) + when(client.createGithubIssue( + feedbackText: anyNamed("feedbackText"), + fileName: anyNamed("fileName"), + feedbackType: anyNamed("feedbackType"), + email: anyNamed("email"))) .thenAnswer((_) async => Future.value(toReturn)); } } diff --git a/test/mock/services/home_widget_mock.dart b/test/mock/services/home_widget_mock.dart index 5e9e23373..28031eae3 100644 --- a/test/mock/services/home_widget_mock.dart +++ b/test/mock/services/home_widget_mock.dart @@ -8,7 +8,6 @@ import 'package:mockito/annotations.dart'; // Project imports: import 'package:notredame/core/services/app_widget_service.dart'; - import 'home_widget_mock.mocks.dart'; /// Pseudo-mock for the static [HomeWidget] class (mocks the channel instead) diff --git a/test/mock/services/in_app_review_service_mock.dart b/test/mock/services/in_app_review_service_mock.dart index 825ed9895..53db569e5 100644 --- a/test/mock/services/in_app_review_service_mock.dart +++ b/test/mock/services/in_app_review_service_mock.dart @@ -4,7 +4,6 @@ import 'package:mockito/mockito.dart'; // Project imports: import 'package:notredame/core/services/in_app_review_service.dart'; - import 'in_app_review_service_mock.mocks.dart'; /// Mock for the [AnalyticsService] diff --git a/test/mock/services/internal_info_service_mock.dart b/test/mock/services/internal_info_service_mock.dart index 35018fd1b..9fa8da90b 100644 --- a/test/mock/services/internal_info_service_mock.dart +++ b/test/mock/services/internal_info_service_mock.dart @@ -5,7 +5,6 @@ import 'package:package_info_plus/package_info_plus.dart'; // Project imports: import 'package:notredame/core/services/internal_info_service.dart'; - import 'internal_info_service_mock.mocks.dart'; @GenerateNiceMocks([MockSpec()]) diff --git a/test/mock/services/launch_url_service_mock.dart b/test/mock/services/launch_url_service_mock.dart index 409a8377a..6a3f85168 100644 --- a/test/mock/services/launch_url_service_mock.dart +++ b/test/mock/services/launch_url_service_mock.dart @@ -4,7 +4,6 @@ import 'package:mockito/mockito.dart'; // Project imports: import 'package:notredame/core/services/launch_url_service.dart'; - import 'launch_url_service_mock.mocks.dart'; /// Mock for the [LaunchUrlService] diff --git a/test/mock/services/navigation_service_mock.dart b/test/mock/services/navigation_service_mock.dart index ef9bb4f5a..53f438d1d 100644 --- a/test/mock/services/navigation_service_mock.dart +++ b/test/mock/services/navigation_service_mock.dart @@ -3,7 +3,6 @@ import 'package:mockito/annotations.dart'; // Project imports: import 'package:notredame/core/services/navigation_service.dart'; - import 'navigation_service_mock.mocks.dart'; /// Mock for the [NavigationService] diff --git a/test/mock/services/networking_service_mock.dart b/test/mock/services/networking_service_mock.dart index 60505d609..2b41a38aa 100644 --- a/test/mock/services/networking_service_mock.dart +++ b/test/mock/services/networking_service_mock.dart @@ -5,7 +5,6 @@ import 'package:mockito/mockito.dart'; // Project imports: import 'package:notredame/core/services/networking_service.dart'; - import 'networking_service_mock.mocks.dart'; /// Mock for the [NetworkingService] diff --git a/test/mock/services/preferences_service_mock.dart b/test/mock/services/preferences_service_mock.dart index c2b7fb0a5..b94c950de 100644 --- a/test/mock/services/preferences_service_mock.dart +++ b/test/mock/services/preferences_service_mock.dart @@ -5,7 +5,6 @@ import 'package:mockito/mockito.dart'; // Project imports: import 'package:notredame/core/constants/preferences_flags.dart'; import 'package:notredame/core/services/preferences_service.dart'; - import 'preferences_service_mock.mocks.dart'; @GenerateNiceMocks([MockSpec()]) diff --git a/test/mock/services/remote_config_service_mock.dart b/test/mock/services/remote_config_service_mock.dart index 4b01c6bad..1b518947e 100644 --- a/test/mock/services/remote_config_service_mock.dart +++ b/test/mock/services/remote_config_service_mock.dart @@ -4,7 +4,6 @@ import 'package:mockito/mockito.dart'; // Project imports: import 'package:notredame/core/services/remote_config_service.dart'; - import 'remote_config_service_mock.mocks.dart'; /// Mock for the [RemoteConfigService] diff --git a/test/mock/services/rive_animation_service_mock.dart b/test/mock/services/rive_animation_service_mock.dart index cda80059f..2b5c10753 100644 --- a/test/mock/services/rive_animation_service_mock.dart +++ b/test/mock/services/rive_animation_service_mock.dart @@ -6,7 +6,6 @@ import 'package:rive/rive.dart'; // Project imports: import 'package:notredame/core/services/rive_animation_service.dart'; import 'package:notredame/core/utils/animation_exception.dart'; - import 'rive_animation_service_mock.mocks.dart'; /// Mock for the [RiveAnimationService] diff --git a/test/mock/services/siren_flutter_service_mock.dart b/test/mock/services/siren_flutter_service_mock.dart index 7aa9652a0..fd90b7df6 100644 --- a/test/mock/services/siren_flutter_service_mock.dart +++ b/test/mock/services/siren_flutter_service_mock.dart @@ -5,7 +5,6 @@ import 'package:pub_semver/pub_semver.dart'; // Project imports: import 'package:notredame/core/services/siren_flutter_service.dart'; - import 'siren_flutter_service_mock.mocks.dart'; /// Mock for the [SirenFlutterService] diff --git a/test/models/news_test.dart b/test/models/news_test.dart index 9e2021bd4..d64a632ef 100644 --- a/test/models/news_test.dart +++ b/test/models/news_test.dart @@ -1,12 +1,10 @@ -// FLUTTER / DART / THIRD-PARTIES // ignore_for_file: avoid_dynamic_calls -import 'package:flutter/material.dart'; +// Package imports: import 'package:flutter_test/flutter_test.dart'; -// MODELS +// Project imports: import 'package:notredame/core/models/news.dart'; -import 'package:notredame/core/models/tags.dart'; void main() { group('News class tests', () { @@ -16,10 +14,7 @@ void main() { 'title': 'Test Title', 'description': 'Test Description', 'image': 'https://example.com/image.jpg', - 'tags': [ - {'text': 'Tag 1', 'color': Colors.blue.value}, - {'text': 'Tag 2', 'color': Colors.red.value}, - ], + 'tags': ['Tag 1', 'Tag 2'], 'date': '2022-01-01T12:00:00Z', }; @@ -30,10 +25,8 @@ void main() { expect(news.description, equals('Test Description')); expect(news.image, equals('https://example.com/image.jpg')); expect(news.tags.length, equals(2)); - expect(news.tags[0].text, equals('Tag 1')); - expect(news.tags[0].color, equals(Colors.blue[500])); - expect(news.tags[1].text, equals('Tag 2')); - expect(news.tags[1].color, equals(Colors.red[500])); + expect(news.tags[0], equals('Tag 1')); + expect(news.tags[1], equals('Tag 2')); expect(news.date, equals(DateTime.parse('2022-01-01T12:00:00Z'))); }); @@ -44,8 +37,8 @@ void main() { description: 'Test Description', image: 'https://example.com/image.jpg', tags: [ - Tag(text: 'Tag 1', color: Colors.blue[500]), - Tag(text: 'Tag 2', color: Colors.red[500]), + 'Tag 1', + 'Tag 2', ], date: DateTime.parse('2022-01-01T12:00:00Z'), ); @@ -57,34 +50,9 @@ void main() { expect(json['description'], equals('Test Description')); expect(json['image'], equals('https://example.com/image.jpg')); expect(json['tags'], hasLength(2)); - expect(json['tags'][0]['text'], equals('Tag 1')); - expect(json['tags'][0]['color'], equals(Colors.blue[500].value)); - expect(json['tags'][1]['text'], equals('Tag 2')); - expect(json['tags'][1]['color'], equals(Colors.red[500].value)); + expect(json['tags'][0], equals('Tag 1')); + expect(json['tags'][1], equals('Tag 2')); expect(json['date'], equals('2022-01-01 12:00:00.000Z')); }); }); - - group('Tag class tests', () { - test('Tag.fromJson() should parse JSON correctly', () { - final json = { - 'text': 'Test Tag', - 'color': Colors.blue[500].value, - }; - - final tag = Tag.fromJson(json); - - expect(tag.text, equals('Test Tag')); - expect(tag.color, equals(Colors.blue[500])); - }); - - test('toJson() should convert Tag to JSON correctly', () { - final tag = Tag(text: 'Test Tag', color: Colors.blue[500]); - - final json = tag.toJson(); - - expect(json['text'], equals('Test Tag')); - expect(json['color'], equals(Colors.blue[500].value)); - }); - }); } diff --git a/test/services/app_widget_service_test.dart b/test/services/app_widget_service_test.dart index 348b40a71..b458ca0c1 100644 --- a/test/services/app_widget_service_test.dart +++ b/test/services/app_widget_service_test.dart @@ -15,7 +15,7 @@ void main() { late HomeWidgetMock homeWidgetMock; late AppWidgetService service; - + group("AppWidgetServiceTest - ", () { setUp(() { setupAnalyticsServiceMock(); diff --git a/test/ui/views/dashboard_view_test.dart b/test/ui/views/dashboard_view_test.dart index ab1410a30..9f4b439db 100644 --- a/test/ui/views/dashboard_view_test.dart +++ b/test/ui/views/dashboard_view_test.dart @@ -142,24 +142,21 @@ void main() { Future testDashboardSchedule(WidgetTester tester, DateTime now, List courses, int expected) async { - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: courses); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); - SettingsManagerMock.stubDateTimeNow(settingsManagerMock, - toReturn: now); + SettingsManagerMock.stubDateTimeNow(settingsManagerMock, toReturn: now); - await tester.pumpWidget( - localizedWidget(child: FeatureDiscovery(child: const DashboardView(updateCode: UpdateCode.none)))); + await tester.pumpWidget(localizedWidget( + child: FeatureDiscovery( + child: const DashboardView(updateCode: UpdateCode.none)))); await tester.pumpAndSettle(); // Find schedule card in second position by its title @@ -187,53 +184,36 @@ void main() { InAppReviewServiceMock.stubIsAvailable(inAppReviewServiceMock, toReturn: false); - CourseRepositoryMock.stubSessions( - courseRepositoryMock, + CourseRepositoryMock.stubSessions(courseRepositoryMock, toReturn: [session]); - CourseRepositoryMock.stubGetSessions( - courseRepositoryMock, + CourseRepositoryMock.stubGetSessions(courseRepositoryMock, toReturn: [session]); - CourseRepositoryMock.stubActiveSessions( - courseRepositoryMock, + CourseRepositoryMock.stubActiveSessions(courseRepositoryMock, toReturn: [session]); - CourseRepositoryMock.stubCourses( - courseRepositoryMock); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubCourses(courseRepositoryMock); + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock); + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); - - RemoteConfigServiceMock.stubGetBroadcastEnabled( - remoteConfigServiceMock); - RemoteConfigServiceMock.stubGetBroadcastColor( - remoteConfigServiceMock); - RemoteConfigServiceMock.stubGetBroadcastEn( - remoteConfigServiceMock); - RemoteConfigServiceMock.stubGetBroadcastFr( - remoteConfigServiceMock); - RemoteConfigServiceMock.stubGetBroadcastTitleEn( - remoteConfigServiceMock); - RemoteConfigServiceMock.stubGetBroadcastTitleFr( - remoteConfigServiceMock); - RemoteConfigServiceMock.stubGetBroadcastType( - remoteConfigServiceMock); - RemoteConfigServiceMock.stubGetBroadcastUrl( - remoteConfigServiceMock); - - SettingsManagerMock.stubGetBool(settingsManagerMock, - PreferencesFlag.discoveryDashboard, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); + + RemoteConfigServiceMock.stubGetBroadcastEnabled(remoteConfigServiceMock); + RemoteConfigServiceMock.stubGetBroadcastColor(remoteConfigServiceMock); + RemoteConfigServiceMock.stubGetBroadcastEn(remoteConfigServiceMock); + RemoteConfigServiceMock.stubGetBroadcastFr(remoteConfigServiceMock); + RemoteConfigServiceMock.stubGetBroadcastTitleEn(remoteConfigServiceMock); + RemoteConfigServiceMock.stubGetBroadcastTitleFr(remoteConfigServiceMock); + RemoteConfigServiceMock.stubGetBroadcastType(remoteConfigServiceMock); + RemoteConfigServiceMock.stubGetBroadcastUrl(remoteConfigServiceMock); + + SettingsManagerMock.stubGetBool( + settingsManagerMock, PreferencesFlag.discoveryDashboard, toReturn: true); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.broadcastCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.broadcastCard); SettingsManagerMock.stubSetInt( settingsManagerMock, PreferencesFlag.aboutUsCard); @@ -241,14 +221,13 @@ void main() { SettingsManagerMock.stubSetInt( settingsManagerMock, PreferencesFlag.scheduleCard); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.progressBarCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.progressBarCard); SettingsManagerMock.stubSetInt( settingsManagerMock, PreferencesFlag.gradesCard); - SettingsManagerMock.stubDateTimeNow( - settingsManagerMock, + SettingsManagerMock.stubDateTimeNow(settingsManagerMock, toReturn: DateTime.now()); }); @@ -257,12 +236,12 @@ void main() { group('UI - ', () { testWidgets('Has view title restore button and cards, displayed', (WidgetTester tester) async { - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); await tester.pumpWidget(localizedWidget( - child: FeatureDiscovery(child: const DashboardView(updateCode: UpdateCode.none)))); + child: FeatureDiscovery( + child: const DashboardView(updateCode: UpdateCode.none)))); await tester.pumpAndSettle(); // Find Dashboard Title @@ -283,22 +262,19 @@ void main() { testWidgets('Has card aboutUs displayed properly', (WidgetTester tester) async { - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: activities); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); await tester.pumpWidget(localizedWidget( - child: FeatureDiscovery(child: const DashboardView(updateCode: UpdateCode.none)))); + child: FeatureDiscovery( + child: const DashboardView(updateCode: UpdateCode.none)))); await tester.pumpAndSettle(); // Find aboutUs card @@ -382,36 +358,33 @@ void main() { group('Interactions - ', () { testWidgets('AboutUsCard is dismissible and can be restored', (WidgetTester tester) async { - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock); + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.broadcastCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.broadcastCard); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.aboutUsCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.aboutUsCard); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.scheduleCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.scheduleCard); SettingsManagerMock.stubSetInt( settingsManagerMock, PreferencesFlag.gradesCard); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.progressBarCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.progressBarCard); await tester.pumpWidget(localizedWidget( - child: FeatureDiscovery(child: const DashboardView(updateCode: UpdateCode.none)))); + child: FeatureDiscovery( + child: const DashboardView(updateCode: UpdateCode.none)))); await tester.pumpAndSettle(); // Find Dismissible Cards @@ -442,35 +415,32 @@ void main() { testWidgets('AboutUsCard is reorderable and can be restored', (WidgetTester tester) async { - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.broadcastCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.broadcastCard); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.aboutUsCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.aboutUsCard); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.scheduleCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.scheduleCard); SettingsManagerMock.stubSetInt( settingsManagerMock, PreferencesFlag.gradesCard); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.progressBarCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.progressBarCard); await tester.pumpWidget(localizedWidget( - child: FeatureDiscovery(child: const DashboardView(updateCode: UpdateCode.none)))); + child: FeatureDiscovery( + child: const DashboardView(updateCode: UpdateCode.none)))); await tester.pumpAndSettle(); // Find Dismissible Cards @@ -526,12 +496,12 @@ void main() { testWidgets('ScheduleCard is dismissible and can be restored', (WidgetTester tester) async { - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); await tester.pumpWidget(localizedWidget( - child: FeatureDiscovery(child: const DashboardView(updateCode: UpdateCode.none)))); + child: FeatureDiscovery( + child: const DashboardView(updateCode: UpdateCode.none)))); await tester.pumpAndSettle(); // Find Dismissible Cards @@ -567,12 +537,12 @@ void main() { group('UI - gradesCard', () { testWidgets('Has card grades displayed - with no courses', (WidgetTester tester) async { - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); await tester.pumpWidget(localizedWidget( - child: FeatureDiscovery(child: const DashboardView(updateCode: UpdateCode.none)))); + child: FeatureDiscovery( + child: const DashboardView(updateCode: UpdateCode.none)))); await tester.pumpAndSettle(); // Find grades card @@ -593,23 +563,19 @@ void main() { testWidgets('Has card grades displayed - with courses', (WidgetTester tester) async { - CourseRepositoryMock.stubCourses( - courseRepositoryMock, - toReturn: courses); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, - fromCacheOnly: true, + CourseRepositoryMock.stubCourses(courseRepositoryMock, toReturn: courses); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, + fromCacheOnly: true, toReturn: courses); + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, toReturn: courses); - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); await tester.pumpWidget(localizedWidget( - child: FeatureDiscovery(child: const DashboardView(updateCode: UpdateCode.none)))); + child: FeatureDiscovery( + child: const DashboardView(updateCode: UpdateCode.none)))); await tester.pumpAndSettle(); // Find grades card @@ -628,26 +594,26 @@ void main() { testWidgets('gradesCard is dismissible and can be restored', (WidgetTester tester) async { - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.broadcastCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.broadcastCard); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.aboutUsCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.aboutUsCard); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.scheduleCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.scheduleCard); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.progressBarCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.progressBarCard); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.gradesCard); - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.gradesCard); + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); await tester.pumpWidget(localizedWidget( - child: FeatureDiscovery(child: const DashboardView(updateCode: UpdateCode.none)))); + child: FeatureDiscovery( + child: const DashboardView(updateCode: UpdateCode.none)))); await tester.pumpAndSettle(); // Find Dismissible Cards @@ -684,12 +650,12 @@ void main() { group("UI - progressBar", () { testWidgets('Has card progressBar displayed', (WidgetTester tester) async { - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); await tester.pumpWidget(localizedWidget( - child: FeatureDiscovery(child: const DashboardView(updateCode: UpdateCode.none)))); + child: FeatureDiscovery( + child: const DashboardView(updateCode: UpdateCode.none)))); await tester.pumpAndSettle(); // Find progress card @@ -707,12 +673,12 @@ void main() { testWidgets('progressCard is dismissible and can be restored', (WidgetTester tester) async { - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); await tester.pumpWidget(localizedWidget( - child: FeatureDiscovery(child: const DashboardView(updateCode: UpdateCode.none)))); + child: FeatureDiscovery( + child: const DashboardView(updateCode: UpdateCode.none)))); await tester.pumpAndSettle(); // Find Dismissible Cards @@ -745,12 +711,12 @@ void main() { testWidgets('progressBarCard is reorderable and can be restored', (WidgetTester tester) async { InAppReviewServiceMock.stubIsAvailable(inAppReviewServiceMock); - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); await tester.pumpWidget(localizedWidget( - child: FeatureDiscovery(child: const DashboardView(updateCode: UpdateCode.none)))); + child: FeatureDiscovery( + child: const DashboardView(updateCode: UpdateCode.none)))); await tester.pumpAndSettle(); // Find Dismissible Cards @@ -811,8 +777,7 @@ void main() { }); testWidgets("Applets Card", (WidgetTester tester) async { - RemoteConfigServiceMock.stubGetBroadcastEnabled( - remoteConfigServiceMock, + RemoteConfigServiceMock.stubGetBroadcastEnabled(remoteConfigServiceMock, toReturn: false); tester.binding.window.physicalSizeTestValue = const Size(800, 1410); @@ -821,12 +786,12 @@ void main() { PreferencesFlag.aboutUsCard: 1, }; - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); await tester.pumpWidget(localizedWidget( - child: FeatureDiscovery(child: const DashboardView(updateCode: UpdateCode.none)))); + child: FeatureDiscovery( + child: const DashboardView(updateCode: UpdateCode.none)))); await tester.pumpAndSettle(); await expectLater(find.byType(DashboardView), @@ -834,38 +799,33 @@ void main() { }); testWidgets("Schedule card", (WidgetTester tester) async { - RemoteConfigServiceMock.stubGetBroadcastEnabled( - remoteConfigServiceMock, + RemoteConfigServiceMock.stubGetBroadcastEnabled(remoteConfigServiceMock, toReturn: false); tester.binding.window.physicalSizeTestValue = const Size(800, 1410); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); dashboard = { PreferencesFlag.broadcastCard: 0, PreferencesFlag.scheduleCard: 1, }; - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); await tester.pumpWidget(localizedWidget( - child: FeatureDiscovery(child: const DashboardView(updateCode: UpdateCode.none)))); + child: FeatureDiscovery( + child: const DashboardView(updateCode: UpdateCode.none)))); await tester.pumpAndSettle(); await expectLater(find.byType(DashboardView), matchesGoldenFile(goldenFilePath("dashboardView_scheduleCard_1"))); }); testWidgets("progressBar Card", (WidgetTester tester) async { - RemoteConfigServiceMock.stubGetBroadcastEnabled( - remoteConfigServiceMock, + RemoteConfigServiceMock.stubGetBroadcastEnabled(remoteConfigServiceMock, toReturn: false); tester.binding.window.physicalSizeTestValue = const Size(800, 1410); @@ -874,12 +834,12 @@ void main() { PreferencesFlag.progressBarCard: 1, }; - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); await tester.pumpWidget(localizedWidget( - child: FeatureDiscovery(child: const DashboardView(updateCode: UpdateCode.none)))); + child: FeatureDiscovery( + child: const DashboardView(updateCode: UpdateCode.none)))); await tester.pumpAndSettle(); await expectLater( diff --git a/test/ui/views/ets_view_test.dart b/test/ui/views/ets_view_test.dart index 87842d3e8..56652c33c 100644 --- a/test/ui/views/ets_view_test.dart +++ b/test/ui/views/ets_view_test.dart @@ -2,10 +2,10 @@ import 'dart:io'; // Flutter imports: -import 'package:feature_discovery/feature_discovery.dart'; import 'package:flutter/material.dart'; // Package imports: +import 'package:feature_discovery/feature_discovery.dart'; import 'package:flutter_test/flutter_test.dart'; // Project imports: @@ -13,7 +13,6 @@ import 'package:notredame/core/managers/course_repository.dart'; import 'package:notredame/core/managers/news_repository.dart'; import 'package:notredame/core/managers/settings_manager.dart'; import 'package:notredame/core/models/news.dart'; -import 'package:notredame/core/models/tags.dart'; import 'package:notredame/core/services/analytics_service.dart'; import 'package:notredame/core/services/navigation_service.dart'; import 'package:notredame/core/services/networking_service.dart'; @@ -32,10 +31,10 @@ void main() { "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tempus arcu sed quam tincidunt, non venenatis orci mollis.", description: "Test 1 description", date: DateTime.now(), - image: null, - tags: [ - Tag(text: "tag1", color: Colors.blue), - Tag(text: "tag2", color: Colors.green), + image: "", + tags: [ + "tag1", + "tag2", ], ), News( @@ -43,10 +42,10 @@ void main() { title: "Test 2", description: "Test 2 description", date: DateTime.now(), - image: null, - tags: [ - Tag(text: "tag1", color: Colors.blue), - Tag(text: "tag2", color: Colors.green), + image: "", + tags: [ + "tag1", + "tag2", ], ), News( @@ -54,10 +53,10 @@ void main() { title: "Test 3", description: "Test 3 description", date: DateTime.now(), - image: null, - tags: [ - Tag(text: "tag1", color: Colors.blue), - Tag(text: "tag2", color: Colors.green), + image: "", + tags: [ + "tag1", + "tag2", ], ), ]; diff --git a/test/ui/views/faq_view_test.dart b/test/ui/views/faq_view_test.dart index 066a17ba5..550730773 100644 --- a/test/ui/views/faq_view_test.dart +++ b/test/ui/views/faq_view_test.dart @@ -1,5 +1,7 @@ -// Flutter imports: +// Dart imports: import 'dart:io'; + +// Flutter imports: import 'package:flutter/material.dart'; // Package imports: diff --git a/test/ui/views/goldenFiles/etsView_1.png b/test/ui/views/goldenFiles/etsView_1.png new file mode 100644 index 0000000000000000000000000000000000000000..8ecc96c1f2cb53b080c4c8fdbd646fab3a204590 GIT binary patch literal 3378 zcmeHKX;f2577jEj3WyFp(9%L2T(Ad38)Xp)DAFtqf{5&!B1lUVL`aB0h{(9m5oomq zWeG=6G6+f70>~CoAs|b@5ENq)BuXG5KqLu)Z1b?E^~Y$7|L2|aoqDh8)UCSrzWTmf znTI@GwASda0f9hTZmv#;K_C?k0K@7lfu5tH%2J?FNjU7{2*USooCH495**!*r~^-` zdgK)lNb{AO)BYofLO#R$)XgXiS%7lKZZfZp>N15UUM_i7bj#zHmKP&uRC=8~Ece&z z_39I*R)it;KS8_=1O2#VOLN#EM(?Z26F-JkW;);7vQ4M<@NrkT+qaGp@Qk&EtGAS} z>uQZkY0p~ov(&jW!j^m3*@Z34jZ6;Tr(Zyy|AB+_q`VAIGYZ9@N zG&ULO?sGCde(+m6V3H?PBb`J1q%#+=Css+jcoCy&s_y@l zHV_WzviYROK{5G!$D^Bnu6CEr3f$9Ym^V-q61dFWe0G~(9&lwjdW{zJdWKi-OiL=` z$3r0QF>rVpk1R3^^+r~ty%JjoY!Ce&y)@d-mj=?=eln39_L>wnu^8_lS$It3>M4iB zjUA(7-Osr<8WcEwynCE75UD6o?wN-A$sapVCRg?JD$@dLcZVODsrkF;9IvQp(zt+b zPxcSIv>Xo;`B{;z?*2pCX^Jy+c5bSYqSw)=AW7Wl$92(LSxRq)kV=B4gaF2ADRbIc z(tM1f;H9CDuP;(gqdpI(HPkKoF>M+WQelQr)I#?uaHUp(8J?M z1?_%$dAUvenA44fZ*1yLQp@h&4cQXY+-FJQ7Tm!?5=B@eSKjviNFRid$ee8LRtN3x}TT*LZp^voyd%F+gcarR{@`T z;SDt6sS%&j($a)mHdVism6dTHrhj8$Y3XO1G+kL_n^ZQ~#rz#MF>t4egGq^rjJ)ev zY`^2%DpxH{%^_xM3a==MS$@OVYdCjDa7;|hKlPvWAbM&-7{Z4(+h9zq zW>>CS#e16 z1s#CXaw|h=R<(8F#34St!E5`djg`6iVILnKB2p^00bH})?Eh&zJohpLa0@yWfusA%9NJ6SmB0!1JYVaDo-Igk|b(9@eHyayaiGq*Tg z;Dy!E(Gd+C(56jNv4n25^y&CFUDxyt3~)YJPoz8tFT+xSMQMQBgudSM_?mNb<3Y`E zzAwSdthwe^e*XPCckbjD7Pge>s5Ox*2yH!;*RDfACjDEyc{PAnJFGHPEbQz;;@TF*qjEym zqb;DrAyhXNbcTt>=$ed-4A^+@?H}u4 zbJ9#~q+v7#gNrUk!u#3Jal!uDcC!yJAmzRlel#)|bxO98F+mB(vXrzvhUkn{+VDMX z>QnT{Wpr0H6r2wZVGMk3Lm`eKy>@)>JZ)v*J?WGewR zrHz4{XAn<~)JP;*z|C491bAwCuEd(Bw8e<$5Gf<^9QvEq|W2<(tRoJ znMw)&o^$T5IUJ*h+OZCu^}SU+@%Qh*;F-mM%D~z(9EU4gm_r-sGG-TRmqisPWzID> zz9gr|t!Mhx4<+uR zxJ48tm!c?jkTZS7q9f3?&1WgFSA=PKn4F(O)YAQ#9ryIYHY6bUFz!&fM8ae;n-V9V zwHS~hI(}`M>$hdI3C31VrrCy&AU2yV5F{~R{;ksK<~ew(PVu;?eHD1<#fyMc+3f5Y z1BbL!X7&=p019nwZx4I@=wkBgi+W>hj`RT?h%UXlF)R#)=cRwT27hx2;iHRw&ZSjA zft(5i97=HBPHO}z2DgYl(!G~x97X}&FC2<4ws$%;i;NAmr`^nP@?|AgW Fe*gt7-z@+D literal 0 HcmV?d00001 diff --git a/test/ui/views/goldenFiles/newsView_1.png b/test/ui/views/goldenFiles/newsView_1.png new file mode 100644 index 0000000000000000000000000000000000000000..9ff3b2f28fd4c4a8fe72c96d238ac9d54da7ecee GIT binary patch literal 1534 zcmeAS@N?(olHy`uVBq!ia0y~yVB`kkYaDDqk%X^n76U29;vjb?hIQv;UIIBR#ZI0f z96(URk vGyG2wb4VIRqaiRF0;3@?8UpkUflmxkn>jrCt5zid%WwuyS3j3^P6{0nZcnUWiahJ{&ZeuC*#XI_Q8xuS#u=6n-Le*)zxLt>#4V!n+0mMI{NAX(BX%R z&(q1`dx8yB6wamy_QC)zE^c$xPV#0^$ukv+OlH@)kJe**uc@axJ?V(<7vdem0(LHD(cw^9 ztxbm%D-yU{kw!Ujze*{@pAL7gcrF6f>MX;rfeE1rp!4P-1&W%JlLL2W8}BYK^$Urd zzW3$XfK(b!aO%$%fXho~OEMRaCP@N*C6&B9dhp)wvKTk_j8jVI^ z<5%%P{v|4TA(8`2X%7QD5lz}rNErv&F6n2(?YwWvf zgC?sJ{Px&_DStr2jT7=4(wg}Z9OrRfbWd+@Z^fwqzdpz*AInB!s-k`O-ShDZGcAY>ZcOPt@AX(r zN0hPAyHBh|ZU7Ko0p=&5wnTsTFJ`}LKa^4ZuB!t*4jtCL^P5zv86ah3WGs?>#HFw8 z>jzL<8LMT|ZcKAmJdSNbU($98R4+`atgNW0_(Hdhz6P2SXc&%8x};L+^DW+MJ)Di) z3JdVsLjIEfe<|>D14XMUgZGpsVY~utAfWNt$9s48duXq40^*0|>RG?#9h6sq`C+-< l*zsCZ-q`V news = [ News( @@ -30,10 +29,10 @@ void main() { "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tempus arcu sed quam tincidunt, non venenatis orci mollis.", description: "Test 1 description", date: DateTime.now(), - image: null, - tags: [ - Tag(text: "tag1", color: Colors.blue), - Tag(text: "tag2", color: Colors.green), + image: "", + tags: [ + "tag1", + "tag2", ], ), News( @@ -41,10 +40,10 @@ void main() { title: "Test 2", description: "Test 2 description", date: DateTime.now(), - image: null, - tags: [ - Tag(text: "tag1", color: Colors.blue), - Tag(text: "tag2", color: Colors.green), + image: "", + tags: [ + "tag1", + "tag2", ], ), News( @@ -52,10 +51,10 @@ void main() { title: "Test 3", description: "Test 3 description", date: DateTime.now(), - image: null, - tags: [ - Tag(text: "tag1", color: Colors.blue), - Tag(text: "tag2", color: Colors.green), + image: "", + tags: [ + "tag1", + "tag2", ], ), ]; @@ -103,7 +102,7 @@ void main() { NewsRepositoryMock.stubNews(newsRepository, toReturn: news); await tester.pumpWidget(localizedWidget(child: NewsView())); - await tester.pumpAndSettle(const Duration(seconds: 1)); + await tester.pumpAndSettle(const Duration(seconds: 5)); expect(find.byType(RefreshIndicator), findsOneWidget); diff --git a/test/ui/views/not_found_view_test.dart b/test/ui/views/not_found_view_test.dart index 0c26d61bb..71d93683f 100644 --- a/test/ui/views/not_found_view_test.dart +++ b/test/ui/views/not_found_view_test.dart @@ -6,10 +6,10 @@ import 'package:flutter/material.dart'; // Package imports: import 'package:flutter_test/flutter_test.dart'; +import 'package:rive/rive.dart'; // Project imports: import 'package:notredame/ui/views/not_found_view.dart'; -import 'package:rive/rive.dart'; import '../../helpers.dart'; import '../../mock/services/rive_animation_service_mock.dart'; @@ -20,7 +20,8 @@ void main() { setupNavigationServiceMock(); setupAnalyticsServiceMock(); final riveAnimationMock = setupRiveAnimationServiceMock(); - RiveAnimationServiceMock.stubLoadRiveFile(riveAnimationMock, 'dot_jumping', RuntimeArtboard()); + RiveAnimationServiceMock.stubLoadRiveFile( + riveAnimationMock, 'dot_jumping', RuntimeArtboard()); }); tearDown(() {}); diff --git a/test/ui/views/profile_view_test.dart b/test/ui/views/profile_view_test.dart index 201063094..fa98c8efd 100644 --- a/test/ui/views/profile_view_test.dart +++ b/test/ui/views/profile_view_test.dart @@ -49,8 +49,7 @@ void main() { UserRepositoryMock.stubGetInfo(userRepositoryMock, toReturn: profileStudent); - UserRepositoryMock.stubProfileStudent( - userRepositoryMock, + UserRepositoryMock.stubProfileStudent(userRepositoryMock, toReturn: profileStudent); UserRepositoryMock.stubGetPrograms(userRepositoryMock, diff --git a/test/ui/views/quick_links_view_test.dart b/test/ui/views/quick_links_view_test.dart index ccc1f5b79..31c3d112a 100644 --- a/test/ui/views/quick_links_view_test.dart +++ b/test/ui/views/quick_links_view_test.dart @@ -36,8 +36,7 @@ void main() { setupNetworkingServiceMock(); setupLaunchUrlServiceMock(); quickLinkRepositoryMock = setupQuickLinkRepositoryMock(); - QuickLinkRepositoryMock.stubGetDefaultQuickLinks( - quickLinkRepositoryMock, + QuickLinkRepositoryMock.stubGetDefaultQuickLinks(quickLinkRepositoryMock, toReturn: quickLinks(intl)); QuickLinkRepositoryMock.stubGetQuickLinkDataFromCacheException( diff --git a/test/ui/views/schedule_view_test.dart b/test/ui/views/schedule_view_test.dart index eea0269b5..6ed30a37c 100644 --- a/test/ui/views/schedule_view_test.dart +++ b/test/ui/views/schedule_view_test.dart @@ -93,8 +93,7 @@ void main() { PreferencesFlag.scheduleListView: true, }; - CourseRepositoryMock.stubGetScheduleActivities( - courseRepositoryMock); + CourseRepositoryMock.stubGetScheduleActivities(courseRepositoryMock); RemoteConfigServiceMock.stubGetCalendarViewEnabled( remoteConfigServiceMock); }); @@ -104,20 +103,14 @@ void main() { (WidgetTester tester) async { tester.binding.window.physicalSizeTestValue = const Size(800, 1410); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock); + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settings); await tester.pumpWidget(localizedWidget( @@ -131,26 +124,20 @@ void main() { testWidgets("default view (no events), showTodayButton disabled", (WidgetTester tester) async { - SettingsManagerMock.stubGetBool(settingsManagerMock, - PreferencesFlag.discoverySchedule); + SettingsManagerMock.stubGetBool( + settingsManagerMock, PreferencesFlag.discoverySchedule); tester.binding.window.physicalSizeTestValue = const Size(800, 1410); settings[PreferencesFlag.scheduleShowTodayBtn] = false; - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock); + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settings); await tester.pumpWidget(localizedWidget( @@ -165,21 +152,15 @@ void main() { testWidgets("view with events, day with events selected", (WidgetTester tester) async { tester.binding.window.physicalSizeTestValue = const Size(800, 1410); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: [activityYesterday, activityToday, activityTomorrow]); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock); + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settings); await tester.pumpWidget(localizedWidget( @@ -197,21 +178,15 @@ void main() { (WidgetTester tester) async { tester.binding.window.physicalSizeTestValue = const Size(800, 1410); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: [activityYesterday, activityTomorrow]); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock); + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settings); await tester.pumpWidget(localizedWidget( @@ -227,21 +202,15 @@ void main() { (WidgetTester tester) async { tester.binding.window.physicalSizeTestValue = const Size(800, 1410); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: [activityYesterday, activityTomorrow]); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock); + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settings); final testingDate = DateTime(2020); @@ -282,21 +251,15 @@ void main() { (WidgetTester tester) async { tester.binding.window.physicalSizeTestValue = const Size(800, 1410); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: [activityToday]); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock); - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock); + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settings); await tester.pumpWidget(localizedWidget( @@ -335,21 +298,15 @@ void main() { (WidgetTester tester) async { tester.binding.window.physicalSizeTestValue = const Size(800, 1410); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: [activityToday]); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock); - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock); + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settings); await tester.pumpWidget(localizedWidget( diff --git a/test/ui/views/student_view_test.dart b/test/ui/views/student_view_test.dart index 6bb1cf6e8..8cb497f38 100644 --- a/test/ui/views/student_view_test.dart +++ b/test/ui/views/student_view_test.dart @@ -29,12 +29,9 @@ void main() { setupSettingsManagerMock(); setupAnalyticsServiceMock(); - CourseRepositoryMock.stubCourses( - courseRepositoryMock); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubCourses(courseRepositoryMock); + CourseRepositoryMock.stubGetCourses(courseRepositoryMock); + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, fromCacheOnly: true); }); diff --git a/test/ui/widgets/bottom_bar_test.dart b/test/ui/widgets/bottom_bar_test.dart index 179a240da..dc069a22e 100644 --- a/test/ui/widgets/bottom_bar_test.dart +++ b/test/ui/widgets/bottom_bar_test.dart @@ -71,8 +71,8 @@ void main() { await tester.tap(find.byIcon(Icons.schedule)); await tester.tap(find.byIcon(Icons.dashboard)); - verify( - navigationServiceMock.pushNamedAndRemoveUntil(RouterPaths.dashboard)); + verify(navigationServiceMock + .pushNamedAndRemoveUntil(RouterPaths.dashboard)); }); testWidgets('schedule', (WidgetTester tester) async { @@ -82,7 +82,8 @@ void main() { await tester.tap(find.byIcon(Icons.schedule)); - verify(navigationServiceMock.pushNamedAndRemoveUntil(RouterPaths.schedule)); + verify(navigationServiceMock + .pushNamedAndRemoveUntil(RouterPaths.schedule)); }); testWidgets('student', (WidgetTester tester) async { @@ -92,7 +93,8 @@ void main() { await tester.tap(find.byIcon(Icons.school)); - verify(navigationServiceMock.pushNamedAndRemoveUntil(RouterPaths.student)); + verify( + navigationServiceMock.pushNamedAndRemoveUntil(RouterPaths.student)); }); testWidgets('ets', (WidgetTester tester) async { diff --git a/test/ui/widgets/grade_button_test.dart b/test/ui/widgets/grade_button_test.dart index 3ba4dafe1..e6e1f3deb 100644 --- a/test/ui/widgets/grade_button_test.dart +++ b/test/ui/widgets/grade_button_test.dart @@ -70,12 +70,11 @@ void main() { testWidgets("Display acronym of the course and the current grade", (WidgetTester tester) async { SettingsManagerMock.stubGetString( - settingsManagerMock, - PreferencesFlag.discoveryStudentGrade, + settingsManagerMock, PreferencesFlag.discoveryStudentGrade, toReturn: 'true'); - await tester.pumpWidget(localizedWidget( - child: GradeButton(courseWithGrade))); + await tester + .pumpWidget(localizedWidget(child: GradeButton(courseWithGrade))); await tester.pumpAndSettle(); expect(find.text(courseWithGrade.acronym), findsOneWidget); @@ -85,12 +84,11 @@ void main() { testWidgets("Grade not available and summary is loaded.", (WidgetTester tester) async { SettingsManagerMock.stubGetString( - settingsManagerMock, - PreferencesFlag.discoveryStudentGrade, + settingsManagerMock, PreferencesFlag.discoveryStudentGrade, toReturn: 'true'); - await tester.pumpWidget(localizedWidget( - child: GradeButton(courseWithSummary))); + await tester + .pumpWidget(localizedWidget(child: GradeButton(courseWithSummary))); await tester.pumpAndSettle(); expect(find.text(courseWithGrade.acronym), findsOneWidget); @@ -106,12 +104,11 @@ void main() { testWidgets("Grade and summary not available.", (WidgetTester tester) async { SettingsManagerMock.stubGetString( - settingsManagerMock, - PreferencesFlag.discoveryStudentGrade, + settingsManagerMock, PreferencesFlag.discoveryStudentGrade, toReturn: 'true'); - await tester.pumpWidget(localizedWidget( - child: GradeButton(gradesNotAvailable))); + await tester.pumpWidget( + localizedWidget(child: GradeButton(gradesNotAvailable))); await tester.pumpAndSettle(); expect(find.text(courseWithGrade.acronym), findsOneWidget); @@ -125,11 +122,11 @@ void main() { group('Interactions - ', () { testWidgets('Grade button redirects to grades view when tapped ', (WidgetTester tester) async { - SettingsManagerMock.stubGetBool(settingsManagerMock, - PreferencesFlag.discoveryStudentGrade, + SettingsManagerMock.stubGetBool( + settingsManagerMock, PreferencesFlag.discoveryStudentGrade, toReturn: true); - await tester.pumpWidget(localizedWidget( - child: GradeButton(courseWithGrade))); + await tester + .pumpWidget(localizedWidget(child: GradeButton(courseWithGrade))); await tester.pumpAndSettle(); await tester.tap(find.text(courseWithGrade.acronym)); @@ -141,8 +138,8 @@ void main() { testWidgets( 'Grade button does not redirect to grades view if the grades discovery did not already launch', (WidgetTester tester) async { - await tester.pumpWidget(localizedWidget( - child: GradeButton(courseWithGrade))); + await tester + .pumpWidget(localizedWidget(child: GradeButton(courseWithGrade))); await tester.pumpAndSettle(); await tester.tap(find.text(courseWithGrade.acronym)); diff --git a/test/ui/widgets/grade_evaluation_tile_test.dart b/test/ui/widgets/grade_evaluation_tile_test.dart index 5d171876d..91e56317e 100644 --- a/test/ui/widgets/grade_evaluation_tile_test.dart +++ b/test/ui/widgets/grade_evaluation_tile_test.dart @@ -65,8 +65,7 @@ void main() { await tester.pumpWidget(localizedWidget( child: FeatureDiscovery( - child: GradeEvaluationTile(evaluation, - completed: true)))); + child: GradeEvaluationTile(evaluation, completed: true)))); await tester.pumpAndSettle(); final circularPercentIndicator = find.byType(GradeCircularProgress); @@ -85,8 +84,7 @@ void main() { final widget = localizedWidget( child: FeatureDiscovery( - child: GradeEvaluationTile(evaluation, - completed: true))); + child: GradeEvaluationTile(evaluation, completed: true))); await tester.pumpWidget(widget); diff --git a/test/ui/widgets/news_card_test.dart b/test/ui/widgets/news_card_test.dart index 718ffdfe4..337490e11 100644 --- a/test/ui/widgets/news_card_test.dart +++ b/test/ui/widgets/news_card_test.dart @@ -1,11 +1,12 @@ -// Package imports: +// Flutter imports: import 'package:flutter/material.dart'; + +// Package imports: import 'package:flutter_test/flutter_test.dart'; -import 'package:notredame/core/models/news.dart'; -import 'package:notredame/core/models/tags.dart'; -import 'package:notredame/ui/widgets/news_card.dart'; // Project imports: +import 'package:notredame/core/models/news.dart'; +import 'package:notredame/ui/widgets/news_card.dart'; import '../../helpers.dart'; void main() { @@ -14,10 +15,10 @@ void main() { title: "Test 3", description: "Test 3 description", date: DateTime.now(), - image: null, - tags: [ - Tag(text: "tag1", color: Colors.blue), - Tag(text: "tag2", color: Colors.green), + image: "", + tags: [ + "tag1", + "tag2", ], ); diff --git a/test/ui/widgets/news_skeleton_test.dart b/test/ui/widgets/news_skeleton_test.dart new file mode 100644 index 000000000..27df32854 --- /dev/null +++ b/test/ui/widgets/news_skeleton_test.dart @@ -0,0 +1,21 @@ +// Package imports: +import 'package:flutter_test/flutter_test.dart'; +import 'package:shimmer/shimmer.dart'; + +// Project imports: +import 'package:notredame/ui/widgets/news_card_skeleton.dart'; +import '../../helpers.dart'; + +void main() { + group('News card skeleton Tests', () { + setUpAll(() async { + await setupAppIntl(); + }); + + testWidgets('Displays a news card skeleton', (WidgetTester tester) async { + await tester.pumpWidget(localizedWidget(child: NewsCardSkeleton())); + + expect(find.byType(Shimmer), findsNWidgets(2)); + }); + }); +} diff --git a/test/ui/widgets/password_text_field_test.dart b/test/ui/widgets/password_text_field_test.dart index 7a2938ea9..b6b937e8b 100644 --- a/test/ui/widgets/password_text_field_test.dart +++ b/test/ui/widgets/password_text_field_test.dart @@ -26,8 +26,7 @@ void main() { testWidgets('has a label, the visibility icon and obscure text', (WidgetTester tester) async { - await tester - .pumpWidget(localizedWidget(child: passwordFormField)); + await tester.pumpWidget(localizedWidget(child: passwordFormField)); await tester.pumpAndSettle(); final icon = find.byIcon(Icons.visibility); @@ -41,8 +40,7 @@ void main() { testWidgets( 'toggling the visibility button should disable the obscureText property', (WidgetTester tester) async { - await tester - .pumpWidget(localizedWidget(child: passwordFormField)); + await tester.pumpWidget(localizedWidget(child: passwordFormField)); await tester.pumpAndSettle(); await tester.tap(find.byIcon(Icons.visibility)); @@ -60,8 +58,7 @@ void main() { testWidgets( 'toggling the visibility button two times should enable the obscureText property', (WidgetTester tester) async { - await tester - .pumpWidget(localizedWidget(child: passwordFormField)); + await tester.pumpWidget(localizedWidget(child: passwordFormField)); await tester.pumpAndSettle(); await tester.tap(find.byIcon(Icons.visibility)); diff --git a/test/ui/widgets/schedule_settings_test.dart b/test/ui/widgets/schedule_settings_test.dart index da1389fd5..e2e8e8d3c 100644 --- a/test/ui/widgets/schedule_settings_test.dart +++ b/test/ui/widgets/schedule_settings_test.dart @@ -76,20 +76,18 @@ void main() { group("ScheduleSettings - ", () { setUp(() async { settingsManagerMock = setupSettingsManagerMock(); - courseRepositoryMock = - setupCourseRepositoryMock(); - remoteConfigServiceMock = - setupRemoteConfigServiceMock(); + courseRepositoryMock = setupCourseRepositoryMock(); + remoteConfigServiceMock = setupRemoteConfigServiceMock(); intl = await setupAppIntl(); CourseRepositoryMock.stubGetScheduleActivities(courseRepositoryMock); - RemoteConfigServiceMock.stubGetCalendarViewEnabled(remoteConfigServiceMock); + RemoteConfigServiceMock.stubGetCalendarViewEnabled( + remoteConfigServiceMock); }); group("ui - ", () { testWidgets("With handle", (WidgetTester tester) async { - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settings); await tester .pumpWidget(localizedWidget(child: const ScheduleSettings())); @@ -175,8 +173,7 @@ void main() { }); testWidgets("Without handle", (WidgetTester tester) async { - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settings); await tester.pumpWidget( @@ -265,8 +262,7 @@ void main() { testWidgets( "Should display activity selection section when a course has activities", (WidgetTester tester) async { - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settings); CourseRepositoryMock.stubGetScheduleActivities(courseRepositoryMock, toReturn: classOneWithLaboratoryABscheduleActivities); @@ -302,16 +298,13 @@ void main() { testWidgets( "When a settings laboratory is already selected, verify that it is in fact preselected", (WidgetTester tester) async { - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settings); CourseRepositoryMock.stubGetScheduleActivities(courseRepositoryMock, toReturn: classOneWithLaboratoryABscheduleActivities); // preselect the laboB - SettingsManagerMock.stubGetDynamicString( - settingsManagerMock, - PreferencesFlag.scheduleLaboratoryGroup, - "GEN101", + SettingsManagerMock.stubGetDynamicString(settingsManagerMock, + PreferencesFlag.scheduleLaboratoryGroup, "GEN101", toReturn: ActivityCode.labGroupB); const scheduleSettings = ScheduleSettings(showHandle: false); @@ -339,8 +332,7 @@ void main() { testWidgets( "if there is only a laboA (no labo b) the options should not appear on screen", (WidgetTester tester) async { - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settings); final courseWithOnlyLabA = List.from( classOneWithLaboratoryABscheduleActivities); @@ -367,12 +359,10 @@ void main() { group("interactions - ", () { testWidgets("onChange calendarFormat", (WidgetTester tester) async { - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settings); SettingsManagerMock.stubSetString( - settingsManagerMock, - PreferencesFlag.scheduleCalendarFormat); + settingsManagerMock, PreferencesFlag.scheduleCalendarFormat); await tester.pumpWidget( localizedWidget(child: const ScheduleSettings(showHandle: false))); @@ -396,11 +386,10 @@ void main() { }); testWidgets("onChange showTodayBtn", (WidgetTester tester) async { - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settings); - SettingsManagerMock.stubSetBool(settingsManagerMock, - PreferencesFlag.scheduleShowTodayBtn); + SettingsManagerMock.stubSetBool( + settingsManagerMock, PreferencesFlag.scheduleShowTodayBtn); await tester.pumpWidget( localizedWidget(child: const ScheduleSettings(showHandle: false))); @@ -418,8 +407,8 @@ void main() { await tester.pumpAndSettle(); - await untilCalled( - settingsManagerMock.setBool(PreferencesFlag.scheduleShowTodayBtn, any)); + await untilCalled(settingsManagerMock.setBool( + PreferencesFlag.scheduleShowTodayBtn, any)); expect( tester.widget(find.descendant( @@ -435,8 +424,7 @@ void main() { testWidgets( "Should display activity selection section when a course has activities", (WidgetTester tester) async { - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settings); CourseRepositoryMock.stubGetScheduleActivities(courseRepositoryMock, toReturn: classOneWithLaboratoryABscheduleActivities); diff --git a/test/viewmodels/choose_language_viewmodel_test.dart b/test/viewmodels/choose_language_viewmodel_test.dart index 8cf5407e6..1e93a2e52 100644 --- a/test/viewmodels/choose_language_viewmodel_test.dart +++ b/test/viewmodels/choose_language_viewmodel_test.dart @@ -44,7 +44,8 @@ void main() { verify(settingsManagerMock .setLocale(AppIntl.supportedLocales.first.languageCode)); verify(navigationServiceMock.pop()); - verify(navigationServiceMock.pushNamedAndRemoveUntil(RouterPaths.login)); + verify( + navigationServiceMock.pushNamedAndRemoveUntil(RouterPaths.login)); }); test('can set language français', () async { @@ -56,7 +57,8 @@ void main() { verify(settingsManagerMock .setLocale(AppIntl.supportedLocales.last.languageCode)); verify(navigationServiceMock.pop()); - verify(navigationServiceMock.pushNamedAndRemoveUntil(RouterPaths.login)); + verify( + navigationServiceMock.pushNamedAndRemoveUntil(RouterPaths.login)); }); test('throws an error when index does not exist', () async { diff --git a/test/viewmodels/dashboard_viewmodel_test.dart b/test/viewmodels/dashboard_viewmodel_test.dart index 5dd0430eb..8dbecc354 100644 --- a/test/viewmodels/dashboard_viewmodel_test.dart +++ b/test/viewmodels/dashboard_viewmodel_test.dart @@ -202,27 +202,19 @@ void main() { preferencesServiceMock = setupPreferencesServiceMock(); viewModel = DashboardViewModel(intl: await setupAppIntl()); - CourseRepositoryMock.stubGetSessions( - courseRepositoryMock, + CourseRepositoryMock.stubGetSessions(courseRepositoryMock, toReturn: [session]); - CourseRepositoryMock.stubActiveSessions( - courseRepositoryMock, + CourseRepositoryMock.stubActiveSessions(courseRepositoryMock, toReturn: [session]); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); - SettingsManagerMock.stubDateTimeNow( - settingsManagerMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); + SettingsManagerMock.stubDateTimeNow(settingsManagerMock, toReturn: DateTime(2020)); - RemoteConfigServiceMock.stubGetBroadcastEnabled( - remoteConfigServiceMock); - RemoteConfigServiceMock.stubGetBroadcastEn( - remoteConfigServiceMock, + RemoteConfigServiceMock.stubGetBroadcastEnabled(remoteConfigServiceMock); + RemoteConfigServiceMock.stubGetBroadcastEn(remoteConfigServiceMock, toReturn: ""); inAppReviewServiceMock = @@ -236,22 +228,16 @@ void main() { group('futureToRunGrades -', () { test('first load from cache than call SignetsAPI to get the courses', () async { - CourseRepositoryMock.stubSessions( - courseRepositoryMock, + CourseRepositoryMock.stubSessions(courseRepositoryMock, toReturn: [session]); - CourseRepositoryMock.stubGetSessions( - courseRepositoryMock, + CourseRepositoryMock.stubGetSessions(courseRepositoryMock, toReturn: [session]); - CourseRepositoryMock.stubActiveSessions( - courseRepositoryMock, + CourseRepositoryMock.stubActiveSessions(courseRepositoryMock, toReturn: [session]); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, - toReturn: courses, - fromCacheOnly: true); + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, + toReturn: courses, fromCacheOnly: true); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, toReturn: courses); expect(await viewModel.futureToRunGrades(), courses); @@ -275,26 +261,19 @@ void main() { test('Signets throw an error while trying to get courses', () async { setupFlutterToastMock(); - CourseRepositoryMock.stubSessions( - courseRepositoryMock, + CourseRepositoryMock.stubSessions(courseRepositoryMock, toReturn: [session]); - CourseRepositoryMock.stubGetSessions( - courseRepositoryMock, + CourseRepositoryMock.stubGetSessions(courseRepositoryMock, toReturn: [session]); - CourseRepositoryMock.stubActiveSessions( - courseRepositoryMock, + CourseRepositoryMock.stubActiveSessions(courseRepositoryMock, toReturn: [session]); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, - toReturn: courses, - fromCacheOnly: true); + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, + toReturn: courses, fromCacheOnly: true); - CourseRepositoryMock.stubGetCoursesException( - courseRepositoryMock); + CourseRepositoryMock.stubGetCoursesException(courseRepositoryMock); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, toReturn: courses); expect(await viewModel.futureToRunGrades(), courses, @@ -319,11 +298,8 @@ void main() { }); test('There is no session active', () async { - CourseRepositoryMock.stubSessions( - courseRepositoryMock, - toReturn: []); - CourseRepositoryMock.stubActiveSessions( - courseRepositoryMock, + CourseRepositoryMock.stubSessions(courseRepositoryMock, toReturn: []); + CourseRepositoryMock.stubActiveSessions(courseRepositoryMock, toReturn: []); expect(await viewModel.futureToRunGrades(), [], @@ -347,25 +323,18 @@ void main() { group("futureToRun - ", () { test("The initial cards are correctly loaded", () async { setupFlutterToastMock(); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCoursesException( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesException(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetSessions( - courseRepositoryMock); - CourseRepositoryMock.stubActiveSessions( - courseRepositoryMock, + CourseRepositoryMock.stubGetSessions(courseRepositoryMock); + CourseRepositoryMock.stubActiveSessions(courseRepositoryMock, toReturn: [session]); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock); + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock); - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); await viewModel.futureToRun(); @@ -385,20 +354,15 @@ void main() { }); test("build the list todays activities sorted by time", () async { - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: activities); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, toReturn: courses); - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); final now = DateTime.now(); - SettingsManagerMock.stubDateTimeNow( - settingsManagerMock, + SettingsManagerMock.stubDateTimeNow(settingsManagerMock, toReturn: DateTime(now.year, now.month, now.day, 8)); await viewModel.futureToRun(); @@ -420,20 +384,15 @@ void main() { test( "build the list todays activities (doesnt remove activity when pending completion)", () async { - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: activities); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, toReturn: courses); - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); final now = DateTime.now(); - SettingsManagerMock.stubDateTimeNow( - settingsManagerMock, + SettingsManagerMock.stubDateTimeNow(settingsManagerMock, toReturn: DateTime(now.year, now.month, now.day, 11, 59)); await viewModel.futureToRun(); @@ -454,20 +413,15 @@ void main() { test("build the list todays activities (remove activity when finished)", () async { - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: activities); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, toReturn: courses); - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); final now = DateTime.now(); - SettingsManagerMock.stubDateTimeNow( - settingsManagerMock, + SettingsManagerMock.stubDateTimeNow(settingsManagerMock, toReturn: DateTime(now.year, now.month, now.day, 12, 01)); await viewModel.futureToRun(); @@ -489,20 +443,15 @@ void main() { }); test("build the list tomorrow activities sorted by time", () async { - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: activities); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, toReturn: courses); - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); final now = DateTime.now(); - SettingsManagerMock.stubDateTimeNow( - settingsManagerMock, + SettingsManagerMock.stubDateTimeNow(settingsManagerMock, toReturn: DateTime(now.year, now.month, now.day, 8)); await viewModel.futureToRun(); @@ -524,26 +473,18 @@ void main() { test( "build the list todays activities with the right course activities (should not have labo A)", () async { - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: activitiesWithLabs); - SettingsManagerMock.stubGetDynamicString( - settingsManagerMock, - PreferencesFlag.scheduleLaboratoryGroup, - "GEN101"); + SettingsManagerMock.stubGetDynamicString(settingsManagerMock, + PreferencesFlag.scheduleLaboratoryGroup, "GEN101"); - SettingsManagerMock.stubGetDynamicString( - settingsManagerMock, - PreferencesFlag.scheduleLaboratoryGroup, - "GEN102"); + SettingsManagerMock.stubGetDynamicString(settingsManagerMock, + PreferencesFlag.scheduleLaboratoryGroup, "GEN102"); - SettingsManagerMock.stubGetDynamicString( - settingsManagerMock, - PreferencesFlag.scheduleLaboratoryGroup, - "GEN103", + SettingsManagerMock.stubGetDynamicString(settingsManagerMock, + PreferencesFlag.scheduleLaboratoryGroup, "GEN103", toReturn: ActivityCode.labGroupB); expect(await viewModel.removeLaboratoryGroup(activitiesWithLabs), [ @@ -557,26 +498,18 @@ void main() { test( "build the list todays activities with the right course activities (should not have labo B)", () async { - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: activitiesWithLabs); - SettingsManagerMock.stubGetDynamicString( - settingsManagerMock, - PreferencesFlag.scheduleLaboratoryGroup, - "GEN101"); + SettingsManagerMock.stubGetDynamicString(settingsManagerMock, + PreferencesFlag.scheduleLaboratoryGroup, "GEN101"); - SettingsManagerMock.stubGetDynamicString( - settingsManagerMock, - PreferencesFlag.scheduleLaboratoryGroup, - "GEN102"); + SettingsManagerMock.stubGetDynamicString(settingsManagerMock, + PreferencesFlag.scheduleLaboratoryGroup, "GEN102"); - SettingsManagerMock.stubGetDynamicString( - settingsManagerMock, - PreferencesFlag.scheduleLaboratoryGroup, - "GEN103", + SettingsManagerMock.stubGetDynamicString(settingsManagerMock, + PreferencesFlag.scheduleLaboratoryGroup, "GEN103", toReturn: ActivityCode.labGroupA); expect(await viewModel.removeLaboratoryGroup(activitiesWithLabs), [ @@ -590,26 +523,18 @@ void main() { test( "build the list todays activities with the right course activities (should have both labs)", () async { - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: activitiesWithLabs); - SettingsManagerMock.stubGetDynamicString( - settingsManagerMock, - PreferencesFlag.scheduleLaboratoryGroup, - "GEN101"); + SettingsManagerMock.stubGetDynamicString(settingsManagerMock, + PreferencesFlag.scheduleLaboratoryGroup, "GEN101"); - SettingsManagerMock.stubGetDynamicString( - settingsManagerMock, - PreferencesFlag.scheduleLaboratoryGroup, - "GEN102"); + SettingsManagerMock.stubGetDynamicString(settingsManagerMock, + PreferencesFlag.scheduleLaboratoryGroup, "GEN102"); - SettingsManagerMock.stubGetDynamicString( - settingsManagerMock, - PreferencesFlag.scheduleLaboratoryGroup, - "GEN103"); + SettingsManagerMock.stubGetDynamicString(settingsManagerMock, + PreferencesFlag.scheduleLaboratoryGroup, "GEN103"); expect(await viewModel.removeLaboratoryGroup(activitiesWithLabs), activitiesWithLabs); @@ -618,25 +543,18 @@ void main() { test("An exception is thrown during the preferenceService call", () async { setupFlutterToastMock(); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock); + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubGetCourses(courseRepositoryMock); PreferencesServiceMock.stubException( - preferenceServiceMock, - PreferencesFlag.broadcastCard); + preferenceServiceMock, PreferencesFlag.broadcastCard); PreferencesServiceMock.stubException( - preferenceServiceMock, - PreferencesFlag.aboutUsCard); + preferenceServiceMock, PreferencesFlag.aboutUsCard); PreferencesServiceMock.stubException( - preferenceServiceMock, - PreferencesFlag.scheduleCard); + preferenceServiceMock, PreferencesFlag.scheduleCard); PreferencesServiceMock.stubException( - preferenceServiceMock, - PreferencesFlag.progressBarCard); + preferenceServiceMock, PreferencesFlag.progressBarCard); await viewModel.futureToRun(); expect(viewModel.cardsToDisplay, []); @@ -647,14 +565,11 @@ void main() { group("futureToRunSessionProgressBar - ", () { test("There is an active session", () async { - CourseRepositoryMock.stubActiveSessions( - courseRepositoryMock, + CourseRepositoryMock.stubActiveSessions(courseRepositoryMock, toReturn: [session]); - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); - SettingsManagerMock.stubDateTimeNow( - settingsManagerMock, + SettingsManagerMock.stubDateTimeNow(settingsManagerMock, toReturn: DateTime(2020)); await viewModel.futureToRunSessionProgressBar(); expect(viewModel.progress, 0.5); @@ -662,14 +577,11 @@ void main() { }); test("Invalid date (Superior limit)", () async { - CourseRepositoryMock.stubActiveSessions( - courseRepositoryMock, + CourseRepositoryMock.stubActiveSessions(courseRepositoryMock, toReturn: [session]); - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); - SettingsManagerMock.stubDateTimeNow( - settingsManagerMock, + SettingsManagerMock.stubDateTimeNow(settingsManagerMock, toReturn: DateTime(2020, 1, 20)); await viewModel.futureToRunSessionProgressBar(); expect(viewModel.progress, 1); @@ -677,14 +589,11 @@ void main() { }); test("Invalid date (Lower limit)", () async { - CourseRepositoryMock.stubActiveSessions( - courseRepositoryMock, + CourseRepositoryMock.stubActiveSessions(courseRepositoryMock, toReturn: [session]); - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); - SettingsManagerMock.stubDateTimeNow( - settingsManagerMock, + SettingsManagerMock.stubDateTimeNow(settingsManagerMock, toReturn: DateTime(2019, 12, 31)); await viewModel.futureToRunSessionProgressBar(); expect(viewModel.progress, 0); @@ -692,8 +601,7 @@ void main() { }); test("Active session is null", () async { - CourseRepositoryMock.stubActiveSessions( - courseRepositoryMock); + CourseRepositoryMock.stubActiveSessions(courseRepositoryMock); await viewModel.futureToRunSessionProgressBar(); expect(viewModel.progress, -1.0); @@ -703,8 +611,7 @@ void main() { test( "currentProgressBarText should be set to ProgressBarText.percentage when it is the first time changeProgressBarText is called", () async { - CourseRepositoryMock.stubActiveSessions( - courseRepositoryMock); + CourseRepositoryMock.stubActiveSessions(courseRepositoryMock); viewModel.changeProgressBarText(); verify(settingsManagerMock.setString(PreferencesFlag.progressBarText, @@ -715,8 +622,7 @@ void main() { test( "currentProgressBarText flag should be set to ProgressBarText.remainingDays when it is the second time changeProgressBarText is called", () async { - CourseRepositoryMock.stubActiveSessions( - courseRepositoryMock); + CourseRepositoryMock.stubActiveSessions(courseRepositoryMock); viewModel.changeProgressBarText(); viewModel.changeProgressBarText(); @@ -728,8 +634,7 @@ void main() { test( "currentProgressBarText flag should be set to ProgressBarText.daysElapsedWithTotalDays when it is the third time changeProgressBarText is called", () async { - CourseRepositoryMock.stubActiveSessions( - courseRepositoryMock); + CourseRepositoryMock.stubActiveSessions(courseRepositoryMock); viewModel.changeProgressBarText(); viewModel.changeProgressBarText(); @@ -743,20 +648,18 @@ void main() { group("interact with cards - ", () { test("can hide a card and reset cards to default layout", () async { - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.broadcastCard); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.aboutUsCard); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.scheduleCard); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.progressBarCard); - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.broadcastCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.aboutUsCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.scheduleCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.progressBarCard); + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock); + CourseRepositoryMock.stubGetCourses(courseRepositoryMock); await viewModel.futureToRun(); @@ -798,8 +701,8 @@ void main() { PreferencesFlag.progressBarCard ]); - verify( - analyticsServiceMock.logEvent("DashboardViewModel", "Restoring cards")); + verify(analyticsServiceMock.logEvent( + "DashboardViewModel", "Restoring cards")); verify(settingsManagerMock.getDashboard()).called(1); verify(settingsManagerMock.setInt(PreferencesFlag.broadcastCard, 0)) .called(1); @@ -816,25 +719,21 @@ void main() { }); test("can set new order for cards", () async { - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock); - - SettingsManagerMock.stubGetDashboard( - settingsManagerMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubGetCourses(courseRepositoryMock); + + SettingsManagerMock.stubGetDashboard(settingsManagerMock, toReturn: dashboard); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.broadcastCard); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.aboutUsCard); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.scheduleCard); - SettingsManagerMock.stubSetInt(settingsManagerMock, - PreferencesFlag.progressBarCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.broadcastCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.aboutUsCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.scheduleCard); + SettingsManagerMock.stubSetInt( + settingsManagerMock, PreferencesFlag.progressBarCard); await viewModel.futureToRun(); diff --git a/test/viewmodels/feedback_viewmodel_test.dart b/test/viewmodels/feedback_viewmodel_test.dart index 0dffbd270..b685b2b9b 100644 --- a/test/viewmodels/feedback_viewmodel_test.dart +++ b/test/viewmodels/feedback_viewmodel_test.dart @@ -46,8 +46,7 @@ void main() { setUp(() async { setupNavigationServiceMock(); githubApiMock = setupGithubApiMock(); - preferencesServiceMock = - setupPreferencesServiceMock(); + preferencesServiceMock = setupPreferencesServiceMock(); appIntl = await setupAppIntl(); setupLogger(); GithubApiMock.stubCreateGithubIssue(githubApiMock, Issue()); diff --git a/test/viewmodels/grades_details_viewmodel_test.dart b/test/viewmodels/grades_details_viewmodel_test.dart index 7353835ad..a099f4c79 100644 --- a/test/viewmodels/grades_details_viewmodel_test.dart +++ b/test/viewmodels/grades_details_viewmodel_test.dart @@ -14,7 +14,7 @@ import '../mock/managers/course_repository_mock.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); late AppIntl intl; - + late CourseRepositoryMock courseRepositoryMock; late GradesDetailsViewModel viewModel; diff --git a/test/viewmodels/grades_viewmodel_test.dart b/test/viewmodels/grades_viewmodel_test.dart index 0600570b5..1f135fb26 100644 --- a/test/viewmodels/grades_viewmodel_test.dart +++ b/test/viewmodels/grades_viewmodel_test.dart @@ -15,9 +15,8 @@ import '../mock/managers/course_repository_mock.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); late AppIntl intl; - + late CourseRepositoryMock courseRepositoryMock; - late GradesViewModel viewModel; @@ -103,15 +102,11 @@ void main() { group('futureToRun -', () { test('first load from cache than call SignetsAPI to get the courses', () async { - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, - toReturn: courses, - fromCacheOnly: true); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, + toReturn: courses, fromCacheOnly: true); + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, toReturn: courses); - CourseRepositoryMock.stubCourses( - courseRepositoryMock, + CourseRepositoryMock.stubCourses(courseRepositoryMock, toReturn: courses); expect(await viewModel.futureToRun(), coursesBySession); @@ -132,14 +127,10 @@ void main() { }); test('Signets throw an error while trying to get courses', () async { - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, - toReturn: courses, - fromCacheOnly: true); - CourseRepositoryMock.stubGetCoursesException( - courseRepositoryMock); - CourseRepositoryMock.stubCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, + toReturn: courses, fromCacheOnly: true); + CourseRepositoryMock.stubGetCoursesException(courseRepositoryMock); + CourseRepositoryMock.stubCourses(courseRepositoryMock, toReturn: courses); setupFlutterToastMock(); @@ -165,11 +156,9 @@ void main() { test( 'Call SignetsAPI to get the courses than reload the coursesBySession', () async { - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, toReturn: courses); - CourseRepositoryMock.stubCourses( - courseRepositoryMock, + CourseRepositoryMock.stubCourses(courseRepositoryMock, toReturn: courses); await viewModel.refresh(); @@ -177,22 +166,20 @@ void main() { expect(viewModel.coursesBySession, coursesBySession); expect(viewModel.sessionOrder, sessionOrder); - verifyInOrder([courseRepositoryMock.getCourses(), - courseRepositoryMock.courses, - courseRepositoryMock.courses]); + verifyInOrder([ + courseRepositoryMock.getCourses(), + courseRepositoryMock.courses, + courseRepositoryMock.courses + ]); verifyNoMoreInteractions(courseRepositoryMock); }); test('Signets throw an error', () async { - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, - toReturn: courses, - fromCacheOnly: true); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock); - CourseRepositoryMock.stubCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, + toReturn: courses, fromCacheOnly: true); + CourseRepositoryMock.stubGetCourses(courseRepositoryMock); + CourseRepositoryMock.stubCourses(courseRepositoryMock, toReturn: courses); setupFlutterToastMock(); @@ -202,11 +189,9 @@ void main() { expect(viewModel.sessionOrder, sessionOrder); reset(courseRepositoryMock); - CourseRepositoryMock.stubCourses( - courseRepositoryMock, + CourseRepositoryMock.stubCourses(courseRepositoryMock, toReturn: courses); - CourseRepositoryMock.stubGetCoursesException( - courseRepositoryMock); + CourseRepositoryMock.stubGetCoursesException(courseRepositoryMock); await viewModel.refresh(); @@ -215,8 +200,11 @@ void main() { "The list of courses should not change even when an error occurs"); expect(viewModel.sessionOrder, sessionOrder); - verifyInOrder([courseRepositoryMock.getCourses(), - courseRepositoryMock.courses, courseRepositoryMock.courses]); + verifyInOrder([ + courseRepositoryMock.getCourses(), + courseRepositoryMock.courses, + courseRepositoryMock.courses + ]); verifyNoMoreInteractions(courseRepositoryMock); }); diff --git a/test/viewmodels/login_viewmodel_test.dart b/test/viewmodels/login_viewmodel_test.dart index 0ee6b4302..a96be3d0a 100644 --- a/test/viewmodels/login_viewmodel_test.dart +++ b/test/viewmodels/login_viewmodel_test.dart @@ -110,8 +110,8 @@ void main() { viewModel.validatePassword(passwordCodeValid); await viewModel.authenticate(); - verify( - navigationServiceMock.pushNamedAndRemoveUntil(RouterPaths.dashboard)); + verify(navigationServiceMock + .pushNamedAndRemoveUntil(RouterPaths.dashboard)); }); test( diff --git a/test/viewmodels/more_viewmodel_test.dart b/test/viewmodels/more_viewmodel_test.dart index c472256c2..a6a78203a 100644 --- a/test/viewmodels/more_viewmodel_test.dart +++ b/test/viewmodels/more_viewmodel_test.dart @@ -115,8 +115,7 @@ void main() { setUp(() async { cacheManagerMock = setupCacheManagerMock(); settingsManagerMock = setupSettingsManagerMock(); - courseRepositoryMock = - setupCourseRepositoryMock(); + courseRepositoryMock = setupCourseRepositoryMock(); remoteConfigServiceMock = setupRemoteConfigServiceMock(); preferenceServiceMock = setupPreferencesServiceMock(); userRepositoryMock = setupUserRepositoryMock(); diff --git a/test/viewmodels/news_viewmodel_test.dart b/test/viewmodels/news_viewmodel_test.dart index 328d80628..9c197d2ba 100644 --- a/test/viewmodels/news_viewmodel_test.dart +++ b/test/viewmodels/news_viewmodel_test.dart @@ -1,60 +1,49 @@ -// FLUTTER / DART / THIRD-PARTIES +// Package imports: +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:mockito/mockito.dart'; +import 'package:logger/logger.dart'; -// MANAGERS -import 'package:notredame/core/managers/settings_manager.dart'; +// Project imports: import 'package:notredame/core/managers/news_repository.dart'; - -// MODEL +import 'package:notredame/core/managers/settings_manager.dart'; import 'package:notredame/core/models/news.dart'; - -// VIEWMODEL import 'package:notredame/core/viewmodels/news_viewmodel.dart'; - -// UTILS import 'package:notredame/locator.dart'; -import 'package:logger/logger.dart'; import '../helpers.dart'; - -class MockNewsRepository extends Mock implements NewsRepository { - @override - List get news => [ - News( - id: 1, - title: 'Mock News 1', - description: 'Mock Description 1', - image: 'https://example.com/mock-image1.jpg', - tags: [], - date: DateTime.now(), - ), - News( - id: 2, - title: 'Mock News 2', - description: 'Mock Description 2', - image: 'https://example.com/mock-image2.jpg', - tags: [], - date: DateTime.now(), - ), - ]; - - static void stubGetNews(MockNewsRepository mock, List newsList) { - when(mock.getNews(fromCacheOnly: anyNamed('fromCacheOnly'))) - .thenAnswer((_) async => newsList); - } -} +import '../mock/managers/news_repository_mock.dart'; void main() { - NewsViewModel viewModel; + late NewsViewModel viewModel; + late NewsRepositoryMock newsRepository; + late AppIntl appIntl; + + final List news = [ + News( + id: 1, + title: 'Mock News 1', + description: 'Mock Description 1', + image: 'https://example.com/mock-image1.jpg', + tags: [], + date: DateTime.now(), + ), + News( + id: 2, + title: 'Mock News 2', + description: 'Mock Description 2', + image: 'https://example.com/mock-image2.jpg', + tags: [], + date: DateTime.now(), + ), + ]; group('NewsViewModel tests', () { - setUp(() { + setUp(() async { + newsRepository = setupNewsRepositoryMock(); setupLogger(); setupSettingsManagerMock(); - final mockNewsRepository = MockNewsRepository(); - MockNewsRepository.stubGetNews(mockNewsRepository, []); - locator.registerSingleton(mockNewsRepository); - viewModel = NewsViewModel(intl: null); // Pass null for AppIntl + NewsRepositoryMock.stubNews(newsRepository, toReturn: news); + appIntl = await setupAppIntl(); + viewModel = NewsViewModel(intl: appIntl); }); tearDown(() { diff --git a/test/viewmodels/not_found_viewmodel_test.dart b/test/viewmodels/not_found_viewmodel_test.dart index 8c676beb8..52e228fe7 100644 --- a/test/viewmodels/not_found_viewmodel_test.dart +++ b/test/viewmodels/not_found_viewmodel_test.dart @@ -54,8 +54,8 @@ void main() { test('navigating back worked', () async { viewModel.navigateToDashboard(); - verify( - navigationServiceMock.pushNamedAndRemoveUntil(RouterPaths.dashboard)); + verify(navigationServiceMock + .pushNamedAndRemoveUntil(RouterPaths.dashboard)); }); }); @@ -78,9 +78,7 @@ void main() { final expectedArtboard = Artboard(); RiveAnimationServiceMock.stubLoadRiveFile( - riveAnimationServiceMock, - 'dot_jumping', - expectedArtboard); + riveAnimationServiceMock, 'dot_jumping', expectedArtboard); await viewModel.loadRiveAnimation(); final artboard = viewModel.artboard; @@ -93,7 +91,8 @@ void main() { test('load the dot_jumping Rive animation successfuly', () async { await viewModel.loadRiveAnimation(); - verify(riveAnimationServiceMock.loadRiveFile(riveFileName: riveFileName)); + verify( + riveAnimationServiceMock.loadRiveFile(riveFileName: riveFileName)); }); test('load file Rive animation with error', () async { @@ -115,9 +114,7 @@ void main() { final artboard = Artboard(); RiveAnimationServiceMock.stubLoadRiveFile( - riveAnimationServiceMock, - 'dot_jumping', - artboard); + riveAnimationServiceMock, 'dot_jumping', artboard); RiveAnimationServiceMock.stubAddControllerToAnimationException( riveAnimationServiceMock, artboard); diff --git a/test/viewmodels/profile_viewmodel_test.dart b/test/viewmodels/profile_viewmodel_test.dart index afa450b0b..1563a9545 100644 --- a/test/viewmodels/profile_viewmodel_test.dart +++ b/test/viewmodels/profile_viewmodel_test.dart @@ -76,8 +76,7 @@ void main() { "first load from cache then call SignetsAPI to get the latest events", () async { UserRepositoryMock.stubGetInfo(userRepositoryMock, toReturn: info); - UserRepositoryMock.stubGetPrograms( - userRepositoryMock); + UserRepositoryMock.stubGetPrograms(userRepositoryMock); expect(await viewModel.futureToRun(), []); @@ -93,15 +92,12 @@ void main() { test("Signets throw an error while trying to get new events", () async { setupFlutterToastMock(); UserRepositoryMock.stubGetInfo(userRepositoryMock, - fromCacheOnly: true, - toReturn: info); - UserRepositoryMock.stubGetInfoException( - userRepositoryMock, + fromCacheOnly: true, toReturn: info); + UserRepositoryMock.stubGetInfoException(userRepositoryMock, fromCacheOnly: false); UserRepositoryMock.stubGetPrograms(userRepositoryMock, fromCacheOnly: true); - UserRepositoryMock.stubGetProgramsException( - userRepositoryMock, + UserRepositoryMock.stubGetProgramsException(userRepositoryMock, fromCacheOnly: false); expect(await viewModel.futureToRun(), [], @@ -119,8 +115,7 @@ void main() { group("info - ", () { test("build the info", () async { - UserRepositoryMock.stubProfileStudent( - userRepositoryMock, + UserRepositoryMock.stubProfileStudent(userRepositoryMock, toReturn: info); expect(viewModel.profileStudent, info); @@ -133,8 +128,7 @@ void main() { group("programs - ", () { test("build the list of programs", () async { - UserRepositoryMock.stubPrograms(userRepositoryMock, - toReturn: programs); + UserRepositoryMock.stubPrograms(userRepositoryMock, toReturn: programs); expect(viewModel.programList, programs); @@ -183,7 +177,8 @@ void main() { // Calculate the expected progression based on the defined ProgramCredits final double expectedProgression = - (45 / programCredits.programsCredits['7694']! * 100).roundToDouble(); + (45 / programCredits.programsCredits['7694']! * 100) + .roundToDouble(); // Verify that the calculated progression matches the expected value expect(progression, expectedProgression); @@ -219,13 +214,10 @@ void main() { group('refresh -', () { test('Call SignetsAPI to get the user info and programs', () async { - UserRepositoryMock.stubProfileStudent( - userRepositoryMock, + UserRepositoryMock.stubProfileStudent(userRepositoryMock, toReturn: info); - UserRepositoryMock.stubGetInfo(userRepositoryMock, - toReturn: info); - UserRepositoryMock.stubGetPrograms( - userRepositoryMock); + UserRepositoryMock.stubGetInfo(userRepositoryMock, toReturn: info); + UserRepositoryMock.stubGetPrograms(userRepositoryMock); await viewModel.refresh(); diff --git a/test/viewmodels/schedule_settings_viewmodel_test.dart b/test/viewmodels/schedule_settings_viewmodel_test.dart index 9a2f5a7f8..0d9b1f70b 100644 --- a/test/viewmodels/schedule_settings_viewmodel_test.dart +++ b/test/viewmodels/schedule_settings_viewmodel_test.dart @@ -130,12 +130,10 @@ void main() { test( "The settings are correctly loaded and sets (if no schedule activities present to use)", () async { - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settings); - CourseRepositoryMock.stubGetScheduleActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetScheduleActivities(courseRepositoryMock, toReturn: []); expect(await viewModel.futureToRun(), settings); @@ -156,12 +154,10 @@ void main() { test( "If there is one valid class which has grouped laboratory, we parse it and store it (None selected)", () async { - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settings); - CourseRepositoryMock.stubGetScheduleActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetScheduleActivities(courseRepositoryMock, toReturn: classOneWithLaboratoryABscheduleActivities); final courseAcronymWithLaboratory = @@ -178,8 +174,8 @@ void main() { .containsKey(courseAcronymWithLaboratory), true); expect( - viewModel - .scheduleActivitiesByCourse[courseAcronymWithLaboratory]!.length, + viewModel.scheduleActivitiesByCourse[courseAcronymWithLaboratory]! + .length, 2); expect( viewModel.selectedScheduleActivity @@ -194,12 +190,10 @@ void main() { test( "If there is two valid class which has grouped laboratory, we store both (First => none selected, Second => group A selected)", () async { - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settings); - CourseRepositoryMock.stubGetScheduleActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetScheduleActivities(courseRepositoryMock, toReturn: twoClassesWithLaboratoryABscheduleActivities); final firstCourseAcronymWithLab = @@ -208,14 +202,10 @@ void main() { final secondCourseAcronymWithLab = classTwoWithLaboratoryABscheduleActivities.first.courseAcronym; - SettingsManagerMock.stubGetDynamicString( - settingsManagerMock, - PreferencesFlag.scheduleLaboratoryGroup, - firstCourseAcronymWithLab); - SettingsManagerMock.stubGetDynamicString( - settingsManagerMock, - PreferencesFlag.scheduleLaboratoryGroup, - secondCourseAcronymWithLab, + SettingsManagerMock.stubGetDynamicString(settingsManagerMock, + PreferencesFlag.scheduleLaboratoryGroup, firstCourseAcronymWithLab); + SettingsManagerMock.stubGetDynamicString(settingsManagerMock, + PreferencesFlag.scheduleLaboratoryGroup, secondCourseAcronymWithLab, toReturn: ActivityCode.labGroupA); expect(await viewModel.futureToRun(), settings); @@ -251,8 +241,7 @@ void main() { group("setter calendarFormat - ", () { test("calendarFormat is updated on the settings", () async { SettingsManagerMock.stubSetString( - settingsManagerMock, - PreferencesFlag.scheduleCalendarFormat); + settingsManagerMock, PreferencesFlag.scheduleCalendarFormat); // Call the setter. viewModel.calendarFormat = CalendarFormat.twoWeeks; @@ -273,8 +262,7 @@ void main() { group("setter calendarView - ", () { test("calendarView is updated on the settings", () async { SettingsManagerMock.stubSetString( - settingsManagerMock, - PreferencesFlag.scheduleListView); + settingsManagerMock, PreferencesFlag.scheduleListView); const expected = true; @@ -287,7 +275,8 @@ void main() { expect(viewModel.toggleCalendarView, true); expect(viewModel.isBusy, false); - verify(settingsManagerMock.setBool(PreferencesFlag.scheduleListView, any)) + verify(settingsManagerMock.setBool( + PreferencesFlag.scheduleListView, any)) .called(1); verifyNoMoreInteractions(settingsManagerMock); }); @@ -296,8 +285,7 @@ void main() { group("setter scheduleShowWeekendDays - ", () { test("scheduleShowWeekendDays is updated on the settings", () async { SettingsManagerMock.stubSetString( - settingsManagerMock, - PreferencesFlag.scheduleShowWeekendDays); + settingsManagerMock, PreferencesFlag.scheduleShowWeekendDays); const expected = true; @@ -321,8 +309,7 @@ void main() { group("setter startingDayOfWeek - ", () { test("startingDayOfWeek is updated on the settings", () async { SettingsManagerMock.stubSetString( - settingsManagerMock, - PreferencesFlag.scheduleStartWeekday); + settingsManagerMock, PreferencesFlag.scheduleStartWeekday); // Call the setter. viewModel.startingDayOfWeek = StartingDayOfWeek.friday; @@ -343,16 +330,15 @@ void main() { group("setter showTodayBtn - ", () { test("showTodayBtn is updated on the settings", () async { SettingsManagerMock.stubSetString( - settingsManagerMock, - PreferencesFlag.scheduleStartWeekday); + settingsManagerMock, PreferencesFlag.scheduleStartWeekday); const expected = false; // Call the setter. viewModel.showTodayBtn = expected; - await untilCalled( - settingsManagerMock.setBool(PreferencesFlag.scheduleShowTodayBtn, any)); + await untilCalled(settingsManagerMock.setBool( + PreferencesFlag.scheduleShowTodayBtn, any)); expect(viewModel.showTodayBtn, expected); expect(viewModel.isBusy, false); diff --git a/test/viewmodels/schedule_viewmodel_test.dart b/test/viewmodels/schedule_viewmodel_test.dart index 51200d3ae..e051da209 100644 --- a/test/viewmodels/schedule_viewmodel_test.dart +++ b/test/viewmodels/schedule_viewmodel_test.dart @@ -258,17 +258,12 @@ void main() { test( "first load from cache than call SignetsAPI to get the latest events", () async { - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock); - CourseRepositoryMock.stubGetScheduleActivities( - courseRepositoryMock); + CourseRepositoryMock.stubGetCourses(courseRepositoryMock); + CourseRepositoryMock.stubGetScheduleActivities(courseRepositoryMock); expect(await viewModel.futureToRun(), []); @@ -287,20 +282,15 @@ void main() { test("Signets throw an error while trying to get new events", () async { setupFlutterToastMock(); - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock, fromCacheOnly: true); CourseRepositoryMock.stubGetCoursesActivitiesException( courseRepositoryMock); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, fromCacheOnly: true); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubGetScheduleActivities( - courseRepositoryMock); + CourseRepositoryMock.stubGetCourses(courseRepositoryMock); + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubGetScheduleActivities(courseRepositoryMock); expect(await viewModel.futureToRun(), [], reason: "Even if SignetsAPI fails we should receives a list."); @@ -320,8 +310,7 @@ void main() { group("coursesActivities - ", () { test("build the list of activities sort by date", () async { - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: activities); final expected = { @@ -340,14 +329,11 @@ void main() { test( 'scheduleActivityIsSelected returns true when activityDescription is not labA or labB', () async { - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: activitiesLabs); - SettingsManagerMock.stubGetDynamicString( - settingsManagerMock, - PreferencesFlag.scheduleLaboratoryGroup, - "GEN103", + SettingsManagerMock.stubGetDynamicString(settingsManagerMock, + PreferencesFlag.scheduleLaboratoryGroup, "GEN103", toReturn: ActivityCode.labGroupA); await viewModel.assignScheduleActivities([ @@ -371,8 +357,7 @@ void main() { test( 'scheduleActivityIsSelected returns true when the course does not have an activity', () async { - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: activitiesLabs); SettingsManagerMock.stubGetDynamicString( @@ -418,8 +403,7 @@ void main() { group("coursesActivitiesFor - ", () { test("Get the correct list of activities for the specified day", () { - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: activities); final expected = [gen102, gen103]; @@ -433,8 +417,7 @@ void main() { }); test("If the day doesn't have any events, return an empty list.", () { - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: activities); expect(viewModel.coursesActivitiesFor(DateTime(2020, 1, 3)), isEmpty, @@ -449,8 +432,7 @@ void main() { group("selectedDateEvents", () { test("The events of the date currently selected are return", () { - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: activities); final expected = [gen102, gen103]; @@ -467,8 +449,7 @@ void main() { }); test("The events of the date currently selected are return", () { - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: activities); final expected = []; @@ -500,11 +481,9 @@ void main() { }; test('selectedWeekEvents for starting day sunday', () async { - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: weekOfActivities); - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settingsStartingDaySunday); final expected = { @@ -527,11 +506,9 @@ void main() { }); test('selectedWeekEvents for starting day monday', () async { - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settingsStartingDayMonday); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: weekOfActivities); final expected = { @@ -553,11 +530,9 @@ void main() { }); test('selectedWeekEvents for starting day saturday', () async { - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: settingsStartingDaySaturday); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: weekOfActivities); final expected = { @@ -583,8 +558,7 @@ void main() { test( 'Call SignetsAPI to get the coursesActivities than reload the coursesActivities', () async { - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: activities); await viewModel.refresh(); @@ -608,8 +582,7 @@ void main() { group('loadSettings -', () { test('calendarFormat changing', () async { - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: { PreferencesFlag.scheduleCalendarFormat: CalendarFormat.month }); @@ -660,22 +633,15 @@ void main() { test( 'loadSettingsScheduleActivities - test when one is selected from one group', () async { - CourseRepositoryMock.stubGetCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubGetCoursesActivities(courseRepositoryMock, toReturn: activities); - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock, - fromCacheOnly: true, - toReturn: courses); - CourseRepositoryMock.stubGetCourses( - courseRepositoryMock); - CourseRepositoryMock.stubGetScheduleActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock); + CourseRepositoryMock.stubGetCourses(courseRepositoryMock, + fromCacheOnly: true, toReturn: courses); + CourseRepositoryMock.stubGetCourses(courseRepositoryMock); + CourseRepositoryMock.stubGetScheduleActivities(courseRepositoryMock, toReturn: classOneWithLaboratoryABscheduleActivities); - SettingsManagerMock.stubGetScheduleSettings( - settingsManagerMock, + SettingsManagerMock.stubGetScheduleSettings(settingsManagerMock, toReturn: { PreferencesFlag.scheduleCalendarFormat: CalendarFormat.month }); @@ -719,14 +685,11 @@ void main() { test( 'coursesActivities - should fill coursesActivities with the activities', () async { - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: activitiesLabs); - SettingsManagerMock.stubGetDynamicString( - settingsManagerMock, - PreferencesFlag.scheduleLaboratoryGroup, - "GEN103", + SettingsManagerMock.stubGetDynamicString(settingsManagerMock, + PreferencesFlag.scheduleLaboratoryGroup, "GEN103", toReturn: ActivityCode.labGroupA); await viewModel.assignScheduleActivities([ @@ -752,14 +715,11 @@ void main() { test( 'coursesActivities - should fill coursesActivities with the activities with no LabB for GEN103', () async { - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: activitiesLabs); - SettingsManagerMock.stubGetDynamicString( - settingsManagerMock, - PreferencesFlag.scheduleLaboratoryGroup, - "GEN103", + SettingsManagerMock.stubGetDynamicString(settingsManagerMock, + PreferencesFlag.scheduleLaboratoryGroup, "GEN103", toReturn: ActivityCode.labGroupA); await viewModel.assignScheduleActivities([ @@ -785,14 +745,11 @@ void main() { test( 'coursesActivities - should fill coursesActivities with the activities with no LabA for GEN103', () async { - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: activitiesLabs); - SettingsManagerMock.stubGetDynamicString( - settingsManagerMock, - PreferencesFlag.scheduleLaboratoryGroup, - "GEN103", + SettingsManagerMock.stubGetDynamicString(settingsManagerMock, + PreferencesFlag.scheduleLaboratoryGroup, "GEN103", toReturn: ActivityCode.labGroupB); await viewModel.assignScheduleActivities([ @@ -818,14 +775,11 @@ void main() { test( 'coursesActivities - should fill coursesActivities with all the activities if none are selected', () async { - CourseRepositoryMock.stubCoursesActivities( - courseRepositoryMock, + CourseRepositoryMock.stubCoursesActivities(courseRepositoryMock, toReturn: activitiesLabs); - SettingsManagerMock.stubGetDynamicString( - settingsManagerMock, - PreferencesFlag.scheduleLaboratoryGroup, - "GEN103"); + SettingsManagerMock.stubGetDynamicString(settingsManagerMock, + PreferencesFlag.scheduleLaboratoryGroup, "GEN103"); await viewModel.assignScheduleActivities([]); diff --git a/test/viewmodels/settings_viewmodel_test.dart b/test/viewmodels/settings_viewmodel_test.dart index d00afe0a9..a3d01d24e 100644 --- a/test/viewmodels/settings_viewmodel_test.dart +++ b/test/viewmodels/settings_viewmodel_test.dart @@ -35,8 +35,7 @@ void main() { test("The settings are correctly loaded and sets", () async { SettingsManagerMock.stubLocale(settingsManagerMock); - SettingsManagerMock.stubThemeMode( - settingsManagerMock); + SettingsManagerMock.stubThemeMode(settingsManagerMock); await viewModel.futureToRun(); expect(viewModel.currentLocale, 'English'); diff --git a/test/viewmodels/startup_viewmodel_test.dart b/test/viewmodels/startup_viewmodel_test.dart index d700701be..211173905 100644 --- a/test/viewmodels/startup_viewmodel_test.dart +++ b/test/viewmodels/startup_viewmodel_test.dart @@ -38,14 +38,11 @@ void main() { setupAnalyticsServiceMock(); navigationServiceMock = setupNavigationServiceMock(); settingsManagerMock = setupSettingsManagerMock(); - preferencesServiceMock = - setupPreferencesServiceMock(); + preferencesServiceMock = setupPreferencesServiceMock(); userRepositoryMock = setupUserRepositoryMock(); networkingServiceMock = setupNetworkingServiceMock(); - internalInfoServiceMock = - setupInternalInfoServiceMock(); - sirenFlutterServiceMock = - setupSirenFlutterServiceMock(); + internalInfoServiceMock = setupInternalInfoServiceMock(); + sirenFlutterServiceMock = setupSirenFlutterServiceMock(); setupLogger(); viewModel = StartUpViewModel(); diff --git a/test/viewmodels/web_link_card_viewmodel_test.dart b/test/viewmodels/web_link_card_viewmodel_test.dart index e50d0e3df..290c835dd 100644 --- a/test/viewmodels/web_link_card_viewmodel_test.dart +++ b/test/viewmodels/web_link_card_viewmodel_test.dart @@ -60,8 +60,8 @@ void main() { test('navigate to security', () async { await viewModel.onLinkClicked(securityQuickLink, Brightness.light); - verify( - analyticsServiceMock.logEvent("QuickLink", "QuickLink clicked: test")); + verify(analyticsServiceMock.logEvent( + "QuickLink", "QuickLink clicked: test")); verify(navigationServiceMock.pushNamed(RouterPaths.security)); verifyNoMoreInteractions(navigationServiceMock); }); @@ -72,8 +72,8 @@ void main() { await viewModel.onLinkClicked(quickLink, Brightness.light); - verify( - launchUrlServiceMock.launchInBrowser(quickLink.link, Brightness.light)); + verify(launchUrlServiceMock.launchInBrowser( + quickLink.link, Brightness.light)); verifyNoMoreInteractions(navigationServiceMock); }); });