Skip to content

Commit

Permalink
Fix ScheduleViewModel tests
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierPaquet-Rapold committed Jan 22, 2024
1 parent cf48052 commit 9393dea
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 38 deletions.
69 changes: 32 additions & 37 deletions lib/core/viewmodels/schedule_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,43 +175,37 @@ class ScheduleViewModel extends FutureViewModel<List<CourseActivity>> {
settings[PreferencesFlag.scheduleListView] as bool;

@override
Future<List<CourseActivity>> futureToRun() =>
_courseRepository.getCoursesActivities(fromCacheOnly: true).then((value) {
setBusyForObject(isLoadingEvents, true);
_courseRepository
.getCoursesActivities()
// ignore: return_type_invalid_for_catch_error
.catchError(onError)
.then((value1) async {
if (value1 != null) {
// Reload the list of activities
coursesActivities;

await _courseRepository
.getCourses(fromCacheOnly: true)
.then((value2) {
courses = value2;
});
if (_coursesActivities.isNotEmpty) {
if (calendarFormat == CalendarFormat.week) {
calendarEvents = selectedWeekCalendarEvents();
} else {
calendarEvents = selectedMonthCalendarEvents();
}
}
Future<List<CourseActivity>> futureToRun() async {
List<CourseActivity>? activities = await _courseRepository.getCoursesActivities(fromCacheOnly: true);
try {
setBusyForObject(isLoadingEvents, true);

final fetchedCourseActivities = await _courseRepository.getCoursesActivities();
if (fetchedCourseActivities != null) {
activities = fetchedCourseActivities;
// Reload the list of activities
coursesActivities;

courses = await _courseRepository.getCourses(fromCacheOnly: true);

if (_coursesActivities.isNotEmpty) {
if (calendarFormat == CalendarFormat.week) {
calendarEvents = selectedWeekCalendarEvents();
} else {
calendarEvents = selectedMonthCalendarEvents();
}
_courseRepository
.getScheduleActivities()
// ignore: return_type_invalid_for_catch_error
.catchError(onError)
.then((value) async {
await assignScheduleActivities(value);
}).whenComplete(() {
setBusyForObject(isLoadingEvents, false);
});
});
return value ?? [];
});
}
}
final scheduleActivities = await _courseRepository.getScheduleActivities();
await assignScheduleActivities(scheduleActivities);
} catch(e) {
onError(e);
} finally {
setBusyForObject(isLoadingEvents, false);
}
return activities ?? [];
}


Future assignScheduleActivities(
List<ScheduleActivity> listOfSchedules) async {
Expand Down Expand Up @@ -351,10 +345,11 @@ class ScheduleViewModel extends FutureViewModel<List<CourseActivity>> {
try {
setBusyForObject(isLoadingEvents, true);
await _courseRepository.getCoursesActivities();
setBusyForObject(isLoadingEvents, false);
notifyListeners();
} on Exception catch (error) {
onError(error);
} finally {
setBusyForObject(isLoadingEvents, false);
}
}

Expand Down
6 changes: 5 additions & 1 deletion test/viewmodels/schedule_viewmodel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,11 @@ void main() {

verifyInOrder([
courseRepositoryMock.getCoursesActivities(fromCacheOnly: true),
courseRepositoryMock.getCoursesActivities()
courseRepositoryMock.getCoursesActivities(),
courseRepositoryMock.coursesActivities,
courseRepositoryMock.coursesActivities,
courseRepositoryMock.getCourses(fromCacheOnly: true),
courseRepositoryMock.getScheduleActivities(),
]);

verifyNoMoreInteractions(courseRepositoryMock);
Expand Down

0 comments on commit 9393dea

Please sign in to comment.