diff --git a/lib/entity/pill_sheet.codegen.dart b/lib/entity/pill_sheet.codegen.dart index ce9b5aba2e..6c03ebcd39 100644 --- a/lib/entity/pill_sheet.codegen.dart +++ b/lib/entity/pill_sheet.codegen.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:flutter/material.dart'; import 'package:pilll/entity/firestore_id_generator.dart'; import 'package:pilll/utils/datetime/date_add.dart'; @@ -125,12 +127,31 @@ class PillSheet with _$PillSheet { // lastTakenPillNumber は最後に服了したピルの番号を返す // あえてnon nullにしている。なぜならよく比較するのでnullableだと不便だから // まだpillを飲んでない場合は `0` が変える。飲んでいる場合は 1以上の値が入る - int get lastTakenPillNumber { + int get lastTakenOrZeroPillNumber { final lastTakenDate = this.lastTakenDate; if (lastTakenDate == null) { return 0; } + // NOTE: [PillSheet:OLD_Calc_LastTakenPillNumber] 服用日が開始日より前の場合がある。服用日数を1つ目の1番目のピルシートに調整した時 + if (lastTakenDate.isBefore(beginingDate)) { + return 0; + } + + return pillNumberFor(targetDate: lastTakenDate); + } + + int? get lastTakenPillNumber { + final lastTakenDate = this.lastTakenDate; + if (lastTakenDate == null) { + return null; + } + + // NOTE: [PillSheet:OLD_Calc_LastTakenPillNumber] 服用日が開始日より前の場合がある。服用日数を1つ目の1番目のピルシートに調整した時 + if (lastTakenDate.isBefore(beginingDate)) { + return null; + } + return pillNumberFor(targetDate: lastTakenDate); } @@ -144,7 +165,7 @@ class PillSheet with _$PillSheet { return lastTakenDate.isAfter(today()) || isSameDay(lastTakenDate, today()); } - bool get isTakenAll => typeInfo.totalCount == lastTakenPillNumber; + bool get isTakenAll => typeInfo.totalCount == lastTakenOrZeroPillNumber; bool get isBegan => beginingDate.date().toUtc().millisecondsSinceEpoch < now().toUtc().millisecondsSinceEpoch; bool get inNotTakenDuration => todayPillNumber > typeInfo.dosingPeriod; bool get pillSheetHasRestOrFakeDuration => !pillSheetType.isNotExistsNotTakenDuration; @@ -179,8 +200,10 @@ class PillSheet with _$PillSheet { return dates[pillNumberInPillSheet - 1]; } + // NOTE: [PillSheet:OLD_Calc_LastTakenPillNumber] beginDate > targetDate(lastTakenDate) の場合がある。「本日の服用日」を編集して1番目を未服用にした場合 + // pillNumberは0は不自然なので、1番を返す int pillNumberFor({required DateTime targetDate}) { - return daysBetween(beginingDate.date(), targetDate) - summarizedRestDuration(restDurations: restDurations, upperDate: targetDate) + 1; + return max(daysBetween(beginingDate.date(), targetDate) - summarizedRestDuration(restDurations: restDurations, upperDate: targetDate) + 1, 1); } // ピルシートのピルの日付を取得する diff --git a/lib/entity/pill_sheet_group.codegen.dart b/lib/entity/pill_sheet_group.codegen.dart index 4a89f47f81..189bdbb1c1 100644 --- a/lib/entity/pill_sheet_group.codegen.dart +++ b/lib/entity/pill_sheet_group.codegen.dart @@ -1,4 +1,5 @@ import 'package:collection/collection.dart'; +import 'package:flutter/material.dart'; import 'package:pilll/entity/firestore_timestamp_converter.dart'; import 'package:pilll/entity/pill_sheet.codegen.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; @@ -111,6 +112,35 @@ class PillSheetGroup with _$PillSheetGroup { } } + PillSheet get lastTakenPillSheetOrFirstPillSheet { + for (final pillSheet in pillSheets.reversed) { + if (pillSheet.lastTakenDate != null) { + return pillSheet; + } + } + return pillSheets[0]; + } + + // テストまで作ったが、プロダクションではまだ使ってない。とはいえ普通に使うメソッドなので visibleForTestingにしておく + @visibleForTesting + int? get lastTakenPillNumberWithoutDate { + for (final pillSheet in pillSheets.reversed) { + final lastTakenPillNumber = pillSheet.lastTakenPillNumber; + if (lastTakenPillNumber != null) { + switch (pillSheetAppearanceMode) { + case PillSheetAppearanceMode.number: + case PillSheetAppearanceMode.date: + return _pillNumberInPillSheet(pillNumberInPillSheet: lastTakenPillNumber); + case PillSheetAppearanceMode.sequential: + return _sequentialPillSheetNumber(pageIndex: pillSheet.groupIndex, pillNumberInPillSheet: lastTakenPillNumber); + case PillSheetAppearanceMode.cyclicSequential: + return _cycleSequentialPillSheetNumber(pageIndex: pillSheet.groupIndex, pillNumberInPillSheet: lastTakenPillNumber); + } + } + } + return null; + } + List get pillSheetTypes => pillSheets.map((e) => e.pillSheetType).toList(); List get restDurations { @@ -120,50 +150,85 @@ class PillSheetGroup with _$PillSheetGroup { ); } - late final List pillMarksPillNumber = _pillMarksPillNumber(); + late final List pillNumbersInPillSheet = _pillNumbersInPillSheet(); late final List pillNumbersForSequential = _pillNumbersForSequential(); late final List pillNumbersForCyclicSequential = _pillNumbersForCyclicSequential(); } extension PillSheetGroupDisplayDomain on PillSheetGroup { - // 日付以外を返す - String displayPillNumberOnlyNumber({ + int pillNumberWithoutDateOrZero({ + // 例えば履歴の表示の際にbeforePillSheetGroupとafterPillSheetGroupのpillSheetAppearanceModeが違う場合があるので、pillSheetAppearanceModeを引数にする required PillSheetAppearanceMode pillSheetAppearanceMode, required int pageIndex, required int pillNumberInPillSheet, }) { + // pillNumberInPillSheet: lastTakenOrZeroPillNumberが0の場合に0を返す + // PillSheetModifiedHistoryPillNumberOrDate.taken で beforeLastTakenPillNumber にプラス1しており、整合性を保つため + if (pillNumberInPillSheet == 0) { + return 0; + } + switch (pillSheetAppearanceMode) { + case PillSheetAppearanceMode.number: + return _pillNumberInPillSheet(pillNumberInPillSheet: pillNumberInPillSheet); + case PillSheetAppearanceMode.date: + return _pillNumberInPillSheet(pillNumberInPillSheet: pillNumberInPillSheet); case PillSheetAppearanceMode.sequential: - return _displaySequentialPillSheetNumber(pageIndex: pageIndex, pillNumberInPillSheet: pillNumberInPillSheet); + return _sequentialPillSheetNumber(pageIndex: pageIndex, pillNumberInPillSheet: pillNumberInPillSheet); + case PillSheetAppearanceMode.cyclicSequential: + return _cycleSequentialPillSheetNumber(pageIndex: pageIndex, pillNumberInPillSheet: pillNumberInPillSheet); + } + } + + int pillNumberWithoutDateOrZeroFromDate({ + // 例えば履歴の表示の際にbeforePillSheetGroupとafterPillSheetGroupのpillSheetAppearanceModeが違う場合があるので、pillSheetAppearanceModeを引数にする + required PillSheetAppearanceMode pillSheetAppearanceMode, + required DateTime date, + }) { + switch (pillSheetAppearanceMode) { case PillSheetAppearanceMode.number: - return _displayPillNumberInPillSheet(pillNumberInPillSheet: pillNumberInPillSheet); + return pillNumbersInPillSheet.firstWhere((e) => isSameDay(e.date, date)).number; case PillSheetAppearanceMode.date: - return _displayPillNumberInPillSheet(pillNumberInPillSheet: pillNumberInPillSheet); + return pillNumbersInPillSheet.firstWhere((e) => isSameDay(e.date, date)).number; + case PillSheetAppearanceMode.sequential: + return pillNumbersForSequential.firstWhere((e) => isSameDay(e.date, date)).number; case PillSheetAppearanceMode.cyclicSequential: - return _displayCycleSequentialPillSheetNumber(pageIndex: pageIndex, pillNumberInPillSheet: pillNumberInPillSheet); + return pillNumbersForCyclicSequential.firstWhere((e) => isSameDay(e.date, date)).number; } } - String displayPillNumber({ + // 日付以外を返す + String displayPillNumberWithoutDate({ + required int pageIndex, + required int pillNumberInPillSheet, + }) { + return pillNumberWithoutDateOrZero( + pillSheetAppearanceMode: pillSheetAppearanceMode, + pageIndex: pageIndex, + pillNumberInPillSheet: pillNumberInPillSheet, + ).toString(); + } + + String displayPillNumberOrDate({ required bool premiumOrTrial, required int pageIndex, required int pillNumberInPillSheet, }) { - return switch (pillSheetAppearanceMode) { - PillSheetAppearanceMode.number => _displayPillNumberInPillSheet(pillNumberInPillSheet: pillNumberInPillSheet), + final pillNumber = switch (pillSheetAppearanceMode) { + PillSheetAppearanceMode.number => _pillNumberInPillSheet(pillNumberInPillSheet: pillNumberInPillSheet), PillSheetAppearanceMode.date => premiumOrTrial ? _displayPillSheetDate(pageIndex: pageIndex, pillNumberInPillSheet: pillNumberInPillSheet) - : _displayPillNumberInPillSheet(pillNumberInPillSheet: pillNumberInPillSheet), - PillSheetAppearanceMode.sequential => _displaySequentialPillSheetNumber(pageIndex: pageIndex, pillNumberInPillSheet: pillNumberInPillSheet), - PillSheetAppearanceMode.cyclicSequential => - _displayCycleSequentialPillSheetNumber(pageIndex: pageIndex, pillNumberInPillSheet: pillNumberInPillSheet), + : _pillNumberInPillSheet(pillNumberInPillSheet: pillNumberInPillSheet), + PillSheetAppearanceMode.sequential => _sequentialPillSheetNumber(pageIndex: pageIndex, pillNumberInPillSheet: pillNumberInPillSheet), + PillSheetAppearanceMode.cyclicSequential => _cycleSequentialPillSheetNumber(pageIndex: pageIndex, pillNumberInPillSheet: pillNumberInPillSheet), }; + return pillNumber.toString(); } - String _displayPillNumberInPillSheet({ + int _pillNumberInPillSheet({ required int pillNumberInPillSheet, }) { - return '$pillNumberInPillSheet'; + return pillNumberInPillSheet; } @visibleForTesting @@ -182,33 +247,33 @@ extension PillSheetGroupDisplayDomain on PillSheetGroup { } @visibleForTesting - String displaySequentialPillSheetNumber({ + int sequentialPillSheetNumber({ required int pageIndex, required int pillNumberInPillSheet, }) { - return _displaySequentialPillSheetNumber(pageIndex: pageIndex, pillNumberInPillSheet: pillNumberInPillSheet); + return _sequentialPillSheetNumber(pageIndex: pageIndex, pillNumberInPillSheet: pillNumberInPillSheet); } - String _displaySequentialPillSheetNumber({ + int _sequentialPillSheetNumber({ required int pageIndex, required int pillNumberInPillSheet, }) { - return pillNumbersForSequential.where((e) => e.pillSheet.groupIndex == pageIndex).toList()[pillNumberInPillSheet - 1].number.toString(); + return pillNumbersForSequential.where((e) => e.pillSheet.groupIndex == pageIndex).toList()[pillNumberInPillSheet - 1].number; } @visibleForTesting - String displayCycleSequentialPillSheetNumber({ + int cycleSequentialPillSheetNumber({ required int pageIndex, required int pillNumberInPillSheet, }) { - return _displayCycleSequentialPillSheetNumber(pageIndex: pageIndex, pillNumberInPillSheet: pillNumberInPillSheet); + return _cycleSequentialPillSheetNumber(pageIndex: pageIndex, pillNumberInPillSheet: pillNumberInPillSheet); } - String _displayCycleSequentialPillSheetNumber({ + int _cycleSequentialPillSheetNumber({ required int pageIndex, required int pillNumberInPillSheet, }) { - return pillNumbersForCyclicSequential.where((e) => e.pillSheet.groupIndex == pageIndex).toList()[pillNumberInPillSheet - 1].number.toString(); + return pillNumbersForCyclicSequential.where((e) => e.pillSheet.groupIndex == pageIndex).toList()[pillNumberInPillSheet - 1].number; } } @@ -234,7 +299,7 @@ extension PillSheetGroupPillNumberDomain on PillSheetGroup { // NOTE: 日付のbegin,endも.numberと一緒な扱いにする case PillSheetAppearanceMode.number: case PillSheetAppearanceMode.date: - return pillMarksPillNumber; + return pillNumbersInPillSheet; case PillSheetAppearanceMode.sequential: return pillNumbersForSequential; case PillSheetAppearanceMode.cyclicSequential: @@ -242,7 +307,7 @@ extension PillSheetGroupPillNumberDomain on PillSheetGroup { } } - List _pillMarksPillNumber() { + List _pillNumbersInPillSheet() { return pillSheets .map((pillSheet) => pillSheet.dates.indexed.map((e) => PillSheetGroupPillNumberDomainPillMarkValue(pillSheet: pillSheet, date: e.$2, number: e.$1)).toList()) @@ -269,25 +334,31 @@ extension PillSheetGroupPillNumberDomain on PillSheetGroup { final displayNumberSetting = this.displayNumberSetting; if (displayNumberSetting != null) { - final beginPillNumberOffset = displayNumberSetting.beginPillNumber; - if (beginPillNumberOffset != null && beginPillNumberOffset > 0) { - pillMarks = pillMarks.map((e) => e.copyWith(number: e.number + beginPillNumberOffset - 1)).toList(); + final beginPillNumber = displayNumberSetting.beginPillNumber; + if (beginPillNumber != null && beginPillNumber > 0) { + pillMarks = pillMarks.map((e) => e.copyWith(number: e.number + beginPillNumber - 1)).toList(); } - final endPillNumberOffset = displayNumberSetting.endPillNumber; - if (endPillNumberOffset != null && endPillNumberOffset > 0) { - final endPillNumberOffsetIndexes = pillMarks.indexed.where((e) => e.$2.number % endPillNumberOffset == 0).map((e) => e.$1); - final beginPillNumberOffsetIndexes = endPillNumberOffsetIndexes.map((e) => e + 1).toList(); - for (int beginPillNumberOffsetIndex in beginPillNumberOffsetIndexes) { - if (beginPillNumberOffsetIndex < pillMarks.length) { - for (final (sublistIndex, (pillMarkIndex, pillMark)) in pillMarks.indexed.toList().sublist(beginPillNumberOffsetIndex).indexed.toList()) { - pillMarks[pillMarkIndex] = pillMark.copyWith(number: sublistIndex + 1); - } - } + final endPillNumber = displayNumberSetting.endPillNumber; + if (endPillNumber != null && endPillNumber > 0) { + final pillCount = endPillNumber - (beginPillNumber ?? 1) + 1; + debugPrint('endPillNumber: $endPillNumber, beginPillNumber: $beginPillNumber, pillCount: $pillCount'); + for (final (pillMarkIndex, pillMark) in pillMarks.indexed) { + debugPrint('--------------------'); + final loopOffset = (pillMarkIndex ~/ pillCount); + debugPrint('loopOffset: $loopOffset'); + + final countOffset = loopOffset * pillCount; + final number = pillMark.number - countOffset; + debugPrint( + 'index: $pillMarkIndex, pillMark.number: ${pillMark.number}, loopOffset: $loopOffset, countOffset: $countOffset, number: $number, date: ${pillMark.date}'); + pillMarks[pillMarkIndex] = pillMark.copyWith(number: number); } } } + debugPrint(pillMarks.map((e) => '${e.date} ${e.number}').join('\n')); + return pillMarks; } @@ -322,25 +393,31 @@ extension PillSheetGroupPillNumberDomain on PillSheetGroup { final displayNumberSetting = this.displayNumberSetting; if (displayNumberSetting != null) { - final beginPillNumberOffset = displayNumberSetting.beginPillNumber; - if (beginPillNumberOffset != null && beginPillNumberOffset > 0) { - pillMarks = pillMarks.map((e) => e.copyWith(number: e.number + beginPillNumberOffset - 1)).toList(); + final beginPillNumber = displayNumberSetting.beginPillNumber; + if (beginPillNumber != null && beginPillNumber > 0) { + pillMarks = pillMarks.map((e) => e.copyWith(number: e.number + beginPillNumber - 1)).toList(); } - final endPillNumberOffset = displayNumberSetting.endPillNumber; - if (endPillNumberOffset != null && endPillNumberOffset > 0) { - final endPillNumberOffsetIndexes = pillMarks.indexed.where((e) => e.$2.number % endPillNumberOffset == 0).map((e) => e.$1); - final beginPillNumberOffsetIndexes = endPillNumberOffsetIndexes.map((e) => e + 1).toList(); - for (int beginPillNumberOffsetIndex in beginPillNumberOffsetIndexes) { - if (beginPillNumberOffsetIndex < pillMarks.length) { - for (final (sublistIndex, (pillMarkIndex, pillMark)) in pillMarks.indexed.toList().sublist(beginPillNumberOffsetIndex).indexed.toList()) { - pillMarks[pillMarkIndex] = pillMark.copyWith(number: sublistIndex + 1); - } - } + final endPillNumber = displayNumberSetting.endPillNumber; + if (endPillNumber != null && endPillNumber > 0) { + final pillCount = endPillNumber - (beginPillNumber ?? 1) + 1; + debugPrint('endPillNumber: $endPillNumber, beginPillNumber: $beginPillNumber, pillCount: $pillCount'); + for (final (pillMarkIndex, pillMark) in pillMarks.indexed) { + debugPrint('--------------------'); + final loopOffset = (pillMarkIndex ~/ pillCount); + debugPrint('loopOffset: $loopOffset'); + + final countOffset = loopOffset * pillCount; + final number = pillMark.number - countOffset; + debugPrint( + 'index: $pillMarkIndex, pillMark.number: ${pillMark.number}, loopOffset: $loopOffset, countOffset: $countOffset, number: $number, date: ${pillMark.date}'); + pillMarks[pillMarkIndex] = pillMark.copyWith(number: number); } } } + debugPrint(pillMarks.map((e) => '${e.date} ${e.number}').join('\n')); + return pillMarks; } } @@ -415,16 +492,6 @@ extension PillSheetGroupRestDurationDomain on PillSheetGroup { return pillSheets.map((e) => e.activeRestDuration).whereNotNull().firstOrNull; } - PillSheet get lastTakenPillSheetOrFirstPillSheet { - for (final pillSheet in pillSheets.reversed) { - if (pillSheet.lastTakenDate != null) { - return pillSheet; - } - } - - return pillSheets[0]; - } - PillSheet get targetBeginRestDurationPillSheet { final PillSheet targetPillSheet; if (lastTakenPillSheetOrFirstPillSheet.isTakenAll) { diff --git a/lib/entity/pill_sheet_modified_history.codegen.dart b/lib/entity/pill_sheet_modified_history.codegen.dart index 309a24ab00..026d40db12 100644 --- a/lib/entity/pill_sheet_modified_history.codegen.dart +++ b/lib/entity/pill_sheet_modified_history.codegen.dart @@ -186,9 +186,9 @@ abstract class PillSheetModifiedHistoryServiceActionFactory { value: PillSheetModifiedHistoryValue( takenPill: TakenPillValue( afterLastTakenDate: afterLastTakenDate, - afterLastTakenPillNumber: after.lastTakenPillNumber, + afterLastTakenPillNumber: after.lastTakenOrZeroPillNumber, beforeLastTakenDate: before.lastTakenDate, - beforeLastTakenPillNumber: before.lastTakenPillNumber, + beforeLastTakenPillNumber: before.lastTakenOrZeroPillNumber, isQuickRecord: isQuickRecord, ), ), @@ -213,7 +213,8 @@ abstract class PillSheetModifiedHistoryServiceActionFactory { final afterID = after.id; final afterLastTakenDate = after.lastTakenDate; - if (afterID == null || afterLastTakenDate == null) { + // since: 2025-01-16 afterLastTakenDate は null許容になった。以前までは服用日の変更やrevert時に1番目のピルシートを指定した場合はbeginingDateの一つ前の日付を入れいたがやめた + if (afterID == null) { throw FormatException('unexpected afterPillSheetID: $afterID or lastTakenDate:${after.lastTakenDate} is null for revertTakenPill action'); } final beforeID = before.id; @@ -227,9 +228,9 @@ abstract class PillSheetModifiedHistoryServiceActionFactory { value: PillSheetModifiedHistoryValue( revertTakenPill: RevertTakenPillValue( afterLastTakenDate: afterLastTakenDate, - afterLastTakenPillNumber: after.lastTakenPillNumber, + afterLastTakenPillNumber: after.lastTakenOrZeroPillNumber, beforeLastTakenDate: beforeLastTakenDate, - beforeLastTakenPillNumber: before.lastTakenPillNumber, + beforeLastTakenPillNumber: before.lastTakenOrZeroPillNumber, ), ), after: after, diff --git a/lib/entity/pill_sheet_modified_history_value.codegen.dart b/lib/entity/pill_sheet_modified_history_value.codegen.dart index 4c07b3a8a3..7b6eab5970 100644 --- a/lib/entity/pill_sheet_modified_history_value.codegen.dart +++ b/lib/entity/pill_sheet_modified_history_value.codegen.dart @@ -162,10 +162,10 @@ class RevertTakenPillValue with _$RevertTakenPillValue { ) DateTime? beforeLastTakenDate, @JsonKey( - fromJson: NonNullTimestampConverter.timestampToDateTime, - toJson: NonNullTimestampConverter.dateTimeToTimestamp, + fromJson: TimestampConverter.timestampToDateTime, + toJson: TimestampConverter.dateTimeToTimestamp, ) - required DateTime afterLastTakenDate, + required DateTime? afterLastTakenDate, required int beforeLastTakenPillNumber, required int afterLastTakenPillNumber, }) = _RevertTakenPillValue; diff --git a/lib/entity/pill_sheet_modified_history_value.codegen.freezed.dart b/lib/entity/pill_sheet_modified_history_value.codegen.freezed.dart index 4e98fa3123..957fa9854c 100644 --- a/lib/entity/pill_sheet_modified_history_value.codegen.freezed.dart +++ b/lib/entity/pill_sheet_modified_history_value.codegen.freezed.dart @@ -1653,8 +1653,8 @@ mixin _$RevertTakenPillValue { // This is deprecated property. TODO: [PillSheetModifiedHistory-V2] delete after 2024-05-01 @JsonKey(fromJson: TimestampConverter.timestampToDateTime, toJson: TimestampConverter.dateTimeToTimestamp) DateTime? get beforeLastTakenDate => throw _privateConstructorUsedError; - @JsonKey(fromJson: NonNullTimestampConverter.timestampToDateTime, toJson: NonNullTimestampConverter.dateTimeToTimestamp) - DateTime get afterLastTakenDate => throw _privateConstructorUsedError; + @JsonKey(fromJson: TimestampConverter.timestampToDateTime, toJson: TimestampConverter.dateTimeToTimestamp) + DateTime? get afterLastTakenDate => throw _privateConstructorUsedError; int get beforeLastTakenPillNumber => throw _privateConstructorUsedError; int get afterLastTakenPillNumber => throw _privateConstructorUsedError; @@ -1670,8 +1670,7 @@ abstract class $RevertTakenPillValueCopyWith<$Res> { @useResult $Res call( {@JsonKey(fromJson: TimestampConverter.timestampToDateTime, toJson: TimestampConverter.dateTimeToTimestamp) DateTime? beforeLastTakenDate, - @JsonKey(fromJson: NonNullTimestampConverter.timestampToDateTime, toJson: NonNullTimestampConverter.dateTimeToTimestamp) - DateTime afterLastTakenDate, + @JsonKey(fromJson: TimestampConverter.timestampToDateTime, toJson: TimestampConverter.dateTimeToTimestamp) DateTime? afterLastTakenDate, int beforeLastTakenPillNumber, int afterLastTakenPillNumber}); } @@ -1689,7 +1688,7 @@ class _$RevertTakenPillValueCopyWithImpl<$Res, $Val extends RevertTakenPillValue @override $Res call({ Object? beforeLastTakenDate = freezed, - Object? afterLastTakenDate = null, + Object? afterLastTakenDate = freezed, Object? beforeLastTakenPillNumber = null, Object? afterLastTakenPillNumber = null, }) { @@ -1698,10 +1697,10 @@ class _$RevertTakenPillValueCopyWithImpl<$Res, $Val extends RevertTakenPillValue ? _value.beforeLastTakenDate : beforeLastTakenDate // ignore: cast_nullable_to_non_nullable as DateTime?, - afterLastTakenDate: null == afterLastTakenDate + afterLastTakenDate: freezed == afterLastTakenDate ? _value.afterLastTakenDate : afterLastTakenDate // ignore: cast_nullable_to_non_nullable - as DateTime, + as DateTime?, beforeLastTakenPillNumber: null == beforeLastTakenPillNumber ? _value.beforeLastTakenPillNumber : beforeLastTakenPillNumber // ignore: cast_nullable_to_non_nullable @@ -1722,8 +1721,7 @@ abstract class _$$RevertTakenPillValueImplCopyWith<$Res> implements $RevertTaken @useResult $Res call( {@JsonKey(fromJson: TimestampConverter.timestampToDateTime, toJson: TimestampConverter.dateTimeToTimestamp) DateTime? beforeLastTakenDate, - @JsonKey(fromJson: NonNullTimestampConverter.timestampToDateTime, toJson: NonNullTimestampConverter.dateTimeToTimestamp) - DateTime afterLastTakenDate, + @JsonKey(fromJson: TimestampConverter.timestampToDateTime, toJson: TimestampConverter.dateTimeToTimestamp) DateTime? afterLastTakenDate, int beforeLastTakenPillNumber, int afterLastTakenPillNumber}); } @@ -1737,7 +1735,7 @@ class __$$RevertTakenPillValueImplCopyWithImpl<$Res> extends _$RevertTakenPillVa @override $Res call({ Object? beforeLastTakenDate = freezed, - Object? afterLastTakenDate = null, + Object? afterLastTakenDate = freezed, Object? beforeLastTakenPillNumber = null, Object? afterLastTakenPillNumber = null, }) { @@ -1746,10 +1744,10 @@ class __$$RevertTakenPillValueImplCopyWithImpl<$Res> extends _$RevertTakenPillVa ? _value.beforeLastTakenDate : beforeLastTakenDate // ignore: cast_nullable_to_non_nullable as DateTime?, - afterLastTakenDate: null == afterLastTakenDate + afterLastTakenDate: freezed == afterLastTakenDate ? _value.afterLastTakenDate : afterLastTakenDate // ignore: cast_nullable_to_non_nullable - as DateTime, + as DateTime?, beforeLastTakenPillNumber: null == beforeLastTakenPillNumber ? _value.beforeLastTakenPillNumber : beforeLastTakenPillNumber // ignore: cast_nullable_to_non_nullable @@ -1768,8 +1766,7 @@ class __$$RevertTakenPillValueImplCopyWithImpl<$Res> extends _$RevertTakenPillVa class _$RevertTakenPillValueImpl extends _RevertTakenPillValue { const _$RevertTakenPillValueImpl( {@JsonKey(fromJson: TimestampConverter.timestampToDateTime, toJson: TimestampConverter.dateTimeToTimestamp) this.beforeLastTakenDate, - @JsonKey(fromJson: NonNullTimestampConverter.timestampToDateTime, toJson: NonNullTimestampConverter.dateTimeToTimestamp) - required this.afterLastTakenDate, + @JsonKey(fromJson: TimestampConverter.timestampToDateTime, toJson: TimestampConverter.dateTimeToTimestamp) required this.afterLastTakenDate, required this.beforeLastTakenPillNumber, required this.afterLastTakenPillNumber}) : super._(); @@ -1782,8 +1779,8 @@ class _$RevertTakenPillValueImpl extends _RevertTakenPillValue { @JsonKey(fromJson: TimestampConverter.timestampToDateTime, toJson: TimestampConverter.dateTimeToTimestamp) final DateTime? beforeLastTakenDate; @override - @JsonKey(fromJson: NonNullTimestampConverter.timestampToDateTime, toJson: NonNullTimestampConverter.dateTimeToTimestamp) - final DateTime afterLastTakenDate; + @JsonKey(fromJson: TimestampConverter.timestampToDateTime, toJson: TimestampConverter.dateTimeToTimestamp) + final DateTime? afterLastTakenDate; @override final int beforeLastTakenPillNumber; @override @@ -1826,8 +1823,8 @@ class _$RevertTakenPillValueImpl extends _RevertTakenPillValue { abstract class _RevertTakenPillValue extends RevertTakenPillValue { const factory _RevertTakenPillValue( {@JsonKey(fromJson: TimestampConverter.timestampToDateTime, toJson: TimestampConverter.dateTimeToTimestamp) final DateTime? beforeLastTakenDate, - @JsonKey(fromJson: NonNullTimestampConverter.timestampToDateTime, toJson: NonNullTimestampConverter.dateTimeToTimestamp) - required final DateTime afterLastTakenDate, + @JsonKey(fromJson: TimestampConverter.timestampToDateTime, toJson: TimestampConverter.dateTimeToTimestamp) + required final DateTime? afterLastTakenDate, required final int beforeLastTakenPillNumber, required final int afterLastTakenPillNumber}) = _$RevertTakenPillValueImpl; const _RevertTakenPillValue._() : super._(); @@ -1839,8 +1836,8 @@ abstract class _RevertTakenPillValue extends RevertTakenPillValue { @JsonKey(fromJson: TimestampConverter.timestampToDateTime, toJson: TimestampConverter.dateTimeToTimestamp) DateTime? get beforeLastTakenDate; @override - @JsonKey(fromJson: NonNullTimestampConverter.timestampToDateTime, toJson: NonNullTimestampConverter.dateTimeToTimestamp) - DateTime get afterLastTakenDate; + @JsonKey(fromJson: TimestampConverter.timestampToDateTime, toJson: TimestampConverter.dateTimeToTimestamp) + DateTime? get afterLastTakenDate; @override int get beforeLastTakenPillNumber; @override diff --git a/lib/entity/pill_sheet_modified_history_value.codegen.g.dart b/lib/entity/pill_sheet_modified_history_value.codegen.g.dart index b3d8e2a2dc..549c43f3cf 100644 --- a/lib/entity/pill_sheet_modified_history_value.codegen.g.dart +++ b/lib/entity/pill_sheet_modified_history_value.codegen.g.dart @@ -119,14 +119,14 @@ Map _$$TakenPillEditedValueImplToJson(_$TakenPillEditedValueImp _$RevertTakenPillValueImpl _$$RevertTakenPillValueImplFromJson(Map json) => _$RevertTakenPillValueImpl( beforeLastTakenDate: TimestampConverter.timestampToDateTime(json['beforeLastTakenDate'] as Timestamp?), - afterLastTakenDate: NonNullTimestampConverter.timestampToDateTime(json['afterLastTakenDate'] as Timestamp), + afterLastTakenDate: TimestampConverter.timestampToDateTime(json['afterLastTakenDate'] as Timestamp?), beforeLastTakenPillNumber: (json['beforeLastTakenPillNumber'] as num).toInt(), afterLastTakenPillNumber: (json['afterLastTakenPillNumber'] as num).toInt(), ); Map _$$RevertTakenPillValueImplToJson(_$RevertTakenPillValueImpl instance) => { 'beforeLastTakenDate': TimestampConverter.dateTimeToTimestamp(instance.beforeLastTakenDate), - 'afterLastTakenDate': NonNullTimestampConverter.dateTimeToTimestamp(instance.afterLastTakenDate), + 'afterLastTakenDate': TimestampConverter.dateTimeToTimestamp(instance.afterLastTakenDate), 'beforeLastTakenPillNumber': instance.beforeLastTakenPillNumber, 'afterLastTakenPillNumber': instance.afterLastTakenPillNumber, }; diff --git a/lib/features/before_pill_sheet_group_history/component/pill_sheet.dart b/lib/features/before_pill_sheet_group_history/component/pill_sheet.dart index 728fc3beb2..ffeb70ba76 100644 --- a/lib/features/before_pill_sheet_group_history/component/pill_sheet.dart +++ b/lib/features/before_pill_sheet_group_history/component/pill_sheet.dart @@ -121,14 +121,14 @@ class HistoricalPillsheetGroupPagePillSheet extends HookConsumerWidget { } if (activePillSheet.id != pillSheet.id) { if (pillSheet.isBegan) { - if (pillNumberInPillSheet > pillSheet.lastTakenPillNumber) { + if (pillNumberInPillSheet > pillSheet.lastTakenOrZeroPillNumber) { return false; } } return true; } - return pillNumberInPillSheet <= activePillSheet.lastTakenPillNumber; + return pillNumberInPillSheet <= activePillSheet.lastTakenOrZeroPillNumber; } } @@ -141,7 +141,7 @@ PillMarkType pillMarkFor({ ? PillMarkType.rest : PillMarkType.fake; } - if (pillNumberInPillSheet <= pillSheet.lastTakenPillNumber) { + if (pillNumberInPillSheet <= pillSheet.lastTakenOrZeroPillNumber) { return PillMarkType.done; } if (pillNumberInPillSheet < pillSheet.todayPillNumber) { @@ -167,14 +167,14 @@ bool shouldPillMarkAnimation({ } if (activePillSheet.id != pillSheet.id) { if (pillSheet.isBegan) { - if (pillNumberInPillSheet > pillSheet.lastTakenPillNumber) { + if (pillNumberInPillSheet > pillSheet.lastTakenOrZeroPillNumber) { return true; } } return false; } - return pillNumberInPillSheet > activePillSheet.lastTakenPillNumber && pillNumberInPillSheet <= activePillSheet.todayPillNumber; + return pillNumberInPillSheet > activePillSheet.lastTakenOrZeroPillNumber && pillNumberInPillSheet <= activePillSheet.todayPillNumber; } class PillNumber extends StatelessWidget { @@ -199,7 +199,7 @@ class PillNumber extends StatelessWidget { final containedMenstruationDuration = menstruationDateRanges.where((e) => e.inRange(pillSheet.displayPillTakeDate(pillNumberInPillSheet))).isNotEmpty; - final text = pillSheetGroup.displayPillNumber( + final text = pillSheetGroup.displayPillNumberOrDate( premiumOrTrial: true, pageIndex: pageIndex, pillNumberInPillSheet: pillNumberInPillSheet, diff --git a/lib/features/calendar/components/pill_sheet_modified_history/components/core/pill_number.dart b/lib/features/calendar/components/pill_sheet_modified_history/components/core/pill_number.dart index 20b7e527ed..75522ab2e6 100644 --- a/lib/features/calendar/components/pill_sheet_modified_history/components/core/pill_number.dart +++ b/lib/features/calendar/components/pill_sheet_modified_history/components/core/pill_number.dart @@ -30,9 +30,10 @@ class PillNumber extends StatelessWidget { abstract class PillSheetModifiedHistoryPillNumberOrDate { static String hyphen() => '-'; - static String taken({required int beforeLastTakenPillNumber, required int afterLastTakenPillNumber}) { + static String taken({required int? beforeLastTakenPillNumber, required int afterLastTakenPillNumber}) { // beforePillSheetの最後に飲んだ番号+1から服用記録が始まる - final left = beforeLastTakenPillNumber + 1; + // nullの場合は服用記録を取り消したり、服用日を移動した際にありえる + final left = (beforeLastTakenPillNumber ?? 0) + 1; // 1度飲みの時に本日分を服用した場合は1錠分の服用履歴を表示する if (left == afterLastTakenPillNumber) { return L.withNumber('$afterLastTakenPillNumber'); diff --git a/lib/features/calendar/components/pill_sheet_modified_history/components/core/taken_pill_action_o_list.dart b/lib/features/calendar/components/pill_sheet_modified_history/components/core/taken_pill_action_o_list.dart index d218d2d30f..9931c852eb 100644 --- a/lib/features/calendar/components/pill_sheet_modified_history/components/core/taken_pill_action_o_list.dart +++ b/lib/features/calendar/components/pill_sheet_modified_history/components/core/taken_pill_action_o_list.dart @@ -3,23 +3,26 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:pilll/entity/pill_sheet.codegen.dart'; +import 'package:pilll/entity/pill_sheet_group.codegen.dart'; import 'package:pilll/entity/pill_sheet_type.dart'; import 'package:pilll/entity/pill_sheet_modified_history_value.codegen.dart'; class TakenPillActionOList extends StatelessWidget { final TakenPillValue value; - final PillSheet beforePillSheet; - final PillSheet afterPillSheet; + final PillSheetGroup beforePillSheetGroup; + final PillSheetGroup afterPillSheetGroup; const TakenPillActionOList({ super.key, required this.value, - required this.beforePillSheet, - required this.afterPillSheet, + required this.beforePillSheetGroup, + required this.afterPillSheetGroup, }); @override Widget build(BuildContext context) { + final beforePillSheet = beforePillSheetGroup.lastTakenPillSheetOrFirstPillSheet; + final afterPillSheet = afterPillSheetGroup.lastTakenPillSheetOrFirstPillSheet; if (beforePillSheet.groupIndex != afterPillSheet.groupIndex) { return SvgPicture.asset('images/dots.svg'); } diff --git a/lib/features/calendar/components/pill_sheet_modified_history/components/rows/pill_sheet_modified_history_changed_pill_number_action.dart b/lib/features/calendar/components/pill_sheet_modified_history/components/rows/pill_sheet_modified_history_changed_pill_number_action.dart index 5ac512556b..0d67023fa0 100644 --- a/lib/features/calendar/components/pill_sheet_modified_history/components/rows/pill_sheet_modified_history_changed_pill_number_action.dart +++ b/lib/features/calendar/components/pill_sheet_modified_history/components/rows/pill_sheet_modified_history_changed_pill_number_action.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:pilll/components/atoms/font.dart'; import 'package:pilll/components/atoms/text_color.dart'; +import 'package:pilll/entity/pill_sheet_group.codegen.dart'; +import 'package:pilll/entity/pill_sheet_modified_history.codegen.dart'; import 'package:pilll/features/calendar/components/pill_sheet_modified_history/components/core/day.dart'; import 'package:pilll/features/calendar/components/pill_sheet_modified_history/components/core/pill_number.dart'; import 'package:pilll/features/calendar/components/pill_sheet_modified_history/components/core/row_layout.dart'; @@ -8,22 +10,29 @@ import 'package:pilll/features/localizations/l.dart'; class PillSheetModifiedHistoryChangedPillNumberAction extends StatelessWidget { final DateTime estimatedEventCausingDate; - final int? beforeTodayPillNumber; - final int? afterTodayPillNumber; + final PillSheetModifiedHistory history; const PillSheetModifiedHistoryChangedPillNumberAction({ super.key, required this.estimatedEventCausingDate, - required this.beforeTodayPillNumber, - required this.afterTodayPillNumber, + required this.history, }); @override Widget build(BuildContext context) { - final beforeTodayPillNumber = this.beforeTodayPillNumber; - final afterTodayPillNumber = this.afterTodayPillNumber; - if (beforeTodayPillNumber == null || afterTodayPillNumber == null) { - return Container(); + final beforePillSheetGroup = history.beforePillSheetGroup; + final afterPillSheetGroup = history.afterPillSheetGroup; + if (beforePillSheetGroup == null || afterPillSheetGroup == null) { + return Text(L.failedToGetPillSheetHistory('changedPillNumber')); } + final beforeTodayPillNumber = beforePillSheetGroup.pillNumberWithoutDateOrZeroFromDate( + pillSheetAppearanceMode: afterPillSheetGroup.pillSheetAppearanceMode, + date: estimatedEventCausingDate, + ); + final afterTodayPillNumber = afterPillSheetGroup.pillNumberWithoutDateOrZeroFromDate( + pillSheetAppearanceMode: afterPillSheetGroup.pillSheetAppearanceMode, + date: estimatedEventCausingDate, + ); + return RowLayout( day: Day(estimatedEventCausingDate: estimatedEventCausingDate), pillNumbersOrHyphenOrDate: PillNumber( diff --git a/lib/features/calendar/components/pill_sheet_modified_history/components/rows/pill_sheet_modified_history_revert_taken_pill_action.dart b/lib/features/calendar/components/pill_sheet_modified_history/components/rows/pill_sheet_modified_history_revert_taken_pill_action.dart index a458f19d9b..f3efd9c8a5 100644 --- a/lib/features/calendar/components/pill_sheet_modified_history/components/rows/pill_sheet_modified_history_revert_taken_pill_action.dart +++ b/lib/features/calendar/components/pill_sheet_modified_history/components/rows/pill_sheet_modified_history_revert_taken_pill_action.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:pilll/components/atoms/font.dart'; import 'package:pilll/components/atoms/text_color.dart'; +import 'package:pilll/entity/pill_sheet_group.codegen.dart'; +import 'package:pilll/entity/pill_sheet_modified_history.codegen.dart'; import 'package:pilll/features/calendar/components/pill_sheet_modified_history/components/core/day.dart'; import 'package:pilll/features/calendar/components/pill_sheet_modified_history/components/core/pill_number.dart'; import 'package:pilll/features/calendar/components/pill_sheet_modified_history/components/core/row_layout.dart'; @@ -8,22 +10,31 @@ import 'package:pilll/features/localizations/l.dart'; class PillSheetModifiedHistoryRevertTakenPillAction extends StatelessWidget { final DateTime estimatedEventCausingDate; - final int? beforeLastTakenPillNumber; - final int? afterLastTakenPillNumber; + final PillSheetModifiedHistory history; const PillSheetModifiedHistoryRevertTakenPillAction({ super.key, required this.estimatedEventCausingDate, - required this.beforeLastTakenPillNumber, - required this.afterLastTakenPillNumber, + required this.history, }); @override Widget build(BuildContext context) { - final beforeLastTakenPillNumber = this.beforeLastTakenPillNumber; - final afterLastTakenPillNumber = this.afterLastTakenPillNumber; - if (beforeLastTakenPillNumber == null || afterLastTakenPillNumber == null) { - return Container(); + final beforePillSheetGroup = history.beforePillSheetGroup; + final afterPillSheetGroup = history.afterPillSheetGroup; + if (beforePillSheetGroup == null || afterPillSheetGroup == null) { + return Text(L.failedToGetPillSheetHistory('revertTakenPill')); } + final beforeLastTakenPillNumber = beforePillSheetGroup.pillNumberWithoutDateOrZero( + // 例えば履歴の表示の際にbeforePillSheetGroupとafterPillSheetGroupのpillSheetAppearanceModeが違う場合があるので、afterPillSheetGroup.pillSheetAppearanceModeを引数にする + pillSheetAppearanceMode: afterPillSheetGroup.pillSheetAppearanceMode, + pageIndex: beforePillSheetGroup.lastTakenPillSheetOrFirstPillSheet.groupIndex, + pillNumberInPillSheet: beforePillSheetGroup.lastTakenPillSheetOrFirstPillSheet.lastTakenOrZeroPillNumber, + ); + final afterLastTakenPillNumber = afterPillSheetGroup.pillNumberWithoutDateOrZero( + pillSheetAppearanceMode: afterPillSheetGroup.pillSheetAppearanceMode, + pageIndex: afterPillSheetGroup.lastTakenPillSheetOrFirstPillSheet.groupIndex, + pillNumberInPillSheet: afterPillSheetGroup.lastTakenPillSheetOrFirstPillSheet.lastTakenOrZeroPillNumber, + ); return RowLayout( day: Day(estimatedEventCausingDate: estimatedEventCausingDate), pillNumbersOrHyphenOrDate: PillNumber( diff --git a/lib/features/calendar/components/pill_sheet_modified_history/components/rows/pill_sheet_modified_history_taken_pill_action.dart b/lib/features/calendar/components/pill_sheet_modified_history/components/rows/pill_sheet_modified_history_taken_pill_action.dart index 73b7746849..3cc26790c4 100644 --- a/lib/features/calendar/components/pill_sheet_modified_history/components/rows/pill_sheet_modified_history_taken_pill_action.dart +++ b/lib/features/calendar/components/pill_sheet_modified_history/components/rows/pill_sheet_modified_history_taken_pill_action.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:pilll/entity/pill_sheet_group.codegen.dart'; import 'package:pilll/features/localizations/l.dart'; import 'package:pilll/utils/analytics.dart'; import 'package:pilll/features/calendar/components/pill_sheet_modified_history/components/core/day.dart'; @@ -7,7 +8,6 @@ import 'package:pilll/features/calendar/components/pill_sheet_modified_history/c import 'package:pilll/features/calendar/components/pill_sheet_modified_history/components/core/row_layout.dart'; import 'package:pilll/features/calendar/components/pill_sheet_modified_history/components/core/time.dart'; import 'package:pilll/features/calendar/components/pill_sheet_modified_history/components/core/taken_pill_action_o_list.dart'; -import 'package:pilll/entity/pill_sheet.codegen.dart'; import 'package:pilll/entity/pill_sheet_modified_history.codegen.dart'; import 'package:pilll/entity/pill_sheet_modified_history_value.codegen.dart'; import 'package:pilll/features/error/error_alert.dart'; @@ -20,8 +20,6 @@ class PillSheetModifiedHistoryTakenPillAction extends HookConsumerWidget { final DateTime estimatedEventCausingDate; final PillSheetModifiedHistory history; final TakenPillValue? value; - final PillSheet? beforePillSheet; - final PillSheet? afterPillSheet; const PillSheetModifiedHistoryTakenPillAction({ super.key, @@ -29,18 +27,16 @@ class PillSheetModifiedHistoryTakenPillAction extends HookConsumerWidget { required this.estimatedEventCausingDate, required this.history, required this.value, - required this.beforePillSheet, - required this.afterPillSheet, }); @override Widget build(BuildContext context, WidgetRef ref) { final setPillSheetModifiedHistory = ref.watch(setPillSheetModifiedHistoryProvider); final value = this.value; - final beforePillSheet = this.beforePillSheet; - final afterPillSheet = this.afterPillSheet; - if (value == null || afterPillSheet == null || beforePillSheet == null) { - return Container(); + final beforePillSheetGroup = history.beforePillSheetGroup; + final afterPillSheetGroup = history.afterPillSheetGroup; + if (value == null || afterPillSheetGroup == null || beforePillSheetGroup == null) { + return Text(L.failedToGetPillSheetHistory('takenPill')); } final time = DateTimeFormatter.hourAndMinute(estimatedEventCausingDate); @@ -88,14 +84,23 @@ class PillSheetModifiedHistoryTakenPillAction extends HookConsumerWidget { day: Day(estimatedEventCausingDate: estimatedEventCausingDate), pillNumbersOrHyphenOrDate: PillNumber( pillNumber: PillSheetModifiedHistoryPillNumberOrDate.taken( - beforeLastTakenPillNumber: beforePillSheet.lastTakenPillNumber, - afterLastTakenPillNumber: afterPillSheet.lastTakenPillNumber, + beforeLastTakenPillNumber: beforePillSheetGroup.pillNumberWithoutDateOrZero( + // 例えば履歴の表示の際にbeforePillSheetGroupとafterPillSheetGroupのpillSheetAppearanceModeが違う場合があるので、afterPillSheetGroup.pillSheetAppearanceModeを引数にする + pillSheetAppearanceMode: afterPillSheetGroup.pillSheetAppearanceMode, + pageIndex: beforePillSheetGroup.lastTakenPillSheetOrFirstPillSheet.groupIndex, + pillNumberInPillSheet: beforePillSheetGroup.lastTakenPillSheetOrFirstPillSheet.lastTakenOrZeroPillNumber, + ), + afterLastTakenPillNumber: afterPillSheetGroup.pillNumberWithoutDateOrZero( + pillSheetAppearanceMode: afterPillSheetGroup.pillSheetAppearanceMode, + pageIndex: afterPillSheetGroup.lastTakenPillSheetOrFirstPillSheet.groupIndex, + pillNumberInPillSheet: afterPillSheetGroup.lastTakenPillSheetOrFirstPillSheet.lastTakenOrZeroPillNumber, + ), )), detail: Time(time: time), takenPillActionOList: TakenPillActionOList( value: value, - beforePillSheet: beforePillSheet, - afterPillSheet: afterPillSheet, + beforePillSheetGroup: beforePillSheetGroup, + afterPillSheetGroup: afterPillSheetGroup, ), ), ); diff --git a/lib/features/calendar/components/pill_sheet_modified_history/pill_sheet_modified_history_list.dart b/lib/features/calendar/components/pill_sheet_modified_history/pill_sheet_modified_history_list.dart index 122ebb401f..088cd06d6d 100644 --- a/lib/features/calendar/components/pill_sheet_modified_history/pill_sheet_modified_history_list.dart +++ b/lib/features/calendar/components/pill_sheet_modified_history/pill_sheet_modified_history_list.dart @@ -79,12 +79,12 @@ class PillSheetModifiedHistoryList extends HookConsumerWidget { .findFirstDifferencePillSheet( history.afterPillSheetGroup?.pillSheets, ) - ?.lastTakenPillNumber, + ?.lastTakenOrZeroPillNumber, afterLastTakenPillNumber: history.afterPillSheetGroup?.pillSheets.reversed .findFirstDifferencePillSheet( history.beforePillSheetGroup?.pillSheets.reversed, ) - ?.lastTakenPillNumber), + ?.lastTakenOrZeroPillNumber), PillSheetModifiedActionType.deletedPillSheet => PillSheetModifiedHistoryDeletedPillSheetAction( estimatedEventCausingDate: history.estimatedEventCausingDate, pillSheetIDs: history.afterPillSheetGroup?.pillSheetIDs), PillSheetModifiedActionType.takenPill => PillSheetModifiedHistoryTakenPillAction( @@ -92,29 +92,15 @@ class PillSheetModifiedHistoryList extends HookConsumerWidget { estimatedEventCausingDate: history.estimatedEventCausingDate, history: history, value: history.value.takenPill, - beforePillSheet: history.beforePillSheetGroup?.pillSheets.findFirstDifferencePillSheet( - history.afterPillSheetGroup?.pillSheets, - ), - afterPillSheet: history.afterPillSheetGroup?.pillSheets.reversed.findFirstDifferencePillSheet( - history.beforePillSheetGroup?.pillSheets.reversed, - ), ), // NOTE: revertTakenPill は findFirstDifferencePillSheetの向きはtakenPill等とは逆になる。なぜならbeforeの方がafterよりも後ろのピルシートの服用記録になるから、beforeの場合は後ろから(reversed)探索する PillSheetModifiedActionType.revertTakenPill => PillSheetModifiedHistoryRevertTakenPillAction( estimatedEventCausingDate: history.estimatedEventCausingDate, - beforeLastTakenPillNumber: history.beforePillSheetGroup?.pillSheets.reversed - .findFirstDifferencePillSheet(history.afterPillSheetGroup?.pillSheets.reversed) - ?.lastTakenPillNumber, - afterLastTakenPillNumber: history.afterPillSheetGroup?.pillSheets - .findFirstDifferencePillSheet( - history.beforePillSheetGroup?.pillSheets, - ) - ?.lastTakenPillNumber, + history: history, ), PillSheetModifiedActionType.changedPillNumber => PillSheetModifiedHistoryChangedPillNumberAction( estimatedEventCausingDate: history.estimatedEventCausingDate, - beforeTodayPillNumber: history.beforeActivePillSheet?.pillNumberFor(targetDate: history.estimatedEventCausingDate), - afterTodayPillNumber: history.afterActivePillSheet?.pillNumberFor(targetDate: history.estimatedEventCausingDate), + history: history, ), PillSheetModifiedActionType.endedPillSheet => PillSheetModifiedHistoryEndedPillSheetAction( value: history.value.endedPillSheet, @@ -166,18 +152,14 @@ class PillSheetModifiedHistoryList extends HookConsumerWidget { estimatedEventCausingDate: history.estimatedEventCausingDate, history: history, value: history.value.takenPill, - beforePillSheet: history.before, - afterPillSheet: history.after, ), PillSheetModifiedActionType.revertTakenPill => PillSheetModifiedHistoryRevertTakenPillAction( estimatedEventCausingDate: history.estimatedEventCausingDate, - beforeLastTakenPillNumber: history.value.revertTakenPill?.beforeLastTakenPillNumber, - afterLastTakenPillNumber: history.value.revertTakenPill?.afterLastTakenPillNumber, + history: history, ), PillSheetModifiedActionType.changedPillNumber => PillSheetModifiedHistoryChangedPillNumberAction( estimatedEventCausingDate: history.estimatedEventCausingDate, - beforeTodayPillNumber: history.value.changedPillNumber?.beforeTodayPillNumber, - afterTodayPillNumber: history.value.changedPillNumber?.afterTodayPillNumber, + history: history, ), PillSheetModifiedActionType.endedPillSheet => PillSheetModifiedHistoryEndedPillSheetAction( value: history.value.endedPillSheet, diff --git a/lib/features/record/components/button/cancel_button.dart b/lib/features/record/components/button/cancel_button.dart index b30287624c..f10dfc46b7 100644 --- a/lib/features/record/components/button/cancel_button.dart +++ b/lib/features/record/components/button/cancel_button.dart @@ -30,7 +30,7 @@ class CancelButton extends HookConsumerWidget { text: L.notTaken, onPressed: () async { analytics.logEvent(name: 'cancel_taken_button_pressed', parameters: { - 'last_taken_pill_number': activePillSheet.lastTakenPillNumber, + 'last_taken_pill_number': activePillSheet.lastTakenOrZeroPillNumber, 'today_pill_number': activePillSheet.todayPillNumber, }); @@ -50,7 +50,7 @@ class CancelButton extends HookConsumerWidget { return await revertTakePill( pillSheetGroup: pillSheetGroup, pageIndex: activePillSheet.groupIndex, - targetRevertPillNumberIntoPillSheet: activePillSheet.lastTakenPillNumber, + targetRevertPillNumberIntoPillSheet: activePillSheet.lastTakenOrZeroPillNumber, ); } } diff --git a/lib/features/record/components/button/taken_button.dart b/lib/features/record/components/button/taken_button.dart index fb03973025..1e8e06c097 100644 --- a/lib/features/record/components/button/taken_button.dart +++ b/lib/features/record/components/button/taken_button.dart @@ -41,7 +41,7 @@ class TakenButton extends HookConsumerWidget { onPressed: () async { try { analytics.logEvent(name: 'taken_button_pressed', parameters: { - 'last_taken_pill_number': activePillSheet.lastTakenPillNumber, + 'last_taken_pill_number': activePillSheet.lastTakenOrZeroPillNumber, 'today_pill_number': activePillSheet.todayPillNumber, }); // NOTE: batch.commit でリモートのDBに書き込む時間がかかるので事前にバッジを0にする diff --git a/lib/features/record/components/pill_sheet/components/record_page_rest_duration_dialog.dart b/lib/features/record/components/pill_sheet/components/record_page_rest_duration_dialog.dart index bede564bf3..56eedceb69 100644 --- a/lib/features/record/components/pill_sheet/components/record_page_rest_duration_dialog.dart +++ b/lib/features/record/components/pill_sheet/components/record_page_rest_duration_dialog.dart @@ -114,10 +114,10 @@ class RecordPageRestDurationDialogTitle extends StatelessWidget { String get _number { switch (appearanceMode) { case PillSheetAppearanceMode.number: - return L.withNumber((pillSheetGroup.lastTakenPillSheetOrFirstPillSheet.lastTakenPillNumber + 1).toString()); + return L.withNumber((pillSheetGroup.lastTakenPillSheetOrFirstPillSheet.lastTakenOrZeroPillNumber + 1).toString()); case PillSheetAppearanceMode.date: final date = pillSheetGroup.lastTakenPillSheetOrFirstPillSheet - .displayPillTakeDate(pillSheetGroup.lastTakenPillSheetOrFirstPillSheet.lastTakenPillNumber + 1); + .displayPillTakeDate(pillSheetGroup.lastTakenPillSheetOrFirstPillSheet.lastTakenOrZeroPillNumber + 1); final dateString = DateTimeFormatter.monthAndDay(date); return dateString; case PillSheetAppearanceMode.sequential: diff --git a/lib/features/record/components/pill_sheet/record_page_pill_sheet.dart b/lib/features/record/components/pill_sheet/record_page_pill_sheet.dart index db91303ca4..6c93c35ec3 100644 --- a/lib/features/record/components/pill_sheet/record_page_pill_sheet.dart +++ b/lib/features/record/components/pill_sheet/record_page_pill_sheet.dart @@ -123,7 +123,7 @@ class RecordPagePillSheet extends HookConsumerWidget { onTap: () async { try { analytics.logEvent(name: 'pill_mark_tapped', parameters: { - 'last_taken_pill_number': pillSheet.lastTakenPillNumber, + 'last_taken_pill_number': pillSheet.lastTakenOrZeroPillNumber, 'today_pill_number': pillSheet.todayPillNumber, 'pillNumberInPillSheet': pillNumberInPillSheet, }); @@ -132,7 +132,7 @@ class RecordPagePillSheet extends HookConsumerWidget { return; } - if (pillSheet.lastTakenPillNumber >= pillNumberInPillSheet) { + if (pillSheet.lastTakenOrZeroPillNumber >= pillNumberInPillSheet) { await revertTakePill( pillSheetGroup: pillSheetGroup, pageIndex: pageIndex, @@ -172,7 +172,7 @@ class RecordPagePillSheet extends HookConsumerWidget { required PillSheetGroup pillSheetGroup, required PillSheet pillSheet, }) async { - if (pillNumberInPillSheet <= pillSheet.lastTakenPillNumber) { + if (pillNumberInPillSheet <= pillSheet.lastTakenOrZeroPillNumber) { return null; } if (pillSheetGroup.lastActiveRestDuration != null) { @@ -220,14 +220,14 @@ class RecordPagePillSheet extends HookConsumerWidget { } if (activePillSheet.id != pillSheet.id) { if (pillSheet.isBegan) { - if (pillNumberInPillSheet > pillSheet.lastTakenPillNumber) { + if (pillNumberInPillSheet > pillSheet.lastTakenOrZeroPillNumber) { return false; } } return true; } - return pillNumberInPillSheet <= activePillSheet.lastTakenPillNumber; + return pillNumberInPillSheet <= activePillSheet.lastTakenOrZeroPillNumber; } } @@ -240,7 +240,7 @@ PillMarkType pillMarkFor({ ? PillMarkType.rest : PillMarkType.fake; } - if (pillNumberInPillSheet <= pillSheet.lastTakenPillNumber) { + if (pillNumberInPillSheet <= pillSheet.lastTakenOrZeroPillNumber) { return PillMarkType.done; } if (pillNumberInPillSheet < pillSheet.todayPillNumber) { @@ -266,14 +266,14 @@ bool shouldPillMarkAnimation({ } if (activePillSheet.id != pillSheet.id) { if (pillSheet.isBegan) { - if (pillNumberInPillSheet > pillSheet.lastTakenPillNumber) { + if (pillNumberInPillSheet > pillSheet.lastTakenOrZeroPillNumber) { return true; } } return false; } - return pillNumberInPillSheet > activePillSheet.lastTakenPillNumber && pillNumberInPillSheet <= activePillSheet.todayPillNumber; + return pillNumberInPillSheet > activePillSheet.lastTakenOrZeroPillNumber && pillNumberInPillSheet <= activePillSheet.todayPillNumber; } class PillNumber extends StatelessWidget { @@ -300,7 +300,7 @@ class PillNumber extends StatelessWidget { final containedMenstruationDuration = menstruationDateRanges.where((e) => e.inRange(pillSheet.displayPillTakeDate(pillNumberInPillSheet))).isNotEmpty; - final text = pillSheetGroup.displayPillNumber( + final text = pillSheetGroup.displayPillNumberOrDate( premiumOrTrial: user.premiumOrTrial, pageIndex: pageIndex, pillNumberInPillSheet: pillNumberInPillSheet, diff --git a/lib/provider/change_pill_number.dart b/lib/provider/change_pill_number.dart index 447123795f..db8d64b2b1 100644 --- a/lib/provider/change_pill_number.dart +++ b/lib/provider/change_pill_number.dart @@ -58,7 +58,7 @@ class ChangePillNumber { beginDate = firstPilSheetBeginDate.addDays(passedTotalCount); } - final DateTime? lastTakenDate; + DateTime? lastTakenDate; if (pillSheetPageIndex == index) { lastTakenDate = beginDate.addDays(pillNumberInPillSheet - 2); } else if (pillSheetPageIndex > index) { @@ -67,6 +67,12 @@ class ChangePillNumber { // state.selectedPillMarkNumberIntoPillSheet < index lastTakenDate = null; } + if (lastTakenDate != null && lastTakenDate.isBefore(beginDate)) { + // if (pillSheetPageIndex == index) + // lastTakenDate = beginDate.addDays(pillNumberInPillSheet - 2); + // ここで1つ目のピル番号の時はlastTakenDateがbeginDateより前になるのでnullにする + lastTakenDate = null; + } final updatedPillSheet = pillSheet.copyWith( beginingDate: beginDate, diff --git a/lib/provider/revert_take_pill.dart b/lib/provider/revert_take_pill.dart index b744b93b6e..f37dacea2d 100644 --- a/lib/provider/revert_take_pill.dart +++ b/lib/provider/revert_take_pill.dart @@ -63,7 +63,7 @@ class RevertTakePill { if (revertDate.isBefore(pillSheet.beginingDate)) { // reset pill sheet when back to one before pill sheet - return pillSheet.copyWith(lastTakenDate: pillSheet.beginingDate.subtract(const Duration(days: 1)).date(), restDurations: []); + return pillSheet.copyWith(lastTakenDate: null, restDurations: []); } else { // Revert対象の日付よりも後ろにある休薬期間のデータは消す final remainingResetDurations = pillSheet.restDurations.where((restDuration) => restDuration.beginDate.date().isBefore(revertDate)).toList(); diff --git a/lib/utils/local_notification.dart b/lib/utils/local_notification.dart index 7cce6a869b..3d96656647 100644 --- a/lib/utils/local_notification.dart +++ b/lib/utils/local_notification.dart @@ -235,13 +235,13 @@ class RegisterReminderLocalNotification { analytics.debug(name: 'run_register_reminder_notification', parameters: { 'todayPillNumber': activePillSheet.todayPillNumber, 'todayPillIsAlreadyTaken': activePillSheet.todayPillIsAlreadyTaken, - 'lastTakenPillNumber': activePillSheet.lastTakenPillNumber, + 'lastTakenPillNumber': activePillSheet.lastTakenOrZeroPillNumber, 'reminderTimes': setting.reminderTimes.toString(), }); final tzNow = tz.TZDateTime.now(tz.local); final List> futures = []; - final badgeNumber = activePillSheet.todayPillNumber - activePillSheet.lastTakenPillNumber; + final badgeNumber = activePillSheet.todayPillNumber - activePillSheet.lastTakenOrZeroPillNumber; for (final reminderTime in setting.reminderTimes) { // 新規ピルシートグループの作成後に通知のスケジュールができないため、多めに通知をスケジュールする @@ -278,8 +278,7 @@ class RegisterReminderLocalNotification { var pillSheetGroupIndex = activePillSheet.groupIndex; var pillSheeType = activePillSheet.pillSheetType; - var pillSheetDisplayNumber = pillSheetGroup.displayPillNumberOnlyNumber( - pillSheetAppearanceMode: pillSheetGroup.pillSheetAppearanceMode, + var pillSheetDisplayNumber = pillSheetGroup.displayPillNumberWithoutDate( pageIndex: activePillSheet.groupIndex, pillNumberInPillSheet: pillNumberInPillSheet, ); @@ -297,8 +296,7 @@ class RegisterReminderLocalNotification { pillSheetTypes: pillSheetGroup.pillSheets.map((e) => e.pillSheetType).toList(), displayNumberSetting: null, ); - pillSheetDisplayNumber = nextPillSheetGroup.displayPillNumberOnlyNumber( - pillSheetAppearanceMode: pillSheetGroup.pillSheetAppearanceMode, + pillSheetDisplayNumber = nextPillSheetGroup.displayPillNumberWithoutDate( pageIndex: 0, pillNumberInPillSheet: pillNumberInPillSheet, ); @@ -310,8 +308,7 @@ class RegisterReminderLocalNotification { final nextPillSheet = pillSheetGroup.pillSheets[activePillSheet.groupIndex + 1]; pillSheetGroupIndex = nextPillSheet.groupIndex; pillSheeType = nextPillSheet.pillSheetType; - pillSheetDisplayNumber = pillSheetGroup.displayPillNumberOnlyNumber( - pillSheetAppearanceMode: pillSheetGroup.pillSheetAppearanceMode, + pillSheetDisplayNumber = pillSheetGroup.displayPillNumberWithoutDate( pageIndex: nextPillSheet.groupIndex, pillNumberInPillSheet: pillNumberInPillSheet, ); @@ -382,7 +379,7 @@ class RegisterReminderLocalNotification { return ''; } // 最後に飲んだ日付が数日前の場合は常にmissedTakenMessage - if (activePillSheet.todayPillNumber - activePillSheet.lastTakenPillNumber > 1) { + if (activePillSheet.todayPillNumber - activePillSheet.lastTakenOrZeroPillNumber > 1) { return setting.reminderNotificationCustomization.missedTakenMessage; } // 本日分の服用記録がない場合で今日のループ(dayOffset==0)の時 diff --git a/test/entity/pill_sheet_group_display_domain_test.dart b/test/entity/pill_sheet_group_display_domain_test.dart index c8cfa8b611..4c7f1ef905 100644 --- a/test/entity/pill_sheet_group_display_domain_test.dart +++ b/test/entity/pill_sheet_group_display_domain_test.dart @@ -245,7 +245,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2020-09-29"), lastTakenDate: null, @@ -261,7 +261,7 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["sheet_id", "sheet_id2"], - pillSheets: [pillSheet, pillShee$2], + pillSheets: [pillSheet, pillSheet2], pillSheetAppearanceMode: PillSheetAppearanceMode.number, createdAt: now(), ); @@ -303,9 +303,9 @@ void main() { pillSheetAppearanceMode: PillSheetAppearanceMode.number, createdAt: now(), ); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), "1"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "10"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "28"); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 1); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 10); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 28); }); // NOTE: 直接このテストケースの結果に関わってこない部分ではあるが、書いちゃったので残している @@ -343,10 +343,10 @@ void main() { createdAt: now(), ); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), "1"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "10"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), "22"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "28"); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 1); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 10); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), 22); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 28); }); test("服用お休みが終わっている場合", () { @@ -383,10 +383,10 @@ void main() { createdAt: now(), ); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), "1"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "10"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), "22"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "28"); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 1); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 10); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), 22); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 28); }); group("複数の服用お休み期間を持つ場合", () { test("最後の服用お休みが終わっていない場合", () { @@ -427,11 +427,11 @@ void main() { pillSheetAppearanceMode: PillSheetAppearanceMode.number, createdAt: now(), ); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), "1"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "10"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 12), "12"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), "22"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "28"); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 1); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 10); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 12), 12); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), 22); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 28); }); test("最後の服用お休み期間が終わっている場合", () { final mockTodayRepository = MockTodayService(); @@ -475,11 +475,11 @@ void main() { pillSheetAppearanceMode: PillSheetAppearanceMode.number, createdAt: now(), ); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), '1'); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "10"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 12), "12"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), "22"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "28"); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 1); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 10); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 12), 12); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), 22); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 28); }); }); }); @@ -513,10 +513,10 @@ void main() { displayNumberSetting: const PillSheetGroupDisplayNumberSetting(beginPillNumber: 10), ); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), "10"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "19"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), "31"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "37"); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 10); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 19); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), 31); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 37); }); test("終了番号が設定されている", () { @@ -541,17 +541,17 @@ void main() { final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["sheet_id"], pillSheets: [pillSheet], - pillSheetAppearanceMode: PillSheetAppearanceMode.number, + pillSheetAppearanceMode: PillSheetAppearanceMode.sequential, createdAt: now(), displayNumberSetting: const PillSheetGroupDisplayNumberSetting(endPillNumber: 11), ); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), "1"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "10"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 11), "11"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 12), "1"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), "11"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "6"); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 1); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 10); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 11), 11); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 12), 1); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), 11); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 6); }); test("開始と終了どちらも設定されている", () { final mockTodayRepository = MockTodayService(); @@ -581,11 +581,11 @@ void main() { endPillNumber: 20, ), ); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), '10'); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "19"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 12), "1"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), "11"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "17"); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 10); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 19); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 12), 10); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), 20); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 15); }); }); }); @@ -609,7 +609,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2020-09-29"), lastTakenDate: null, @@ -625,16 +625,16 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["sheet_id", "sheet_id2"], - pillSheets: [pillSheet, pillShee$2], + pillSheets: [pillSheet, pillSheet2], pillSheetAppearanceMode: PillSheetAppearanceMode.number, createdAt: now(), ); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), '1'); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "10"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "28"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 1), "29"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 10), "38"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 28), "56"); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 1); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 10); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 28); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 1), 29); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 10), 38); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 28), 56); }); group("displayNumberSettingの設定がある場合", () { @@ -657,7 +657,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2020-09-29"), lastTakenDate: null, @@ -673,17 +673,17 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["sheet_id", "sheet_id2"], - pillSheets: [pillSheet, pillShee$2], + pillSheets: [pillSheet, pillSheet2], createdAt: now(), displayNumberSetting: const PillSheetGroupDisplayNumberSetting(beginPillNumber: 10), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), '10'); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "19"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "37"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 1), "38"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 10), "47"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 28), "65"); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 10); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 19); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 37); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 1), 38); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 10), 47); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 28), 65); }); test("終了番号が設定されている", () { @@ -713,12 +713,12 @@ void main() { pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), "1"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "10"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 11), "11"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 12), "1"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), "11"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "6"); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 1); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 10); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 11), 11); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 12), 1); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), 11); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 6); }); test("開始番号が設定されている", () { final mockTodayRepository = MockTodayService(); @@ -739,7 +739,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2020-09-29"), lastTakenDate: null, @@ -755,18 +755,18 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["sheet_id", "sheet_id2"], - pillSheets: [pillSheet, pillShee$2], + pillSheets: [pillSheet, pillSheet2], createdAt: now(), displayNumberSetting: const PillSheetGroupDisplayNumberSetting(endPillNumber: 40), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), "1"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "10"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "28"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 1), "29"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 10), "38"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 28), "16"); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 1); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 10); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 28); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 1), 29); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 10), 38); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 28), 16); }); test("開始と終了どちらも設定されている", () { final mockTodayRepository = MockTodayService(); @@ -787,7 +787,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2020-09-29"), lastTakenDate: null, @@ -803,17 +803,17 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["sheet_id", "sheet_id2"], - pillSheets: [pillSheet, pillShee$2], + pillSheets: [pillSheet, pillSheet2], createdAt: now(), displayNumberSetting: const PillSheetGroupDisplayNumberSetting(beginPillNumber: 10, endPillNumber: 40), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), "10"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "19"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "37"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 1), "38"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 10), "7"); - expect(pillSheetGroup.displaySequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 28), "25"); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 10); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 19); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 37); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 1), 38); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 10), 16); + expect(pillSheetGroup.sequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 28), 34); }); }); }); @@ -846,9 +846,9 @@ void main() { createdAt: now(), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), "1"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "10"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "28"); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 1); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 10); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 28); }); group("服用お休み期間を持つ場合", () { @@ -885,10 +885,10 @@ void main() { pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), "1"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "10"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), "22"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "28"); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 1); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 10); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), 22); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 28); }); test("服用お休みが終わっている場合", () { @@ -925,10 +925,10 @@ void main() { pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), "1"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "10"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), "1"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "7"); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 1); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 10); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), 1); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 7); }); group("複数の服用お休み期間を持つ場合", () { test("最後の服用お休みが終わっていない場合", () { @@ -969,11 +969,11 @@ void main() { createdAt: now(), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), "1"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "10"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 12), "1"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), "11"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "17"); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 1); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 10); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 12), 1); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), 11); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 17); }); test("最後の服用お休み期間が終わっている場合", () { final mockTodayRepository = MockTodayService(); @@ -1017,12 +1017,12 @@ void main() { createdAt: now(), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), '1'); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "10"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 12), "1"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 18), "7"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), "4"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "10"); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 1); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 10); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 12), 1); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 18), 7); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), 4); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 10); }); }); }); @@ -1056,10 +1056,10 @@ void main() { pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), "10"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "19"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), "31"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "37"); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 10); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 19); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), 31); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 37); }); test("終了番号が設定されている", () { @@ -1089,12 +1089,12 @@ void main() { pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), "1"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "10"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 11), "11"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 12), "1"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), "11"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "6"); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 1); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 10); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 11), 11); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 12), 1); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), 11); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 6); }); test("開始と終了どちらも設定されている", () { final mockTodayRepository = MockTodayService(); @@ -1124,11 +1124,11 @@ void main() { ), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), '10'); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "19"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 12), "1"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), "11"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "17"); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 10); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 19); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 12), 10); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 22), 20); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 15); }); }); }); @@ -1152,7 +1152,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2020-09-29"), lastTakenDate: null, @@ -1168,16 +1168,16 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["sheet_id", "sheet_id2"], - pillSheets: [pillSheet, pillShee$2], + pillSheets: [pillSheet, pillSheet2], createdAt: now(), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), '1'); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "10"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "28"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 1), "29"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 10), "38"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 28), "56"); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 1); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 10); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 28); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 1), 29); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 10), 38); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 28), 56); }); group("displayNumberSettingの設定がある場合", () { @@ -1200,7 +1200,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2020-09-29"), lastTakenDate: null, @@ -1216,17 +1216,17 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["sheet_id", "sheet_id2"], - pillSheets: [pillSheet, pillShee$2], + pillSheets: [pillSheet, pillSheet2], createdAt: now(), displayNumberSetting: const PillSheetGroupDisplayNumberSetting(beginPillNumber: 10), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), '10'); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "19"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "37"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 1), "38"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 10), "47"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 28), "65"); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 10); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 19); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 37); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 1), 38); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 10), 47); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 28), 65); }); test("開始番号が設定されている", () { @@ -1248,7 +1248,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2020-09-29"), lastTakenDate: null, @@ -1264,18 +1264,18 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["sheet_id", "sheet_id2"], - pillSheets: [pillSheet, pillShee$2], + pillSheets: [pillSheet, pillSheet2], createdAt: now(), displayNumberSetting: const PillSheetGroupDisplayNumberSetting(endPillNumber: 40), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), "1"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "10"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "28"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 1), "29"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 10), "38"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 28), "16"); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 1); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 10); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 28); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 1), 29); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 10), 38); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 28), 16); }); test("開始と終了どちらも設定されている", () { final mockTodayRepository = MockTodayService(); @@ -1296,7 +1296,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2020-09-29"), lastTakenDate: null, @@ -1312,17 +1312,17 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["sheet_id", "sheet_id2"], - pillSheets: [pillSheet, pillShee$2], + pillSheets: [pillSheet, pillSheet2], createdAt: now(), displayNumberSetting: const PillSheetGroupDisplayNumberSetting(beginPillNumber: 10, endPillNumber: 40), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), "10"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), "19"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), "37"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 1), "38"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 10), "7"); - expect(pillSheetGroup.displayCycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 28), "25"); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 1), 10); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 10), 19); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 0, pillNumberInPillSheet: 28), 37); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 1), 38); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 10), 16); + expect(pillSheetGroup.cycleSequentialPillSheetNumber(pageIndex: 1, pillNumberInPillSheet: 28), 34); }); }); }); diff --git a/test/entity/pill_sheet_group_test.dart b/test/entity/pill_sheet_group_test.dart index 0820cdf8b6..c30d9353ce 100644 --- a/test/entity/pill_sheet_group_test.dart +++ b/test/entity/pill_sheet_group_test.dart @@ -17,6 +17,364 @@ void main() { SharedPreferences.setMockInitialValues({}); }); + group("#lastTakenPillNumberWithoutDate", () { + group("ピルシートが一つの場合", () { + test("today: 2020-09-19, begin: 2020-09-14, end: 2020-09-18", () { + final mockTodayRepository = MockTodayService(); + todayRepository = mockTodayRepository; + when(mockTodayRepository.now()).thenReturn(DateTime.parse("2020-09-19")); + + const sheetType = PillSheetType.pillsheet_21; + final pillSheet = PillSheet( + id: firestoreIDGenerator(), + beginingDate: DateTime.parse("2020-09-14"), + lastTakenDate: DateTime.parse("2020-09-18"), + createdAt: now(), + typeInfo: PillSheetTypeInfo( + dosingPeriod: sheetType.dosingPeriod, + name: sheetType.fullName, + totalCount: sheetType.totalCount, + pillSheetTypeReferencePath: sheetType.rawPath, + ), + ); + // created at and id are anything value + final pillSheetGroup = PillSheetGroup( + pillSheetIDs: ["sheet_id"], + pillSheets: [pillSheet], + pillSheetAppearanceMode: PillSheetAppearanceMode.sequential, + createdAt: now(), + ); + expect(pillSheetGroup.lastTakenPillNumberWithoutDate, 5); + }); + group("服用お休み期間を持つ場合", () { + test("服用お休みが終わっていない場合", () { + final mockTodayRepository = MockTodayService(); + todayRepository = mockTodayRepository; + when(mockTodayRepository.now()).thenReturn(DateTime.parse("2020-09-28")); + + const sheetType = PillSheetType.pillsheet_21; + final pillSheet = PillSheet( + id: firestoreIDGenerator(), + beginingDate: DateTime.parse("2020-09-01"), + lastTakenDate: DateTime.parse("2020-09-28"), + createdAt: now(), + restDurations: [ + RestDuration( + id: "rest_duration_id", + beginDate: DateTime.parse("2020-09-22"), + createdDate: DateTime.parse("2020-09-22"), + ) + ], + typeInfo: PillSheetTypeInfo( + dosingPeriod: sheetType.dosingPeriod, + name: sheetType.fullName, + totalCount: sheetType.totalCount, + pillSheetTypeReferencePath: sheetType.rawPath, + ), + ); + // created at and id are anything value + final pillSheetGroup = PillSheetGroup( + pillSheetIDs: ["sheet_id"], + pillSheets: [pillSheet], + pillSheetAppearanceMode: PillSheetAppearanceMode.sequential, + createdAt: now(), + ); + expect(pillSheetGroup.lastTakenPillNumberWithoutDate, 22); + }); + + test("服用お休みが終わっている場合", () { + final mockTodayRepository = MockTodayService(); + todayRepository = mockTodayRepository; + when(mockTodayRepository.now()).thenReturn(DateTime.parse("2020-09-28")); + + const sheetType = PillSheetType.pillsheet_21; + final pillSheet = PillSheet( + id: firestoreIDGenerator(), + beginingDate: DateTime.parse("2020-09-01"), + lastTakenDate: DateTime.parse("2020-09-28"), + createdAt: now(), + restDurations: [ + RestDuration( + id: "rest_duration_id", + beginDate: DateTime.parse("2020-09-22"), + createdDate: DateTime.parse("2020-09-22"), + endDate: DateTime.parse("2020-09-25"), + ) + ], + typeInfo: PillSheetTypeInfo( + dosingPeriod: sheetType.dosingPeriod, + name: sheetType.fullName, + totalCount: sheetType.totalCount, + pillSheetTypeReferencePath: sheetType.rawPath, + ), + ); + // created at and id are anything value + final pillSheetGroup = PillSheetGroup( + pillSheetIDs: ["sheet_id"], + pillSheets: [pillSheet], + pillSheetAppearanceMode: PillSheetAppearanceMode.sequential, + createdAt: now(), + ); + expect(pillSheetGroup.lastTakenPillNumberWithoutDate, 25); + }); + group("複数の服用お休み期間を持つ場合", () { + test("最後の服用お休みが終わっていない場合", () { + final mockTodayRepository = MockTodayService(); + todayRepository = mockTodayRepository; + when(mockTodayRepository.now()).thenReturn(DateTime.parse("2020-09-28")); + + const sheetType = PillSheetType.pillsheet_21; + final pillSheet = PillSheet( + id: firestoreIDGenerator(), + beginingDate: DateTime.parse("2020-09-01"), + lastTakenDate: DateTime.parse("2020-09-28"), + createdAt: now(), + restDurations: [ + RestDuration( + id: "rest_duration_id", + beginDate: DateTime.parse("2020-09-12"), + createdDate: DateTime.parse("2020-09-12"), + endDate: DateTime.parse("2020-09-15"), + ), + RestDuration( + id: "rest_duration_id", + beginDate: DateTime.parse("2020-09-22"), + createdDate: DateTime.parse("2020-09-22"), + ) + ], + typeInfo: PillSheetTypeInfo( + dosingPeriod: sheetType.dosingPeriod, + name: sheetType.fullName, + totalCount: sheetType.totalCount, + pillSheetTypeReferencePath: sheetType.rawPath, + ), + ); + // created at and id are anything value + final pillSheetGroup = PillSheetGroup( + pillSheetIDs: ["sheet_id"], + pillSheets: [pillSheet], + pillSheetAppearanceMode: PillSheetAppearanceMode.sequential, + createdAt: now(), + ); + expect(pillSheetGroup.lastTakenPillNumberWithoutDate, 19); + }); + test("最後の服用お休み期間が終わっている場合", () { + final mockTodayRepository = MockTodayService(); + todayRepository = mockTodayRepository; + when(mockTodayRepository.now()).thenReturn(DateTime.parse("2020-09-28")); + + const sheetType = PillSheetType.pillsheet_21; + // 服用お休みを考慮しない場合は28日間 + final pillSheet = PillSheet( + id: firestoreIDGenerator(), + beginingDate: DateTime.parse("2020-09-01"), + lastTakenDate: DateTime.parse("2020-09-28"), + createdAt: now(), + restDurations: [ + // 3日分 + RestDuration( + id: "rest_duration_id", + beginDate: DateTime.parse("2020-09-12"), + createdDate: DateTime.parse("2020-09-12"), + endDate: DateTime.parse("2020-09-15"), + ), + // 3日分 + RestDuration( + id: "rest_duration_id", + beginDate: DateTime.parse("2020-09-22"), + createdDate: DateTime.parse("2020-09-22"), + endDate: DateTime.parse("2020-09-25"), + ) + ], + typeInfo: PillSheetTypeInfo( + dosingPeriod: sheetType.dosingPeriod, + name: sheetType.fullName, + totalCount: sheetType.totalCount, + pillSheetTypeReferencePath: sheetType.rawPath, + ), + ); + // created at and id are anything value + final pillSheetGroup = PillSheetGroup( + pillSheetIDs: ["sheet_id"], + pillSheets: [pillSheet], + pillSheetAppearanceMode: PillSheetAppearanceMode.sequential, + createdAt: now(), + ); + expect(pillSheetGroup.lastTakenPillNumberWithoutDate, 22); + }); + }); + }); + }); + group("has two pill sheets", () { + test("it is plane pattern", () { + final mockTodayRepository = MockTodayService(); + todayRepository = mockTodayRepository; + when(mockTodayRepository.now()).thenReturn(DateTime.parse("2022-03-29")); + + const sheetType = PillSheetType.pillsheet_21; + final pillSheet1 = PillSheet( + id: firestoreIDGenerator(), + beginingDate: DateTime.parse("2022-03-01"), + lastTakenDate: DateTime.parse("2022-03-28"), + createdAt: now(), + groupIndex: 0, + typeInfo: PillSheetTypeInfo( + dosingPeriod: sheetType.dosingPeriod, + name: sheetType.fullName, + totalCount: sheetType.totalCount, + pillSheetTypeReferencePath: sheetType.rawPath, + ), + ); + final pillSheet2 = PillSheet( + id: firestoreIDGenerator(), + beginingDate: DateTime.parse("2022-03-29"), + lastTakenDate: null, + groupIndex: 1, + createdAt: now(), + typeInfo: PillSheetTypeInfo( + dosingPeriod: sheetType.dosingPeriod, + name: sheetType.fullName, + totalCount: sheetType.totalCount, + pillSheetTypeReferencePath: sheetType.rawPath, + ), + ); + // created at and id are anything value + final pillSheetGroup = PillSheetGroup( + pillSheetIDs: ["sheet_id", "sheet_id2"], + pillSheets: [pillSheet1, pillSheet2], + pillSheetAppearanceMode: PillSheetAppearanceMode.sequential, + createdAt: now(), + ); + expect(pillSheetGroup.lastTakenPillNumberWithoutDate, 28); + }); + test("with begin display number setting", () { + final mockTodayRepository = MockTodayService(); + todayRepository = mockTodayRepository; + when(mockTodayRepository.now()).thenReturn(DateTime.parse("2022-03-29")); + + const sheetType = PillSheetType.pillsheet_21; + final pillSheet1 = PillSheet( + id: firestoreIDGenerator(), + beginingDate: DateTime.parse("2022-03-01"), + lastTakenDate: DateTime.parse("2022-03-28"), + createdAt: now(), + groupIndex: 0, + typeInfo: PillSheetTypeInfo( + dosingPeriod: sheetType.dosingPeriod, + name: sheetType.fullName, + totalCount: sheetType.totalCount, + pillSheetTypeReferencePath: sheetType.rawPath, + ), + ); + final pillSheet2 = PillSheet( + id: firestoreIDGenerator(), + beginingDate: DateTime.parse("2022-03-29"), + lastTakenDate: null, + createdAt: now(), + groupIndex: 1, + typeInfo: PillSheetTypeInfo( + dosingPeriod: sheetType.dosingPeriod, + name: sheetType.fullName, + totalCount: sheetType.totalCount, + pillSheetTypeReferencePath: sheetType.rawPath, + ), + ); + // created at and id are anything value + final pillSheetGroup = PillSheetGroup( + pillSheetIDs: ["sheet_id", "sheet_id2"], + pillSheets: [pillSheet1, pillSheet2], + createdAt: now(), + displayNumberSetting: const PillSheetGroupDisplayNumberSetting(beginPillNumber: 2), + pillSheetAppearanceMode: PillSheetAppearanceMode.sequential, + ); + expect(pillSheetGroup.lastTakenPillNumberWithoutDate, 29); + }); + test("with end display number setting", () { + final mockTodayRepository = MockTodayService(); + todayRepository = mockTodayRepository; + when(mockTodayRepository.now()).thenReturn(DateTime.parse("2022-03-29")); + + const sheetType = PillSheetType.pillsheet_21; + final pillSheet1 = PillSheet( + id: firestoreIDGenerator(), + beginingDate: DateTime.parse("2022-03-01"), + lastTakenDate: DateTime.parse("2022-03-28"), + createdAt: now(), + groupIndex: 0, + typeInfo: PillSheetTypeInfo( + dosingPeriod: sheetType.dosingPeriod, + name: sheetType.fullName, + totalCount: sheetType.totalCount, + pillSheetTypeReferencePath: sheetType.rawPath, + ), + ); + final pillSheet2 = PillSheet( + id: firestoreIDGenerator(), + beginingDate: DateTime.parse("2022-03-29"), + lastTakenDate: null, + createdAt: now(), + groupIndex: 1, + typeInfo: PillSheetTypeInfo( + dosingPeriod: sheetType.dosingPeriod, + name: sheetType.fullName, + totalCount: sheetType.totalCount, + pillSheetTypeReferencePath: sheetType.rawPath, + ), + ); + // created at and id are anything value + final pillSheetGroup = PillSheetGroup( + pillSheetIDs: ["sheet_id", "sheet_id2"], + pillSheets: [pillSheet1, pillSheet2], + createdAt: now(), + displayNumberSetting: const PillSheetGroupDisplayNumberSetting(endPillNumber: 28), + pillSheetAppearanceMode: PillSheetAppearanceMode.sequential, + ); + expect(pillSheetGroup.lastTakenPillNumberWithoutDate, 28); + }); + test("with begin and end display number setting", () { + final mockTodayRepository = MockTodayService(); + todayRepository = mockTodayRepository; + when(mockTodayRepository.now()).thenReturn(DateTime.parse("2022-03-29")); + + const sheetType = PillSheetType.pillsheet_21; + final pillSheet1 = PillSheet( + id: firestoreIDGenerator(), + beginingDate: DateTime.parse("2022-03-01"), + lastTakenDate: DateTime.parse("2022-03-28"), + createdAt: now(), + groupIndex: 0, + typeInfo: PillSheetTypeInfo( + dosingPeriod: sheetType.dosingPeriod, + name: sheetType.fullName, + totalCount: sheetType.totalCount, + pillSheetTypeReferencePath: sheetType.rawPath, + ), + ); + final pillSheet2 = PillSheet( + id: firestoreIDGenerator(), + beginingDate: DateTime.parse("2022-03-29"), + lastTakenDate: null, + createdAt: now(), + groupIndex: 1, + typeInfo: PillSheetTypeInfo( + dosingPeriod: sheetType.dosingPeriod, + name: sheetType.fullName, + totalCount: sheetType.totalCount, + pillSheetTypeReferencePath: sheetType.rawPath, + ), + ); + // created at and id are anything value + final pillSheetGroup = PillSheetGroup( + pillSheetIDs: ["sheet_id", "sheet_id2"], + pillSheets: [pillSheet1, pillSheet2], + createdAt: now(), + displayNumberSetting: const PillSheetGroupDisplayNumberSetting(beginPillNumber: 2, endPillNumber: 28), + pillSheetAppearanceMode: PillSheetAppearanceMode.sequential, + ); + expect(pillSheetGroup.lastTakenPillNumberWithoutDate, 2); + }); + }); + }); group("#sequentialTodayPillNumber", () { group("ピルシートが一つの場合", () { test("today: 2020-09-19, begin: 2020-09-14, end: 2020-09-18", () { @@ -239,7 +597,7 @@ void main() { when(mockTodayRepository.now()).thenReturn(DateTime.parse("2022-03-29")); const sheetType = PillSheetType.pillsheet_21; - final pillShee$1 = PillSheet( + final pillSheet1 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2022-03-01"), lastTakenDate: DateTime.parse("2020-03-28"), @@ -252,7 +610,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2022-03-29"), lastTakenDate: null, @@ -268,7 +626,7 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["sheet_id", "sheet_id2"], - pillSheets: [pillShee$1, pillShee$2], + pillSheets: [pillSheet1, pillSheet2], pillSheetAppearanceMode: PillSheetAppearanceMode.sequential, createdAt: now(), ); @@ -280,7 +638,7 @@ void main() { when(mockTodayRepository.now()).thenReturn(DateTime.parse("2022-03-29")); const sheetType = PillSheetType.pillsheet_21; - final pillShee$1 = PillSheet( + final pillSheet1 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2022-03-01"), lastTakenDate: DateTime.parse("2020-03-28"), @@ -293,7 +651,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2022-03-29"), lastTakenDate: null, @@ -309,7 +667,7 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["sheet_id", "sheet_id2"], - pillSheets: [pillShee$1, pillShee$2], + pillSheets: [pillSheet1, pillSheet2], createdAt: now(), displayNumberSetting: const PillSheetGroupDisplayNumberSetting(beginPillNumber: 2), pillSheetAppearanceMode: PillSheetAppearanceMode.sequential, @@ -322,7 +680,7 @@ void main() { when(mockTodayRepository.now()).thenReturn(DateTime.parse("2022-03-29")); const sheetType = PillSheetType.pillsheet_21; - final pillShee$1 = PillSheet( + final pillSheet1 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2022-03-01"), lastTakenDate: DateTime.parse("2020-03-28"), @@ -335,7 +693,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2022-03-29"), lastTakenDate: null, @@ -351,7 +709,7 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["sheet_id", "sheet_id2"], - pillSheets: [pillShee$1, pillShee$2], + pillSheets: [pillSheet1, pillSheet2], createdAt: now(), displayNumberSetting: const PillSheetGroupDisplayNumberSetting(endPillNumber: 28), pillSheetAppearanceMode: PillSheetAppearanceMode.sequential, @@ -364,7 +722,7 @@ void main() { when(mockTodayRepository.now()).thenReturn(DateTime.parse("2022-03-29")); const sheetType = PillSheetType.pillsheet_21; - final pillShee$1 = PillSheet( + final pillSheet1 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2022-03-01"), lastTakenDate: DateTime.parse("2020-03-28"), @@ -377,7 +735,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2022-03-29"), lastTakenDate: null, @@ -393,12 +751,12 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["sheet_id", "sheet_id2"], - pillSheets: [pillShee$1, pillShee$2], + pillSheets: [pillSheet1, pillSheet2], createdAt: now(), displayNumberSetting: const PillSheetGroupDisplayNumberSetting(beginPillNumber: 2, endPillNumber: 28), pillSheetAppearanceMode: PillSheetAppearanceMode.sequential, ); - expect(pillSheetGroup.sequentialTodayPillNumber, 2); + expect(pillSheetGroup.sequentialTodayPillNumber, 3); }); }); }); @@ -683,7 +1041,7 @@ void main() { when(mockTodayRepository.now()).thenReturn(DateTime.parse("2022-03-30")); const sheetType = PillSheetType.pillsheet_21; - final pillShee$1 = PillSheet( + final pillSheet1 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2022-03-01"), lastTakenDate: DateTime.parse("2020-03-28"), @@ -696,7 +1054,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2022-03-29"), lastTakenDate: DateTime.parse("2022-03-29"), @@ -712,7 +1070,7 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["sheet_id", "sheet_id2"], - pillSheets: [pillShee$1, pillShee$2], + pillSheets: [pillSheet1, pillSheet2], createdAt: now(), pillSheetAppearanceMode: PillSheetAppearanceMode.sequential, ); @@ -724,7 +1082,7 @@ void main() { when(mockTodayRepository.now()).thenReturn(DateTime.parse("2022-03-30")); const sheetType = PillSheetType.pillsheet_21; - final pillShee$1 = PillSheet( + final pillSheet1 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2022-03-01"), lastTakenDate: DateTime.parse("2020-03-28"), @@ -737,7 +1095,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2022-03-29"), lastTakenDate: DateTime.parse("2022-03-29"), @@ -753,7 +1111,7 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["sheet_id", "sheet_id2"], - pillSheets: [pillShee$1, pillShee$2], + pillSheets: [pillSheet1, pillSheet2], createdAt: now(), displayNumberSetting: const PillSheetGroupDisplayNumberSetting(beginPillNumber: 2), pillSheetAppearanceMode: PillSheetAppearanceMode.sequential, @@ -766,7 +1124,7 @@ void main() { when(mockTodayRepository.now()).thenReturn(DateTime.parse("2022-03-30")); const sheetType = PillSheetType.pillsheet_21; - final pillShee$1 = PillSheet( + final pillSheet1 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2022-03-01"), lastTakenDate: DateTime.parse("2020-03-28"), @@ -779,7 +1137,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2022-03-29"), lastTakenDate: DateTime.parse("2022-03-29"), @@ -795,7 +1153,7 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["sheet_id", "sheet_id2"], - pillSheets: [pillShee$1, pillShee$2], + pillSheets: [pillSheet1, pillSheet2], createdAt: now(), displayNumberSetting: const PillSheetGroupDisplayNumberSetting(endPillNumber: 28), pillSheetAppearanceMode: PillSheetAppearanceMode.sequential, @@ -809,7 +1167,7 @@ void main() { when(mockTodayRepository.now()).thenReturn(DateTime.parse("2022-03-30")); const sheetType = PillSheetType.pillsheet_21; - final pillShee$1 = PillSheet( + final pillSheet1 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2022-03-01"), lastTakenDate: DateTime.parse("2020-03-28"), @@ -822,7 +1180,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2022-03-29"), lastTakenDate: DateTime.parse("2022-03-29"), @@ -838,7 +1196,7 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["sheet_id", "sheet_id2"], - pillSheets: [pillShee$1, pillShee$2], + pillSheets: [pillSheet1, pillSheet2], createdAt: now(), displayNumberSetting: const PillSheetGroupDisplayNumberSetting(endPillNumber: 28), pillSheetAppearanceMode: PillSheetAppearanceMode.sequential, @@ -851,7 +1209,7 @@ void main() { when(mockTodayRepository.now()).thenReturn(DateTime.parse("2022-03-30")); const sheetType = PillSheetType.pillsheet_21; - final pillShee$1 = PillSheet( + final pillSheet1 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2022-03-01"), lastTakenDate: DateTime.parse("2020-03-28"), @@ -864,7 +1222,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), beginingDate: DateTime.parse("2022-03-29"), lastTakenDate: DateTime.parse("2022-03-29"), @@ -880,12 +1238,12 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["sheet_id", "sheet_id2"], - pillSheets: [pillShee$1, pillShee$2], + pillSheets: [pillSheet1, pillSheet2], createdAt: now(), displayNumberSetting: const PillSheetGroupDisplayNumberSetting(beginPillNumber: 2, endPillNumber: 28), pillSheetAppearanceMode: PillSheetAppearanceMode.sequential, ); - expect(pillSheetGroup.sequentialLastTakenPillNumber, 2); + expect(pillSheetGroup.sequentialLastTakenPillNumber, 3); }); }); }); @@ -1051,7 +1409,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), groupIndex: 1, beginingDate: DateTime.parse("2020-09-01").add(const Duration(days: 28)), @@ -1064,7 +1422,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$3 = PillSheet( + final pillSheet3 = PillSheet( id: firestoreIDGenerator(), groupIndex: 2, beginingDate: DateTime.parse("2020-09-01").add(const Duration(days: 28 * 2)), @@ -1080,7 +1438,7 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["1", "2", "3"], - pillSheets: [pillSheet, pillShee$2, pillShee$3], + pillSheets: [pillSheet, pillSheet2, pillSheet3], createdAt: now(), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); @@ -1111,7 +1469,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), groupIndex: 1, beginingDate: DateTime.parse("2020-09-01").add(const Duration(days: 28)), @@ -1124,7 +1482,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$3 = PillSheet( + final pillSheet3 = PillSheet( id: firestoreIDGenerator(), groupIndex: 2, beginingDate: DateTime.parse("2020-09-01").add(const Duration(days: 28 * 2)), @@ -1140,7 +1498,7 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["1", "2", "3"], - pillSheets: [pillSheet, pillShee$2, pillShee$3], + pillSheets: [pillSheet, pillSheet2, pillSheet3], createdAt: now(), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); @@ -1184,7 +1542,7 @@ void main() { endDate: null, ), ]); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), groupIndex: 1, beginingDate: DateTime.parse("2020-09-01").add(const Duration(days: 28 + pastDaysFromBeginRestDuration)), @@ -1197,7 +1555,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$3 = PillSheet( + final pillSheet3 = PillSheet( id: firestoreIDGenerator(), groupIndex: 2, beginingDate: DateTime.parse("2020-09-01").add(const Duration(days: 28 * 2 + pastDaysFromBeginRestDuration)), @@ -1213,7 +1571,7 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["1", "2", "3"], - pillSheets: [pillSheet, pillShee$2, pillShee$3], + pillSheets: [pillSheet, pillSheet2, pillSheet3], createdAt: now(), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); @@ -1257,7 +1615,7 @@ void main() { endDate: DateTime.parse("2020-09-10").add(const Duration(days: restDurationDays)), ), ]); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), groupIndex: 1, beginingDate: DateTime.parse("2020-09-01").add(const Duration(days: 28 + restDurationDays)), @@ -1270,7 +1628,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$3 = PillSheet( + final pillSheet3 = PillSheet( id: firestoreIDGenerator(), groupIndex: 2, beginingDate: DateTime.parse("2020-09-01").add(const Duration(days: 28 * 2 + restDurationDays)), @@ -1286,7 +1644,7 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["1", "2", "3"], - pillSheets: [pillSheet, pillShee$2, pillShee$3], + pillSheets: [pillSheet, pillSheet2, pillSheet3], createdAt: now(), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); @@ -1322,7 +1680,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), groupIndex: 1, beginingDate: DateTime.parse("2020-09-01").add(const Duration(days: 28)), @@ -1335,7 +1693,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$3 = PillSheet( + final pillSheet3 = PillSheet( id: firestoreIDGenerator(), groupIndex: 2, beginingDate: DateTime.parse("2020-09-01").add(const Duration(days: 28 * 2)), @@ -1351,7 +1709,7 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["1", "2", "3"], - pillSheets: [pillSheet, pillShee$2, pillShee$3], + pillSheets: [pillSheet, pillSheet2, pillSheet3], createdAt: now(), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); @@ -1383,7 +1741,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), groupIndex: 1, beginingDate: DateTime.parse("2020-09-01").add(const Duration(days: 28)), @@ -1396,7 +1754,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$3 = PillSheet( + final pillSheet3 = PillSheet( id: firestoreIDGenerator(), groupIndex: 2, beginingDate: DateTime.parse("2020-09-01").add(const Duration(days: 28 * 2)), @@ -1412,7 +1770,7 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["1", "2", "3"], - pillSheets: [pillSheet, pillShee$2, pillShee$3], + pillSheets: [pillSheet, pillSheet2, pillSheet3], createdAt: now(), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); @@ -1447,7 +1805,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: firestoreIDGenerator(), groupIndex: 1, beginingDate: DateTime.parse("2020-09-01").add(const Duration(days: 28)), @@ -1460,7 +1818,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - final pillShee$3 = PillSheet( + final pillSheet3 = PillSheet( id: firestoreIDGenerator(), groupIndex: 2, beginingDate: DateTime.parse("2020-09-01").add(const Duration(days: 28 * 2)), @@ -1476,7 +1834,7 @@ void main() { // created at and id are anything value final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["1", "2", "3"], - pillSheets: [pillSheet, pillShee$2, pillShee$3], + pillSheets: [pillSheet, pillSheet2, pillSheet3], createdAt: now(), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); diff --git a/test/entity/pill_sheet_test.dart b/test/entity/pill_sheet_test.dart index 081a2584eb..1e4529d399 100644 --- a/test/entity/pill_sheet_test.dart +++ b/test/entity/pill_sheet_test.dart @@ -464,7 +464,7 @@ void main() { expect(model.isBegan, false); }); }); - group("#lastTakenPillNumber", () { + group("#lastTakenOrZeroPillNumber", () { test("未服用の場合は0になる", () { final mockTodayRepository = MockTodayService(); todayRepository = mockTodayRepository; @@ -483,7 +483,27 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - expect(model.lastTakenPillNumber, 0); + expect(model.lastTakenOrZeroPillNumber, 0); + }); + test("beginingDate > lastTakenDateの場合は0になる。服用日が開始日より前になる。「今日飲むピル番号」の調整機能で1つ目のピルを選択した時", () { + final mockTodayRepository = MockTodayService(); + todayRepository = mockTodayRepository; + when(mockTodayRepository.now()).thenReturn(DateTime.parse("2020-09-19")); + + const sheetType = PillSheetType.pillsheet_21; + final model = PillSheet( + id: firestoreIDGenerator(), + beginingDate: DateTime.parse("2020-09-14"), + lastTakenDate: DateTime.parse("2020-09-13"), + createdAt: now(), + typeInfo: PillSheetTypeInfo( + dosingPeriod: sheetType.dosingPeriod, + name: sheetType.fullName, + totalCount: sheetType.totalCount, + pillSheetTypeReferencePath: sheetType.rawPath, + ), + ); + expect(model.lastTakenOrZeroPillNumber, 0); }); test("6日目だが4番まで服用済み", () { final mockTodayRepository = MockTodayService(); @@ -503,7 +523,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - expect(model.lastTakenPillNumber, 4); + expect(model.lastTakenOrZeroPillNumber, 4); }); test("境界値テスト。28番を服用", () { final mockTodayRepository = MockTodayService(); @@ -523,7 +543,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - expect(model.lastTakenPillNumber, 28); + expect(model.lastTakenOrZeroPillNumber, 28); }); test("服用お休み期間がある場合。服用お休みが終了してない場合", () { final mockTodayRepository = MockTodayService(); @@ -550,7 +570,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - expect(model.lastTakenPillNumber, 22); + expect(model.lastTakenOrZeroPillNumber, 22); }); test("服用お休み期間がある場合。服用お休みが終了している場合", () { final mockTodayRepository = MockTodayService(); @@ -578,7 +598,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - expect(model.lastTakenPillNumber, 25); + expect(model.lastTakenOrZeroPillNumber, 25); }); test("服用お休みが終了しているが、まだピルを服用していない場合", () { final mockTodayRepository = MockTodayService(); @@ -606,7 +626,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - expect(model.lastTakenPillNumber, 0); + expect(model.lastTakenOrZeroPillNumber, 0); }); group("服用お休みを同じピルシートで複数している場合", () { @@ -641,7 +661,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - expect(model.lastTakenPillNumber, 19); + expect(model.lastTakenOrZeroPillNumber, 19); }); test("最後の服用お休みが終了している場合", () { final mockTodayRepository = MockTodayService(); @@ -675,7 +695,7 @@ void main() { pillSheetTypeReferencePath: sheetType.rawPath, ), ); - expect(model.lastTakenPillNumber, 19); + expect(model.lastTakenOrZeroPillNumber, 19); }); }); }); diff --git a/test/features/calendar/util_test.dart b/test/features/calendar/util_test.dart index 5006b9a9fb..af5ed4f177 100644 --- a/test/features/calendar/util_test.dart +++ b/test/features/calendar/util_test.dart @@ -40,7 +40,7 @@ void main() { lastTakenDate: null, createdAt: now(), ); - var pillShee$2 = PillSheet( + var pillSheet2 = PillSheet( id: firestoreIDGenerator(), typeInfo: PillSheetType.pillsheet_24_0.typeInfo, beginingDate: beginingDate.add(const Duration(days: 28)), @@ -49,7 +49,7 @@ void main() { ); final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["1", "2"], - pillSheets: [pillSheet, pillShee$2], + pillSheets: [pillSheet, pillSheet2], createdAt: now(), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); @@ -96,7 +96,7 @@ void main() { lastTakenDate: null, createdAt: now(), ); - var pillShee$2 = PillSheet( + var pillSheet2 = PillSheet( id: firestoreIDGenerator(), typeInfo: PillSheetType.pillsheet_21_0.typeInfo, beginingDate: beginingDate.add(const Duration(days: 28)), @@ -105,7 +105,7 @@ void main() { ); final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["1", "2"], - pillSheets: [pillSheet, pillShee$2], + pillSheets: [pillSheet, pillSheet2], createdAt: now(), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); @@ -152,7 +152,7 @@ void main() { lastTakenDate: null, createdAt: now(), ); - var pillShee$2 = PillSheet( + var pillSheet2 = PillSheet( id: firestoreIDGenerator(), typeInfo: PillSheetType.pillsheet_24_0.typeInfo, beginingDate: beginingDate.add(const Duration(days: 28)), @@ -161,7 +161,7 @@ void main() { ); final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["1", "2"], - pillSheets: [pillSheet, pillShee$2], + pillSheets: [pillSheet, pillSheet2], createdAt: now(), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); @@ -623,7 +623,7 @@ void main() { lastTakenDate: null, createdAt: now(), ); - var pillShee$2 = PillSheet( + var pillSheet2 = PillSheet( id: firestoreIDGenerator(), typeInfo: PillSheetType.pillsheet_21_0.typeInfo, beginingDate: beginingDate.add(const Duration(days: 28)), @@ -632,7 +632,7 @@ void main() { ); final pillSheetGroup = PillSheetGroup( pillSheetIDs: ["1", "2"], - pillSheets: [pillSheet, pillShee$2], + pillSheets: [pillSheet, pillSheet2], createdAt: now(), pillSheetAppearanceMode: PillSheetAppearanceMode.number, ); diff --git a/test/features/initial_setting/initial_setting_state_notifier_test.dart b/test/features/initial_setting/initial_setting_state_notifier_test.dart index a4562b8028..50f8cb5e15 100644 --- a/test/features/initial_setting/initial_setting_state_notifier_test.dart +++ b/test/features/initial_setting/initial_setting_state_notifier_test.dart @@ -370,7 +370,7 @@ void main() { lastTakenDate: DateTime.parse("2020-09-18"), createdAt: now(), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: "sheet_id2", typeInfo: PillSheetType.pillsheet_21.typeInfo, beginingDate: mockToday, @@ -383,7 +383,7 @@ void main() { pillSheetIDs: ["sheet_id", "sheet_id2"], pillSheets: [ pillSheet.copyWith(id: "sheet_id"), - pillShee$2.copyWith(id: "sheet_id2"), + pillSheet2.copyWith(id: "sheet_id2"), ], createdAt: now(), pillSheetAppearanceMode: PillSheetAppearanceMode.date, diff --git a/test/features/record/provider/add_pill_sheet_group_test.dart b/test/features/record/provider/add_pill_sheet_group_test.dart index db959664cf..2d9d41bea1 100644 --- a/test/features/record/provider/add_pill_sheet_group_test.dart +++ b/test/features/record/provider/add_pill_sheet_group_test.dart @@ -121,7 +121,7 @@ void main() { lastTakenDate: null, createdAt: now(), ); - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: "sheet_id2", typeInfo: PillSheetType.pillsheet_21.typeInfo, beginingDate: mockToday.add(const Duration(days: 28)), @@ -134,7 +134,7 @@ void main() { pillSheetIDs: ["sheet_id", "sheet_id2"], pillSheets: [ pillSheet.copyWith(id: "sheet_id"), - pillShee$2.copyWith(id: "sheet_id2"), + pillSheet2.copyWith(id: "sheet_id2"), ], createdAt: now(), ); diff --git a/test/features/record/provider/revert_take_pill_test.dart b/test/features/record/provider/revert_take_pill_test.dart index 7da2a6a557..d3ce0301ad 100644 --- a/test/features/record/provider/revert_take_pill_test.dart +++ b/test/features/record/provider/revert_take_pill_test.dart @@ -53,7 +53,7 @@ void main() { pillSheetIDs: ["sheet_id"], pillSheets: [ pillSheet.copyWith( - lastTakenDate: yesterday.subtract(const Duration(days: 1)), + lastTakenDate: null, ), ], createdAt: now(), @@ -208,7 +208,7 @@ void main() { pillSheetIDs: ["sheet_id"], pillSheets: [ pillSheet.copyWith( - lastTakenDate: beginDate.subtract(const Duration(days: 1)), + lastTakenDate: null, restDurations: [], ), ], @@ -357,7 +357,7 @@ void main() { ); // actived pill sheet - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: "2", typeInfo: PillSheetType.pillsheet_21.typeInfo, beginingDate: yesterday, @@ -369,7 +369,7 @@ void main() { final pillSheetGroup = PillSheetGroup( id: "group_id", pillSheetIDs: ["1", "2"], - pillSheets: [pillSheet, pillShee$2], + pillSheets: [pillSheet, pillSheet2], createdAt: now(), ); final updatedPillSheetGroup = PillSheetGroup( @@ -377,7 +377,7 @@ void main() { pillSheetIDs: ["1", "2"], pillSheets: [ pillSheet, - pillShee$2.copyWith( + pillSheet2.copyWith( lastTakenDate: yesterday, ), ], @@ -388,8 +388,8 @@ void main() { final history = PillSheetModifiedHistoryServiceActionFactory.createRevertTakenPillAction( pillSheetGroupID: "group_id", - before: pillShee$2, - after: pillShee$2.copyWith( + before: pillSheet2, + after: pillSheet2.copyWith( lastTakenDate: yesterday, ), beforePillSheetGroup: pillSheetGroup, @@ -442,7 +442,7 @@ void main() { ); // actived pill sheet - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: "2", typeInfo: PillSheetType.pillsheet_21.typeInfo, beginingDate: yesterday, @@ -454,7 +454,7 @@ void main() { final pillSheetGroup = PillSheetGroup( id: "group_id", pillSheetIDs: ["1", "2"], - pillSheets: [pillSheet, pillShee$2], + pillSheets: [pillSheet, pillSheet2], createdAt: now(), ); final updatedPillSheetGroup = PillSheetGroup( @@ -464,8 +464,8 @@ void main() { pillSheet.copyWith( lastTakenDate: mockToday.subtract(const Duration(days: 4)), ), - pillShee$2.copyWith( - lastTakenDate: pillShee$2.beginingDate.subtract(const Duration(days: 1)), + pillSheet2.copyWith( + lastTakenDate: null, ), ], createdAt: now(), @@ -475,7 +475,7 @@ void main() { final history = PillSheetModifiedHistoryServiceActionFactory.createRevertTakenPillAction( pillSheetGroupID: "group_id", - before: pillShee$2, + before: pillSheet2, after: pillSheet.copyWith(lastTakenDate: mockToday.subtract(const Duration(days: 4))), beforePillSheetGroup: pillSheetGroup, afterPillSheetGroup: updatedPillSheetGroup, @@ -526,7 +526,7 @@ void main() { ); // actived pill sheet - final pillShee$2 = PillSheet( + final pillSheet2 = PillSheet( id: "2", typeInfo: PillSheetType.pillsheet_21.typeInfo, beginingDate: yesterday, @@ -541,7 +541,7 @@ void main() { final pillSheetGroup = PillSheetGroup( id: "group_id", pillSheetIDs: ["1", "2"], - pillSheets: [pillSheet, pillShee$2], + pillSheets: [pillSheet, pillSheet2], createdAt: now(), ); final updatedPillSheetGroup = PillSheetGroup( @@ -551,8 +551,8 @@ void main() { pillSheet.copyWith( lastTakenDate: mockToday.subtract(const Duration(days: 4)), ), - pillShee$2.copyWith( - lastTakenDate: pillShee$2.beginingDate.subtract(const Duration(days: 1)), + pillSheet2.copyWith( + lastTakenDate: null, restDurations: [], ) ], @@ -563,7 +563,7 @@ void main() { final history = PillSheetModifiedHistoryServiceActionFactory.createRevertTakenPillAction( pillSheetGroupID: "group_id", - before: pillShee$2, + before: pillSheet2, after: pillSheet.copyWith(lastTakenDate: mockToday.subtract(const Duration(days: 4)), restDurations: []), beforePillSheetGroup: pillSheetGroup, afterPillSheetGroup: updatedPillSheetGroup, diff --git a/test/features/record/record_page_state_test.dart b/test/features/record/record_page_state_test.dart index 0433199cbc..3bcb036970 100644 --- a/test/features/record/record_page_state_test.dart +++ b/test/features/record/record_page_state_test.dart @@ -34,7 +34,7 @@ void main() { final pillSheetGroup = PillSheetGroup(pillSheetIDs: ["1"], pillSheets: [pillSheetEntity], createdAt: now()); await waitForResetStoreState(); - expect(pillSheetGroup.pillSheets.first.todayPillNumber, pillSheetGroup.pillSheets.first.lastTakenPillNumber); + expect(pillSheetGroup.pillSheets.first.todayPillNumber, pillSheetGroup.pillSheets.first.lastTakenOrZeroPillNumber); expect(pillSheetGroup.pillSheets.first.todayPillIsAlreadyTaken, isTrue); expect(pillMarkFor(pillNumberInPillSheet: 1, pillSheet: pillSheetEntity), PillMarkType.done); expect(pillMarkFor(pillNumberInPillSheet: 2, pillSheet: pillSheetEntity), PillMarkType.done); diff --git a/test/provider/change_pill_number_test.dart b/test/provider/change_pill_number_test.dart index 7f583357d8..2d6d86d828 100644 --- a/test/provider/change_pill_number_test.dart +++ b/test/provider/change_pill_number_test.dart @@ -367,7 +367,7 @@ void main() { ); final updatedRight = right.copyWith( beginingDate: DateTime.parse("2022-05-01"), - lastTakenDate: DateTime.parse("2022-04-30"), + lastTakenDate: null, ); final pillSheetGroup = PillSheetGroup(