Skip to content

Commit

Permalink
Do nothing when user tries to create "in 0 lessons" due date chip. (#…
Browse files Browse the repository at this point in the history
…1277)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Ensured that the "in X lessons" chip is not added if the lesson count
is zero or less.
- **Tests**
- Added tests to validate the correct behavior when no lessons are
specified.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Nils Reichardt <[email protected]>
  • Loading branch information
Jonas-Sander and nilsreichardt authored Jan 22, 2024
1 parent 9a63c4b commit 10229b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/lib/homework/homework_dialog/homework_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,9 @@ class _DueDateChipsController extends ChangeNotifier {
}

void addInXLessonsChip(InXLessonsDueDateSelection inXLessons) {
if (inXLessons.inXLessons <= 0) {
return;
}
final alreadyExists = chips.firstWhereOrNull(
(chip) => chip.dueDate == inXLessons,
) !=
Expand Down
16 changes: 16 additions & 0 deletions app/test/homework/homework_dialog_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,22 @@ void main() {
expect(controller.getSelectedLessonChips(), ['Nächste Stunde']);
expect(nrOfChipsBefore, nrOfChipsAfter);
});
testWidgets(
'regression test: when trying to create a custom "in 0 lessons" chip no chip will be added',
(tester) async {
final controller = createController(tester);
controller.addCourse(courseWith(id: 'foo_course'));
controller.addNextLessonDates('foo_course', [Date('2023-11-06')]);
await pumpAndSettleHomeworkDialog(tester,
showDueDateSelectionChips: true);

final nrOfChipsBefore = controller.getLessonChips().length;
await controller.selectCourse('foo_course');
await controller.createCustomChip(inXLessons: 0);
final nrOfChipsAfter = controller.getLessonChips().length;

expect(nrOfChipsBefore, nrOfChipsAfter);
});
testWidgets(
'when creating a "in 5 lessons" custom chip it will be selected and the correct date will be selected',
(tester) async {
Expand Down

0 comments on commit 10229b7

Please sign in to comment.