Skip to content

Check if the active course reviews are completed instead of all course reviews #1188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/data/services/signets-api/models/course.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ class Course {
if (reviews == null) {
return true;
}
return reviews!.every((review) => review.isCompleted);

final now = DateTime.now();
final activeReviews =
reviews!.where((review) => review.startAt.isBefore(now) && review.endAt.isAfter(now)).toList();

return activeReviews.isNotEmpty && activeReviews.every((review) => review.isCompleted);
}

Course(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,19 @@ void main() {
isCompleted: false,
);

final futureInactiveCourseReview = CourseReview(
acronym: 'GEN101',
group: '02',
teacherName: 'TEST',
startAt: DateTime.now().add(const Duration(days: 30)),
endAt: DateTime.now().add(const Duration(days: 60)),
type: 'Cours',
isCompleted: false,
);

final completedReviewList = <CourseReview>[completedCourseReview];
final nonCompletedReviewList = <CourseReview>[nonCompletedCourseReview];
final nonCompletedReviewList = <CourseReview>[nonCompletedCourseReview, futureInactiveCourseReview];
final semiCompletedReviewList = <CourseReview>[completedCourseReview, futureInactiveCourseReview];

final Course course = Course(
acronym: 'GEN101',
Expand All @@ -92,6 +103,16 @@ void main() {
title: 'Cours générique',
);

final Course courseWithEvaluationSemiCompleted = Course(
acronym: 'GEN101',
group: '02',
session: 'H2020',
programCode: '999',
numberOfCredits: 3,
title: 'Cours générique',
summary: courseSummary,
reviews: semiCompletedReviewList);

final Course courseWithEvaluationNotCompleted = Course(
acronym: 'GEN101',
group: '02',
Expand Down Expand Up @@ -204,6 +225,34 @@ void main() {

expect(find.byKey(const Key("EvaluationNotCompleted")), findsOneWidget);
});

testWidgets(
'display regular course content (evaluations, circular progress, etc) when in the evaluation period and the evaluation is completed with a future (inactive) review not completed',
(WidgetTester tester) async {
setupFlutterToastMock(tester);
CourseRepositoryMock.stubGetCourseSummary(courseRepositoryMock, courseWithEvaluationSemiCompleted,
toReturn: courseWithEvaluationSemiCompleted);
await tester.runAsync(() async {
await tester.pumpWidget(localizedWidget(child: GradesDetailsView(course: courseWithEvaluationSemiCompleted)));
await tester.pumpAndSettle(const Duration(seconds: 2));
}).then(
(value) {
expect(find.byType(RefreshIndicator), findsOneWidget);

// Find all the grade circular progress
expect(find.byKey(const Key("GradeCircularProgress_summary")), findsOneWidget);
for (final eval in courseSummary.evaluations) {
expect(find.byKey(Key("GradeCircularProgress_${eval.title}")), findsOneWidget);
}

expect(find.byType(Card), findsNWidgets(5));

for (final eval in courseSummary.evaluations) {
expect(find.byKey(Key("GradeEvaluationTile_${eval.title}")), findsOneWidget);
}
},
);
});
});
});
}
Loading