diff --git a/lib/features/measurements/widgets/helpers.dart b/lib/features/measurements/widgets/helpers.dart index 4d943f310..2e9961705 100644 --- a/lib/features/measurements/widgets/helpers.dart +++ b/lib/features/measurements/widgets/helpers.dart @@ -296,7 +296,9 @@ class MeasurementDistributionChart extends ConsumerWidget { watch: (ref) => ref.watch(measurementValueCountsProvider(category.id!, range.countCutoff, summed)), loading: const CenteredProgressIndicator(), - builder: (context, counts) => [_histogram(counts, summed)], + // The histogram fills the height it is given; the column around it would + // otherwise offer it an unbounded one + builder: (context, counts) => [Expanded(child: _histogram(counts, summed))], onError: (_, error) => [StreamErrorIndicator(error.toString())], ); } diff --git a/test/features/measurements/widgets/entries_test.dart b/test/features/measurements/widgets/entries_test.dart index 063bf40d0..cfb1efdf9 100644 --- a/test/features/measurements/widgets/entries_test.dart +++ b/test/features/measurements/widgets/entries_test.dart @@ -224,6 +224,34 @@ void main() { expect(find.textContaining('Blutdruck'), findsNothing); }); + testWidgets('A distribution category draws its histogram in the chart box', ( + WidgetTester tester, + ) async { + // The histogram fills the height it is given, and the list around it is a + // scrollable: an unbounded box reaching it is a layout error + final category = MeasurementCategory( + id: 'c1', + name: 'Bizeps', + unit: 'cm', + chartType: ChartType.distribution, + ); + final entries = [ + for (var day = 0; day < 30; day++) + MeasurementEntry( + id: 'e-$day', + categoryId: 'c1', + date: DateTime.now().subtract(Duration(days: day)), + value: 30 + day % 5, + notes: '', + ), + ]; + + await tester.pumpWidget(createEntriesList(category, {'c1': entries})); + await tester.pumpAndSettle(); + + expect(find.byType(MeasurementDistributionWidgetFl), findsOneWidget); + }); + testWidgets('A free-form category keeps the name the user gave it', ( WidgetTester tester, ) async { diff --git a/test/helpers/measurement_repository_stubs.dart b/test/helpers/measurement_repository_stubs.dart index 423d9cf6e..cd050be87 100644 --- a/test/helpers/measurement_repository_stubs.dart +++ b/test/helpers/measurement_repository_stubs.dart @@ -121,6 +121,28 @@ void stubMeasurementReads( }); }); + // Counted over the whole fixture: the cutoff and the daily summing are the + // repository's own, and covered where they happen + when( + repo.watchValueCounts(any, since: anyNamed('since'), summedPerDay: anyNamed('summedPerDay')), + ).thenAnswer((invocation) { + final ofCategory = entries[invocation.positionalArguments.first as String] ?? const []; + final byValue = >{}; + for (final entry in ofCategory) { + byValue.putIfAbsent(entry.value, () => []).add(entry); + } + + return Stream.value([ + for (final MapEntry(:key, :value) in byValue.entries) + MeasurementValueCount( + value: key, + unit: null, + count: value.length, + newest: value.map((e) => e.date).reduce((a, b) => b.isAfter(a) ? b : a), + ), + ]); + }); + when(repo.watchDailyBuckets()).thenAnswer( (_) => Stream.value({ for (final id in entries.keys) id: dayBuckets(entries[id]!),