Point the weight screen test at the method the screen calls

This commit is contained in:
Roland Geider
2026-08-03 20:20:17 +02:00
parent d4e28bfb70
commit d93794de5b

View File

@@ -63,6 +63,11 @@ void main() {
when( when(
mockMeasurementRepository.watchAll(entriesSince: anyNamed('entriesSince')), mockMeasurementRepository.watchAll(entriesSince: anyNamed('entriesSince')),
).thenAnswer((_) => Stream.value([getBodyWeightCategory()])); ).thenAnswer((_) => Stream.value([getBodyWeightCategory()]));
when(
mockMeasurementRepository.watchOfficialBodyWeightCategory(
entriesSince: anyNamed('entriesSince'),
),
).thenAnswer((_) => Stream.value(getBodyWeightCategory()));
when( when(
mockMeasurementRepository.deleteLocalDrift(any), mockMeasurementRepository.deleteLocalDrift(any),
).thenAnswer((_) async => Future.value()); ).thenAnswer((_) async => Future.value());
@@ -135,9 +140,9 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
// The default range reads from its cutoff on // The default range reads from its cutoff on
verifyNever(mockMeasurementRepository.watchAll(entriesSince: null)); verifyNever(mockMeasurementRepository.watchOfficialBodyWeightCategory(entriesSince: null));
verify( verify(
mockMeasurementRepository.watchAll( mockMeasurementRepository.watchOfficialBodyWeightCategory(
entriesSince: argThat(isNotNull, named: 'entriesSince'), entriesSince: argThat(isNotNull, named: 'entriesSince'),
), ),
).called(greaterThanOrEqualTo(1)); ).called(greaterThanOrEqualTo(1));
@@ -147,7 +152,9 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
// The full history has no lower bound // The full history has no lower bound
verify(mockMeasurementRepository.watchAll(entriesSince: null)).called(1); verify(
mockMeasurementRepository.watchOfficialBodyWeightCategory(entriesSince: null),
).called(1);
}); });
testWidgets('Test deleting an item using the Delete button', (WidgetTester tester) async { testWidgets('Test deleting an item using the Delete button', (WidgetTester tester) async {
@@ -180,10 +187,12 @@ void main() {
testWidgets('Converts mixed-unit entries to the profile unit', (WidgetTester tester) async { testWidgets('Converts mixed-unit entries to the profile unit', (WidgetTester tester) async {
// 176.4 lb convert to 80.01 kg for the metric profile; the kg entry stays // 176.4 lb convert to 80.01 kg for the metric profile; the kg entry stays
when(mockMeasurementRepository.watchAll(entriesSince: anyNamed('entriesSince'))).thenAnswer( when(
(_) => Stream.value([ mockMeasurementRepository.watchOfficialBodyWeightCategory(
getBodyWeightCategory([testWeightEntryLb, testWeightEntry1]), entriesSince: anyNamed('entriesSince'),
]), ),
).thenAnswer(
(_) => Stream.value(getBodyWeightCategory([testWeightEntryLb, testWeightEntry1])),
); );
await tester.pumpWidget(createWeightScreen()); await tester.pumpWidget(createWeightScreen());
@@ -209,10 +218,12 @@ void main() {
source: 'apple', source: 'apple',
externalId: 'w-1', externalId: 'w-1',
); );
when(mockMeasurementRepository.watchAll(entriesSince: anyNamed('entriesSince'))).thenAnswer( when(
(_) => Stream.value([ mockMeasurementRepository.watchOfficialBodyWeightCategory(
getBodyWeightCategory([imported, testWeightEntry1]), entriesSince: anyNamed('entriesSince'),
]), ),
).thenAnswer(
(_) => Stream.value(getBodyWeightCategory([imported, testWeightEntry1])),
); );
await tester.pumpWidget(createWeightScreen()); await tester.pumpWidget(createWeightScreen());
@@ -227,8 +238,10 @@ void main() {
WidgetTester tester, WidgetTester tester,
) async { ) async {
when( when(
mockMeasurementRepository.watchAll(entriesSince: anyNamed('entriesSince')), mockMeasurementRepository.watchOfficialBodyWeightCategory(
).thenAnswer((_) => Stream.value([])); entriesSince: anyNamed('entriesSince'),
),
).thenAnswer((_) => Stream.value(null));
await tester.pumpWidget(createWeightScreen()); await tester.pumpWidget(createWeightScreen());
// No pumpAndSettle: the overview shows an endless spinner in this state // No pumpAndSettle: the overview shows an endless spinner in this state