Skip to content

Commit

Permalink
Fix wrong homework section title for end-of-month.
Browse files Browse the repository at this point in the history
The heading "Später" (later) was wrongly shown if the current day is the end of month and the due date for the homework is the start of the next month. This was caused by using `addDaysWithNoChecking` instead of `addDays`.

Fixes #53.
  • Loading branch information
Jonas-Sander committed Oct 25, 2023
1 parent de1c75f commit 1865b22
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class TodoDateSubcategorizer extends Subcategorizer {
List<HomeworkSectionView> subcategorize(HomeworkList homeworks) {
final latestHomeworkList = homeworks;
final now = currentDate;
final tomorrow = now.addDaysWithNoChecking(1);
final in2Days = tomorrow.addDaysWithNoChecking(1);
final tomorrow = now.addDays(1);
final in2Days = tomorrow.addDays(1);

final List<HomeworkReadModel> overdueHomework = latestHomeworkList
.where((h) => Date.fromDateTime(h.todoDate) < now)
Expand Down
26 changes: 24 additions & 2 deletions lib/hausaufgabenheft_logik/test/homework_page_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,28 @@ void main() {
}
}

test(
// https://github.com/SharezoneApp/sharezone-app/issues/53
'Regressions test: Shows "Morgen" as section title if today is end of month (e.g. 31.10) and tomorrow is first of next month (e.g. 01.11)',
() async {
repository = createRepositoy();
final kvs = InMemoryKeyValueStore();
bloc = createBloc(repository,
keyValueStore: kvs, getCurrentDateTime: () => DateTime(2023, 10, 31));
homeworkSortingCache = HomeworkSortingCache(kvs);

await addToRepository([
createHomework(
id: 'hw', todoDate: const Date(year: 2023, month: 11, day: 1))
], repository);

bloc.add(LoadHomeworks());

Success success = await bloc.stream.whereType<Success>().first;

expect(success.open.sections.first.title, 'Morgen');
});

test(
'Regressions Test für #954 "Wenn man Hausaufgaben nach Fach sortiert und dann eine Aufgabe abhakt wechselt die App automatisch wieder in die Ansicht nach Datum."',
() async {
Expand Down Expand Up @@ -277,8 +299,8 @@ void main() {
});

test('date subcategory titles are only shown when necessary', () async {
final tomorrow = createHomework(
title: 'abc', todoDate: Date.now().addDaysWithNoChecking(1));
final tomorrow =
createHomework(title: 'abc', todoDate: Date.now().addDays(1));
await addToRepository([tomorrow]);
bloc.add(LoadHomeworks());

Expand Down

0 comments on commit 1865b22

Please sign in to comment.