mirror of
https://github.com/wger-project/flutter.git
synced 2026-11-29 01:18:35 +01:00
Give the distribution chart the height it is drawn in
This commit is contained in:
@@ -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())],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 = <num, List<MeasurementEntry>>{};
|
||||
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]!),
|
||||
|
||||
Reference in New Issue
Block a user