From ab5331bcc4448d62891a569459f1edcadabdcf8a Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Tue, 4 Aug 2026 13:52:44 +0200 Subject: [PATCH] Fix tests --- .../providers/measurement_repository_test.dart | 13 +++++++++++-- .../nutrition/widgets/plan_weight_chart_test.dart | 12 +++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/test/features/measurements/providers/measurement_repository_test.dart b/test/features/measurements/providers/measurement_repository_test.dart index 26bbd2a82..f27359ddd 100644 --- a/test/features/measurements/providers/measurement_repository_test.dart +++ b/test/features/measurements/providers/measurement_repository_test.dart @@ -221,6 +221,15 @@ void main() { }); group('watchOfficialBodyWeightCategory', () { + /// The entries with their dates back in UTC. + /// + /// Drift hands them over in the local zone (UtcDateTimeConverter), and a + /// DateTime only equals another one in the same zone, so comparing against + /// the UTC fixtures passes in UTC and nowhere else. + List inUtc(Iterable entries) => [ + for (final entry in entries) entry.copyWith(date: entry.date.toUtc()), + ]; + Future seedBodyWeight() async { await repo.addLocalDriftCategory(getBodyWeightCategory()); for (final entry in [testWeightEntry1, testWeightEntry2]) { @@ -235,7 +244,7 @@ void main() { final emitted = await repo.watchOfficialBodyWeightCategory().first; expect(emitted!.id, testBodyWeightCategoryId); - expect(emitted.entries, [testWeightEntry2, testWeightEntry1]); + expect(inUtc(emitted.entries), [testWeightEntry2, testWeightEntry1]); }); test('a category of the same type that is not official is ignored', () async { @@ -267,7 +276,7 @@ void main() { .watchOfficialBodyWeightCategory(entriesSince: DateTime.utc(2021, 01, 05)) .first; - expect(emitted!.entries, [testWeightEntry2]); + expect(inUtc(emitted!.entries), [testWeightEntry2]); }); }); diff --git a/test/features/nutrition/widgets/plan_weight_chart_test.dart b/test/features/nutrition/widgets/plan_weight_chart_test.dart index 6371fddfa..cc587926b 100644 --- a/test/features/nutrition/widgets/plan_weight_chart_test.dart +++ b/test/features/nutrition/widgets/plan_weight_chart_test.dart @@ -40,10 +40,16 @@ void main() { setUp(() { mockMeasurementRepo = MockMeasurementRepository(); - when(mockMeasurementRepo.watchAll()).thenAnswer( - (_) => Stream.value([ + // The chart reads the official category through bodyWeightCategoryProvider, + // not the whole list + when( + mockMeasurementRepo.watchOfficialBodyWeightCategory( + entriesSince: anyNamed('entriesSince'), + ), + ).thenAnswer( + (_) => Stream.value( getBodyWeightCategory([testWeightEntry2, testWeightEntry1, testWeightEntryLb]), - ]), + ), ); mockUserProfileRepo = MockUserProfileRepository();