From 58bb822fe3efae2d44f33a69f18643c52d3ab4b2 Mon Sep 17 00:00:00 2001 From: bannzai Date: Fri, 5 Apr 2024 20:02:53 +0900 Subject: [PATCH 1/3] Fix --- .../components/setting/components/rest_duration/provider.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/features/record/components/setting/components/rest_duration/provider.dart b/lib/features/record/components/setting/components/rest_duration/provider.dart index 7511d0cf7a..e16e6a9aff 100644 --- a/lib/features/record/components/setting/components/rest_duration/provider.dart +++ b/lib/features/record/components/setting/components/rest_duration/provider.dart @@ -256,7 +256,7 @@ class ChangeRestDuration { PillSheetModifiedHistoryServiceActionFactory.createChangedRestDurationBeginDateAction( pillSheetGroupID: pillSheetGroup.id, before: fromRestDurationPillSheet, - after: toRestDurationPillSheet, + after: updatedToRestDurationPillSheet, beforeRestDuration: fromRestDuration, afterRestDuration: toRestDuration, beforePillSheetGroup: pillSheetGroup, @@ -269,7 +269,7 @@ class ChangeRestDuration { PillSheetModifiedHistoryServiceActionFactory.createChangedRestDurationAction( pillSheetGroupID: pillSheetGroup.id, before: fromRestDurationPillSheet, - after: toRestDurationPillSheet, + after: updatedToRestDurationPillSheet, beforeRestDuration: fromRestDuration, afterRestDuration: toRestDuration, beforePillSheetGroup: pillSheetGroup, From e200a3a7090997516b8bd6c85c95fbfaea7884e6 Mon Sep 17 00:00:00 2001 From: bannzai Date: Fri, 5 Apr 2024 20:02:58 +0900 Subject: [PATCH 2/3] Add test caes --- .../supports/button/provider_test.dart | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/test/features/record/components/supports/button/provider_test.dart b/test/features/record/components/supports/button/provider_test.dart index a8d56359b5..d13ab49be4 100644 --- a/test/features/record/components/supports/button/provider_test.dart +++ b/test/features/record/components/supports/button/provider_test.dart @@ -234,4 +234,88 @@ void main() { verify(batchSetPillSheetModifiedHistory(batch, history)).called(1); }); }); + + group("#changeRestDurationBeginDate", () { + test("group has only one pill sheet", () async { + var mockTodayRepository = MockTodayService(); + final mockToday = DateTime.parse("2020-09-19"); + todayRepository = mockTodayRepository; + when(mockTodayRepository.now()).thenReturn(mockToday); + + final mockIDGenerator = MockFirestoreIDGenerator(); + when(mockIDGenerator.call()).thenReturn("rest_duration_id"); + firestoreIDGenerator = mockIDGenerator; + final beforeRestDuration = RestDuration( + id: "rest_duration_id", + beginDate: now(), + createdDate: now(), + endDate: null, + ); + final afterRestDuration = RestDuration( + id: "rest_duration_id", + beginDate: now().subtract(const Duration(days: 1)), + createdDate: now(), + endDate: null, + ); + + final batchFactory = MockBatchFactory(); + final batch = MockWriteBatch(); + when(batchFactory.batch()).thenReturn(batch); + + final pillSheet = PillSheet( + id: "pill_sheet_id_1", + typeInfo: PillSheetType.pillsheet_28_0.typeInfo, + lastTakenDate: null, + beginingDate: now(), + createdAt: now(), + restDurations: [beforeRestDuration], + ); + final updatedPillSheet = pillSheet.copyWith( + restDurations: [afterRestDuration], + ); + + final pillSheetGroup = PillSheetGroup( + id: "group_id", + pillSheetIDs: ["pill_sheet_id_1"].toList(), + pillSheets: [pillSheet], + createdAt: now(), + ); + final updatedPillSheetGroup = PillSheetGroup( + id: "group_id", + pillSheetIDs: ["pill_sheet_id_1"].toList(), + pillSheets: [updatedPillSheet], + createdAt: now(), + ); + final batchSetPillSheetGroup = MockBatchSetPillSheetGroup(); + when(batchSetPillSheetGroup(batch, updatedPillSheetGroup)).thenReturn(updatedPillSheetGroup.copyWith(id: "group_id")); + + final history = PillSheetModifiedHistoryServiceActionFactory.createChangedRestDurationBeginDateAction( + pillSheetGroupID: "group_id", + before: pillSheet, + after: updatedPillSheet, + beforeRestDuration: beforeRestDuration, + afterRestDuration: afterRestDuration, + beforePillSheetGroup: pillSheetGroup, + afterPillSheetGroup: updatedPillSheetGroup, + ); + final batchSetPillSheetModifiedHistory = MockBatchSetPillSheetModifiedHistory(); + when(batchSetPillSheetModifiedHistory(batch, history)).thenReturn(null); + + final beginRestDuration = ChangeRestDuration( + actionType: PillSheetModifiedActionType.changedRestDurationBeginDate, + batchFactory: batchFactory, + batchSetPillSheetGroup: batchSetPillSheetGroup, + batchSetPillSheetModifiedHistory: batchSetPillSheetModifiedHistory); + await beginRestDuration.call( + fromRestDuration: beforeRestDuration, + toRestDuration: afterRestDuration, + pillSheetGroup: pillSheetGroup, + ); + + verify(batchFactory.batch()).called(1); + + verify(batchSetPillSheetGroup(batch, updatedPillSheetGroup)).called(1); + verify(batchSetPillSheetModifiedHistory(batch, history)).called(1); + }); + }); } From ce38cf3a407967298f2f8cd4b3645926d9c744f2 Mon Sep 17 00:00:00 2001 From: bannzai Date: Fri, 5 Apr 2024 20:54:03 +0900 Subject: [PATCH 3/3] Add test case --- .../supports/button/provider_test.dart | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/test/features/record/components/supports/button/provider_test.dart b/test/features/record/components/supports/button/provider_test.dart index d13ab49be4..42e28ff05f 100644 --- a/test/features/record/components/supports/button/provider_test.dart +++ b/test/features/record/components/supports/button/provider_test.dart @@ -318,4 +318,88 @@ void main() { verify(batchSetPillSheetModifiedHistory(batch, history)).called(1); }); }); + + group("#changeRestDuration", () { + test("group has only one pill sheet", () async { + var mockTodayRepository = MockTodayService(); + final mockToday = DateTime.parse("2020-09-19"); + todayRepository = mockTodayRepository; + when(mockTodayRepository.now()).thenReturn(mockToday); + + final mockIDGenerator = MockFirestoreIDGenerator(); + when(mockIDGenerator.call()).thenReturn("rest_duration_id"); + firestoreIDGenerator = mockIDGenerator; + final beforeRestDuration = RestDuration( + id: "rest_duration_id", + beginDate: now(), + createdDate: now(), + endDate: now(), + ); + final afterRestDuration = RestDuration( + id: "rest_duration_id", + beginDate: now().subtract(const Duration(days: 2)), + createdDate: now(), + endDate: now().subtract(const Duration(days: 1)), + ); + + final batchFactory = MockBatchFactory(); + final batch = MockWriteBatch(); + when(batchFactory.batch()).thenReturn(batch); + + final pillSheet = PillSheet( + id: "pill_sheet_id_1", + typeInfo: PillSheetType.pillsheet_28_0.typeInfo, + lastTakenDate: null, + beginingDate: now(), + createdAt: now(), + restDurations: [beforeRestDuration], + ); + final updatedPillSheet = pillSheet.copyWith( + restDurations: [afterRestDuration], + ); + + final pillSheetGroup = PillSheetGroup( + id: "group_id", + pillSheetIDs: ["pill_sheet_id_1"].toList(), + pillSheets: [pillSheet], + createdAt: now(), + ); + final updatedPillSheetGroup = PillSheetGroup( + id: "group_id", + pillSheetIDs: ["pill_sheet_id_1"].toList(), + pillSheets: [updatedPillSheet], + createdAt: now(), + ); + final batchSetPillSheetGroup = MockBatchSetPillSheetGroup(); + when(batchSetPillSheetGroup(batch, updatedPillSheetGroup)).thenReturn(updatedPillSheetGroup.copyWith(id: "group_id")); + + final history = PillSheetModifiedHistoryServiceActionFactory.createChangedRestDurationAction( + pillSheetGroupID: "group_id", + before: pillSheet, + after: updatedPillSheet, + beforeRestDuration: beforeRestDuration, + afterRestDuration: afterRestDuration, + beforePillSheetGroup: pillSheetGroup, + afterPillSheetGroup: updatedPillSheetGroup, + ); + final batchSetPillSheetModifiedHistory = MockBatchSetPillSheetModifiedHistory(); + when(batchSetPillSheetModifiedHistory(batch, history)).thenReturn(null); + + final beginRestDuration = ChangeRestDuration( + actionType: PillSheetModifiedActionType.changedRestDuration, + batchFactory: batchFactory, + batchSetPillSheetGroup: batchSetPillSheetGroup, + batchSetPillSheetModifiedHistory: batchSetPillSheetModifiedHistory); + await beginRestDuration.call( + fromRestDuration: beforeRestDuration, + toRestDuration: afterRestDuration, + pillSheetGroup: pillSheetGroup, + ); + + verify(batchFactory.batch()).called(1); + + verify(batchSetPillSheetGroup(batch, updatedPillSheetGroup)).called(1); + verify(batchSetPillSheetModifiedHistory(batch, history)).called(1); + }); + }); }