mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-01 02:02:35 +01:00
Aggregate measurement chart points in SQL
This commit is contained in:
87
lib/features/measurements/models/measurement_bucket.dart
Normal file
87
lib/features/measurements/models/measurement_bucket.dart
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* This file is part of wger Workout Manager <https://github.com/wger-project>.
|
||||
* Copyright (c) 2026 wger Team
|
||||
*
|
||||
* wger Workout Manager is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/// Points a chart is condensed to.
|
||||
///
|
||||
/// Shared by the two implementations of the same ladder: the SQL one in
|
||||
/// `MeasurementRepository.watchEntryBuckets` and `downsample`, which still
|
||||
/// serves the paths that read entries rather than buckets.
|
||||
const measurementChartMaxPoints = 200;
|
||||
|
||||
/// Calendar units a category's entries are condensed into, finest first.
|
||||
///
|
||||
/// The calendar rather than equal slices of the span: these metrics have a
|
||||
/// daily rhythm, so slices that do not line up with a day each catch a
|
||||
/// different phase of it and the chart oscillates at the slice frequency.
|
||||
enum MeasurementBucketUnit {
|
||||
/// One bucket per entry, i.e. no condensing.
|
||||
entry,
|
||||
hour,
|
||||
day,
|
||||
week,
|
||||
month,
|
||||
}
|
||||
|
||||
/// The level a chart wants its points at.
|
||||
///
|
||||
/// Only [auto] is free to pick from the whole ladder; the others exist because
|
||||
/// the chart itself is built on a calendar unit and coarser points would draw
|
||||
/// a grid of the wrong cells.
|
||||
enum MeasurementBucketLevel {
|
||||
/// The finest unit that keeps the series under the point limit.
|
||||
auto,
|
||||
|
||||
/// One point per calendar day, whatever the point count.
|
||||
day,
|
||||
|
||||
/// One point per calendar week (starting Monday).
|
||||
week,
|
||||
}
|
||||
|
||||
/// One calendar bucket of a category's entries, as SQLite aggregated it.
|
||||
///
|
||||
/// Grouped by bucket *and* by the unit the values were entered in, so a
|
||||
/// category holding mixed units yields one bucket per unit and the caller
|
||||
/// converts each before merging them.
|
||||
class MeasurementBucket {
|
||||
const MeasurementBucket({
|
||||
required this.start,
|
||||
required this.unit,
|
||||
required this.count,
|
||||
required this.sum,
|
||||
required this.min,
|
||||
required this.max,
|
||||
});
|
||||
|
||||
/// Start of the bucket in the local zone; the entry's own timestamp at the
|
||||
/// [MeasurementBucketUnit.entry] level.
|
||||
final DateTime start;
|
||||
|
||||
/// Unit the values in it were entered in (`extra_data.unit`), null when they
|
||||
/// carry none and the category unit applies.
|
||||
final String? unit;
|
||||
|
||||
final int count;
|
||||
final num sum;
|
||||
|
||||
/// Lowest and highest value the bucket stands for. A daily aggregate
|
||||
/// contributes its stored bounds rather than its value, so condensing one
|
||||
/// keeps the true extremes.
|
||||
final num min;
|
||||
final num max;
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import 'package:collection/collection.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:wger/core/network/auth_credentials_storage.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart';
|
||||
|
||||
@@ -53,6 +54,23 @@ Stream<Map<String, MeasurementEntry>> latestMeasurementEntries(Ref ref) {
|
||||
return ref.read(measurementRepositoryProvider).watchLatestEntries();
|
||||
}
|
||||
|
||||
/// The chart points of one category, condensed by SQLite.
|
||||
///
|
||||
/// Kept apart from the category streams, which hand over the entries
|
||||
/// themselves. [level] is what the chart in question needs, see
|
||||
/// `chartBucketLevel`.
|
||||
@riverpod
|
||||
Stream<List<MeasurementBucket>> measurementChartBuckets(
|
||||
Ref ref,
|
||||
String categoryId,
|
||||
DateTime? since,
|
||||
MeasurementBucketLevel level,
|
||||
) {
|
||||
return ref
|
||||
.read(measurementRepositoryProvider)
|
||||
.watchEntryBuckets(categoryId, since: since, level: level);
|
||||
}
|
||||
|
||||
/// One category with its children and the entries from [since] on, null while
|
||||
/// it does not exist (or no longer does).
|
||||
@riverpod
|
||||
|
||||
@@ -180,6 +180,125 @@ final class LatestMeasurementEntriesProvider
|
||||
|
||||
String _$latestMeasurementEntriesHash() => r'87b87ef6ca747e9f47855692f9e687b85f81e99b';
|
||||
|
||||
/// The chart points of one category, condensed by SQLite.
|
||||
///
|
||||
/// Kept apart from the category streams, which hand over the entries
|
||||
/// themselves: a chart shows a few hundred points, and a watch-fed metric
|
||||
/// holds tens of thousands a year. [level] is what the chart in question needs,
|
||||
/// see `chartBucketLevel`.
|
||||
|
||||
@ProviderFor(measurementChartBuckets)
|
||||
final measurementChartBucketsProvider = MeasurementChartBucketsFamily._();
|
||||
|
||||
/// The chart points of one category, condensed by SQLite.
|
||||
///
|
||||
/// Kept apart from the category streams, which hand over the entries
|
||||
/// themselves: a chart shows a few hundred points, and a watch-fed metric
|
||||
/// holds tens of thousands a year. [level] is what the chart in question needs,
|
||||
/// see `chartBucketLevel`.
|
||||
|
||||
final class MeasurementChartBucketsProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
AsyncValue<List<MeasurementBucket>>,
|
||||
List<MeasurementBucket>,
|
||||
Stream<List<MeasurementBucket>>
|
||||
>
|
||||
with $FutureModifier<List<MeasurementBucket>>, $StreamProvider<List<MeasurementBucket>> {
|
||||
/// The chart points of one category, condensed by SQLite.
|
||||
///
|
||||
/// Kept apart from the category streams, which hand over the entries
|
||||
/// themselves: a chart shows a few hundred points, and a watch-fed metric
|
||||
/// holds tens of thousands a year. [level] is what the chart in question needs,
|
||||
/// see `chartBucketLevel`.
|
||||
MeasurementChartBucketsProvider._({
|
||||
required MeasurementChartBucketsFamily super.from,
|
||||
required (String, DateTime?, MeasurementBucketLevel) super.argument,
|
||||
}) : super(
|
||||
retry: null,
|
||||
name: r'measurementChartBucketsProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$measurementChartBucketsHash();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return r'measurementChartBucketsProvider'
|
||||
''
|
||||
'$argument';
|
||||
}
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$StreamProviderElement<List<MeasurementBucket>> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $StreamProviderElement(pointer);
|
||||
|
||||
@override
|
||||
Stream<List<MeasurementBucket>> create(Ref ref) {
|
||||
final argument = this.argument as (String, DateTime?, MeasurementBucketLevel);
|
||||
return measurementChartBuckets(ref, argument.$1, argument.$2, argument.$3);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is MeasurementChartBucketsProvider && other.argument == argument;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return argument.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
String _$measurementChartBucketsHash() => r'90698be9ec4f287fc4764549bc6cbcb5b7933262';
|
||||
|
||||
/// The chart points of one category, condensed by SQLite.
|
||||
///
|
||||
/// Kept apart from the category streams, which hand over the entries
|
||||
/// themselves: a chart shows a few hundred points, and a watch-fed metric
|
||||
/// holds tens of thousands a year. [level] is what the chart in question needs,
|
||||
/// see `chartBucketLevel`.
|
||||
|
||||
final class MeasurementChartBucketsFamily extends $Family
|
||||
with
|
||||
$FunctionalFamilyOverride<
|
||||
Stream<List<MeasurementBucket>>,
|
||||
(String, DateTime?, MeasurementBucketLevel)
|
||||
> {
|
||||
MeasurementChartBucketsFamily._()
|
||||
: super(
|
||||
retry: null,
|
||||
name: r'measurementChartBucketsProvider',
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
isAutoDispose: true,
|
||||
);
|
||||
|
||||
/// The chart points of one category, condensed by SQLite.
|
||||
///
|
||||
/// Kept apart from the category streams, which hand over the entries
|
||||
/// themselves: a chart shows a few hundred points, and a watch-fed metric
|
||||
/// holds tens of thousands a year. [level] is what the chart in question needs,
|
||||
/// see `chartBucketLevel`.
|
||||
|
||||
MeasurementChartBucketsProvider call(
|
||||
String categoryId,
|
||||
DateTime? since,
|
||||
MeasurementBucketLevel level,
|
||||
) => MeasurementChartBucketsProvider._(
|
||||
argument: (categoryId, since, level),
|
||||
from: this,
|
||||
);
|
||||
|
||||
@override
|
||||
String toString() => r'measurementChartBucketsProvider';
|
||||
}
|
||||
|
||||
/// One category with its children and the entries from [since] on, null while
|
||||
/// it does not exist (or no longer does).
|
||||
|
||||
|
||||
@@ -24,7 +24,9 @@ import 'package:collection/collection.dart';
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:stream_transform/stream_transform.dart';
|
||||
import 'package:wger/database/powersync/database.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart';
|
||||
|
||||
@@ -39,6 +41,11 @@ class MeasurementRepository {
|
||||
|
||||
MeasurementRepository(this._db);
|
||||
|
||||
/// Coalesces the bursts a health import writes, so the per-emission work
|
||||
/// below runs once they settle. Leading, unlike the nutrition streams: a
|
||||
/// screen is waiting for the first emission.
|
||||
static const _emitDebounce = Duration(milliseconds: 200);
|
||||
|
||||
/// Watches all categories, populated with their appropriate entries.
|
||||
///
|
||||
/// The list is flat (children of multi-value groups appear as regular items
|
||||
@@ -82,7 +89,7 @@ class MeasurementRepository {
|
||||
OrderingTerm(expression: _db.measurementEntryTable.date, mode: OrderingMode.desc),
|
||||
]);
|
||||
|
||||
return joined.watch().map((rows) {
|
||||
return joined.watch().debounce(_emitDebounce, leading: true).map((rows) {
|
||||
final Map<String, MeasurementCategory> map = {};
|
||||
// Guards against the same entry being added twice. Scanning the list
|
||||
// built so far would do, but is quadratic, and a category can hold
|
||||
@@ -165,12 +172,145 @@ class MeasurementRepository {
|
||||
// Entries that share the newest timestamp (the importer writes a day
|
||||
// aggregate on midnight) collapse onto one, which is what a single latest
|
||||
// value means
|
||||
return query.watch().map((rows) {
|
||||
return query.watch().debounce(_emitDebounce, leading: true).map((rows) {
|
||||
final entries = rows.map((row) => table.map(row.data));
|
||||
return {for (final entry in entries) entry.categoryId: entry};
|
||||
});
|
||||
}
|
||||
|
||||
/// Chart points for [categoryId]: one bucket per calendar unit, condensed by
|
||||
/// SQLite instead of by walking every entry in Dart.
|
||||
///
|
||||
/// [level] fixes the unit for the charts built on one; `auto` takes the
|
||||
/// finest that keeps the series under [maxPoints], down to one bucket per
|
||||
/// entry. [since] bounds the entries read, null covers the full history.
|
||||
///
|
||||
/// The ladder is the same one `downsample` walks in Dart for the paths that
|
||||
/// read entries; the two must stay in step.
|
||||
Stream<List<MeasurementBucket>> watchEntryBuckets(
|
||||
String categoryId, {
|
||||
DateTime? since,
|
||||
MeasurementBucketLevel level = MeasurementBucketLevel.auto,
|
||||
int maxPoints = measurementChartMaxPoints,
|
||||
}) {
|
||||
_logger.finer('Watching $level buckets of measurement category $categoryId');
|
||||
|
||||
final variables = [
|
||||
Variable.withString(categoryId),
|
||||
// Encoded the way drift writes the column (UTC ISO-8601 text), so this
|
||||
// reads the same rows as the typed queries above
|
||||
if (since != null) Variable.withString(since.toUtc().toIso8601String()),
|
||||
];
|
||||
final where = 'WHERE category_id = ?1${since == null ? '' : ' AND date >= ?2'}';
|
||||
|
||||
// Only `auto` reads the probe, so a fixed level does not pay for it
|
||||
final fixed = switch (level) {
|
||||
MeasurementBucketLevel.day => MeasurementBucketUnit.day,
|
||||
MeasurementBucketLevel.week => MeasurementBucketUnit.week,
|
||||
MeasurementBucketLevel.auto => null,
|
||||
};
|
||||
if (fixed != null) {
|
||||
return _bucketQuery(
|
||||
fixed,
|
||||
where,
|
||||
variables,
|
||||
).watch().debounce(_emitDebounce, leading: true).map(_toBuckets);
|
||||
}
|
||||
|
||||
// Every unit's point count in one pass, so picking one costs no scan
|
||||
// per candidate
|
||||
final probe = _db.customSelect(
|
||||
'SELECT COUNT(*) AS entries, '
|
||||
'COUNT(DISTINCT ${_bucketExpression(MeasurementBucketUnit.hour)}) AS hours, '
|
||||
'COUNT(DISTINCT ${_bucketExpression(MeasurementBucketUnit.day)}) AS days, '
|
||||
'COUNT(DISTINCT ${_bucketExpression(MeasurementBucketUnit.week)}) AS weeks '
|
||||
'FROM ${_db.measurementEntryTable.actualTableName} $where',
|
||||
variables: variables,
|
||||
readsFrom: {_db.measurementEntryTable},
|
||||
);
|
||||
|
||||
return probe
|
||||
.watchSingle()
|
||||
.debounce(_emitDebounce, leading: true)
|
||||
.asyncMap(
|
||||
(row) async => _toBuckets(
|
||||
await _bucketQuery(_ladderUnit(row, maxPoints), where, variables).get(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// The aggregate of a category's entries at [unit], one row per bucket and
|
||||
/// per unit the values were entered in: a mean over kg and lb values would
|
||||
/// be a number in neither.
|
||||
Selectable<QueryRow> _bucketQuery(
|
||||
MeasurementBucketUnit unit,
|
||||
String where,
|
||||
List<Variable> variables,
|
||||
) => _db.customSelect(
|
||||
'SELECT ${_bucketExpression(unit)} AS bucket, '
|
||||
r"json_extract(extra_data, '$.unit') AS unit, "
|
||||
'COUNT(*) AS n, '
|
||||
'SUM(value) AS total, '
|
||||
// A daily aggregate contributes the range it summarises, not its mean
|
||||
r"MIN(COALESCE(json_extract(extra_data, '$.min'), value)) AS low, "
|
||||
r"MAX(COALESCE(json_extract(extra_data, '$.max'), value)) AS high "
|
||||
'FROM ${_db.measurementEntryTable.actualTableName} $where '
|
||||
'GROUP BY bucket, unit ORDER BY bucket',
|
||||
variables: variables,
|
||||
readsFrom: {_db.measurementEntryTable},
|
||||
);
|
||||
|
||||
List<MeasurementBucket> _toBuckets(List<QueryRow> rows) => [
|
||||
for (final row in rows)
|
||||
MeasurementBucket(
|
||||
start: _parseBucketStart(row.read<String>('bucket')),
|
||||
unit: row.read<String?>('unit'),
|
||||
count: row.read<int>('n'),
|
||||
sum: row.read<double>('total'),
|
||||
min: row.read<double>('low'),
|
||||
max: row.read<double>('high'),
|
||||
),
|
||||
];
|
||||
|
||||
/// The finest unit that keeps the series under [maxPoints], mirroring the
|
||||
/// ladder `downsample` walks in Dart.
|
||||
MeasurementBucketUnit _ladderUnit(QueryRow probe, int maxPoints) {
|
||||
for (final (unit, points) in [
|
||||
(MeasurementBucketUnit.entry, probe.read<int>('entries')),
|
||||
(MeasurementBucketUnit.hour, probe.read<int>('hours')),
|
||||
(MeasurementBucketUnit.day, probe.read<int>('days')),
|
||||
(MeasurementBucketUnit.week, probe.read<int>('weeks')),
|
||||
]) {
|
||||
if (points <= maxPoints) {
|
||||
return unit;
|
||||
}
|
||||
}
|
||||
return MeasurementBucketUnit.month;
|
||||
}
|
||||
|
||||
/// The SQL producing a bucket key, which is also the bucket's start.
|
||||
///
|
||||
/// Shifted to the local zone, since the column is UTC: a reading half an
|
||||
/// hour after midnight belongs to the day the user had it.
|
||||
String _bucketExpression(MeasurementBucketUnit unit) => switch (unit) {
|
||||
MeasurementBucketUnit.entry => 'date',
|
||||
MeasurementBucketUnit.hour => "strftime('%Y-%m-%dT%H:00:00', date, 'localtime')",
|
||||
MeasurementBucketUnit.day => "strftime('%Y-%m-%dT00:00:00', date, 'localtime')",
|
||||
// 'weekday 1' moves to the next Monday or stays on one, so -6 days
|
||||
// first lands on the Monday of the entry's own week
|
||||
MeasurementBucketUnit.week =>
|
||||
"strftime('%Y-%m-%dT00:00:00', date, 'localtime', '-6 days', 'weekday 1')",
|
||||
MeasurementBucketUnit.month => "strftime('%Y-%m-01T00:00:00', date, 'localtime')",
|
||||
};
|
||||
|
||||
/// A bucket key as a local [DateTime]. The entry level hands back the stored
|
||||
/// column, which is UTC and marked as such; the other units are already
|
||||
/// local.
|
||||
DateTime _parseBucketStart(String value) {
|
||||
final parsed = DateTime.parse(value);
|
||||
return parsed.isUtc ? parsed.toLocal() : parsed;
|
||||
}
|
||||
|
||||
/// One-shot snapshot of all categories with their entries.
|
||||
Future<List<MeasurementCategory>> getAllOnce() => watchAll().first;
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:wger/core/form_screen.dart';
|
||||
import 'package:wger/core/formatting/formatting.dart';
|
||||
import 'package:wger/features/measurements/measurements.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
import 'package:wger/features/measurements/models/unit_conversion.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_notifier.dart';
|
||||
@@ -50,20 +49,6 @@ class CategoriesCard extends ConsumerWidget {
|
||||
return _buildGroupCard(context, ref);
|
||||
}
|
||||
|
||||
final cutoff = range.cutoff;
|
||||
final allEntries = chartEntriesFor(
|
||||
currentCategory.entries,
|
||||
targetUnit: currentCategory.unit,
|
||||
categoryUnit: currentCategory.unit,
|
||||
);
|
||||
// The average is computed over the full history and only then cut, so the
|
||||
// first points of the range average the days before it instead of starting
|
||||
// over at the cutoff
|
||||
final settings = currentCategory.chartSettings;
|
||||
final allAverage = movingAverage(allEntries, days: settings.averageWindow);
|
||||
final entriesAll = cutoff == null ? allEntries : allEntries.whereDate(cutoff, null);
|
||||
final average = cutoff == null ? allAverage : allAverage.whereDate(cutoff, null);
|
||||
|
||||
return Card(
|
||||
elevation: elevation,
|
||||
child: SingleChildScrollView(
|
||||
@@ -80,24 +65,14 @@ class CategoriesCard extends ConsumerWidget {
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
height: 220,
|
||||
child: buildChartForMetricType(
|
||||
currentCategory.metricType,
|
||||
entriesAll,
|
||||
average,
|
||||
currentCategory.unit,
|
||||
chartType: currentCategory.chartType,
|
||||
settings: settings,
|
||||
),
|
||||
MeasurementChartPoints(
|
||||
category: currentCategory,
|
||||
range: range,
|
||||
builder: _chart,
|
||||
// The card is one of many on the overview; a failing query takes
|
||||
// its chart, not the way into the category
|
||||
onError: (_, _) => const [SizedBox(height: 220)],
|
||||
),
|
||||
if (average.isNotEmpty && !currentCategory.metricType.isSummedPerDay)
|
||||
MeasurementOverallChangeWidget(
|
||||
average.first,
|
||||
average.last,
|
||||
currentCategory.unit,
|
||||
),
|
||||
const Divider(),
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
@@ -143,6 +118,33 @@ class CategoriesCard extends ConsumerWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// The chart itself and the one-number change below it.
|
||||
List<Widget> _chart(BuildContext context, List<MeasurementChartEntry> allPoints) {
|
||||
final settings = currentCategory.chartSettings;
|
||||
final (:entries, :average) = chartSeriesFor(allPoints, range, settings);
|
||||
|
||||
return [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
height: 220,
|
||||
child: buildChartForMetricType(
|
||||
currentCategory.metricType,
|
||||
entries,
|
||||
average,
|
||||
currentCategory.unit,
|
||||
chartType: currentCategory.chartType,
|
||||
settings: settings,
|
||||
),
|
||||
),
|
||||
if (average.isNotEmpty && !currentCategory.metricType.isSummedPerDay)
|
||||
MeasurementOverallChangeWidget(
|
||||
average.first,
|
||||
average.last,
|
||||
currentCategory.unit,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/// Card for a multi-value group (e.g. blood pressure): all components in one
|
||||
/// chart, then one row per component with its latest reading; new readings
|
||||
/// are entered for all components at once.
|
||||
|
||||
@@ -26,6 +26,7 @@ import 'package:intl/intl.dart';
|
||||
import 'package:wger/core/charts.dart';
|
||||
import 'package:wger/core/consts.dart';
|
||||
import 'package:wger/core/formatting/formatting.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
|
||||
class MeasurementOverallChangeWidget extends StatelessWidget {
|
||||
@@ -588,9 +589,14 @@ DateTime weekStart(DateTime date) =>
|
||||
/// through every single sample buries.
|
||||
///
|
||||
/// Series that already fit are returned unchanged.
|
||||
///
|
||||
/// The same ladder exists in SQL, in `MeasurementRepository.watchEntryBuckets`,
|
||||
/// which is where a category's own chart points come from. This one serves what
|
||||
/// reads entries instead: the distribution and the group components. The two
|
||||
/// must agree, or the same data draws differently depending on the path.
|
||||
List<MeasurementChartEntry> downsample(
|
||||
List<MeasurementChartEntry> entries, {
|
||||
int maxPoints = 200,
|
||||
int maxPoints = measurementChartMaxPoints,
|
||||
}) {
|
||||
if (entries.length <= maxPoints) {
|
||||
return entries;
|
||||
@@ -610,13 +616,20 @@ List<MeasurementChartEntry> downsample(
|
||||
/// Condenses one bucket into a single point: the mean value at the start of
|
||||
/// the bucket, spanning the values it stands for.
|
||||
MeasurementChartEntry _summarise(DateTime start, List<MeasurementChartEntry> bucket) {
|
||||
final value = bucket.map((e) => e.value).average;
|
||||
// An entry that already carries a range contributes its bounds, not just
|
||||
// its value, so re-condensing an aggregate keeps the true extremes
|
||||
final low = bucket.map((e) => e.min ?? e.value).min;
|
||||
final high = bucket.map((e) => e.max ?? e.value).max;
|
||||
// A lone reading in its bucket has no spread, and a zero-width band is a
|
||||
// line drawn twice
|
||||
final hasRange = low < value || high > value;
|
||||
|
||||
return MeasurementChartEntry(
|
||||
bucket.map((e) => e.value).average,
|
||||
value,
|
||||
start,
|
||||
// An entry that already carries a range contributes its bounds, not just
|
||||
// its value, so re-condensing an aggregate keeps the true extremes
|
||||
min: bucket.map((e) => e.min ?? e.value).min,
|
||||
max: bucket.map((e) => e.max ?? e.value).max,
|
||||
min: hasRange ? low : null,
|
||||
max: hasRange ? high : null,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:wger/core/form_screen.dart';
|
||||
import 'package:wger/core/formatting/formatting.dart';
|
||||
import 'package:wger/core/snackbar.dart';
|
||||
import 'package:wger/features/measurements/measurements.dart';
|
||||
import 'package:wger/core/widgets/error.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart';
|
||||
import 'package:wger/features/measurements/models/unit_conversion.dart';
|
||||
@@ -74,7 +74,6 @@ class EntriesList extends ConsumerWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final i18n = AppLocalizations.of(context);
|
||||
// The overrides describe a single category and only apply to the leaf
|
||||
// branch below; a group is presented through its components
|
||||
final name = title ?? category.displayName(context);
|
||||
@@ -101,22 +100,6 @@ class EntriesList extends ConsumerWidget {
|
||||
]
|
||||
: const <PlanPeriod>[];
|
||||
|
||||
// Values are read through the unit helper; for plain categories without
|
||||
// per-entry units this is a pass-through to the category unit
|
||||
final allEntries = chartEntriesFor(
|
||||
category.entries,
|
||||
targetUnit: unit,
|
||||
categoryUnit: category.unit,
|
||||
);
|
||||
// The average is computed over the full history and only then cut, so the
|
||||
// first points of the range average the days before it instead of starting
|
||||
// over at the cutoff
|
||||
final settings = category.chartSettings;
|
||||
final allAverage = movingAverage(allEntries, days: settings.averageWindow);
|
||||
final cutoff = range.cutoff;
|
||||
final entriesAll = cutoff == null ? allEntries : allEntries.whereDate(cutoff, null);
|
||||
final average = cutoff == null ? allAverage : allAverage.whereDate(cutoff, null);
|
||||
|
||||
final datetimeFormat = localizedDate(context);
|
||||
|
||||
return Column(
|
||||
@@ -125,17 +108,14 @@ class EntriesList extends ConsumerWidget {
|
||||
value: range,
|
||||
onChanged: onRangeChanged,
|
||||
),
|
||||
...getOverviewWidgetsSeries(
|
||||
name,
|
||||
entriesAll,
|
||||
average,
|
||||
planPeriods,
|
||||
unitLabel,
|
||||
context,
|
||||
metricType: category.metricType,
|
||||
mainChartTitle: range.chartTitle(i18n, name),
|
||||
chartType: category.chartType,
|
||||
settings: settings,
|
||||
MeasurementChartPoints(
|
||||
category: category,
|
||||
range: range,
|
||||
// Values are read through the unit helper; for plain categories
|
||||
// without per-entry units this is a pass-through
|
||||
targetUnit: unit,
|
||||
builder: (context, points) => _chart(context, points, name, unitLabel, planPeriods),
|
||||
onError: (_, error) => [StreamErrorIndicator(error.toString())],
|
||||
),
|
||||
SizedBox(
|
||||
height: 300,
|
||||
@@ -209,6 +189,32 @@ class EntriesList extends ConsumerWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// The chart, its overall change and the legend, over the range the points
|
||||
/// were read for.
|
||||
List<Widget> _chart(
|
||||
BuildContext context,
|
||||
List<MeasurementChartEntry> allPoints,
|
||||
String name,
|
||||
String unitLabel,
|
||||
List<PlanPeriod> planPeriods,
|
||||
) {
|
||||
final settings = category.chartSettings;
|
||||
final (:entries, :average) = chartSeriesFor(allPoints, range, settings);
|
||||
|
||||
return getOverviewWidgetsSeries(
|
||||
name,
|
||||
entries,
|
||||
average,
|
||||
planPeriods,
|
||||
unitLabel,
|
||||
context,
|
||||
metricType: category.metricType,
|
||||
mainChartTitle: range.chartTitle(AppLocalizations.of(context), name),
|
||||
chartType: category.chartType,
|
||||
settings: settings,
|
||||
);
|
||||
}
|
||||
|
||||
/// Detail view of a multi-value group: one chart over all components, a
|
||||
/// legend that doubles as the way into each component, and the readings
|
||||
/// themselves.
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:wger/core/widgets/progress_indicator.dart';
|
||||
import 'package:wger/features/measurements/measurements.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart';
|
||||
import 'package:wger/features/measurements/models/unit_conversion.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_notifier.dart';
|
||||
import 'package:wger/features/measurements/widgets/chart_range_selector.dart';
|
||||
import 'package:wger/features/measurements/widgets/charts.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
|
||||
@@ -204,6 +209,204 @@ List<MeasurementChartEntry> chartEntriesFor(
|
||||
);
|
||||
}).toList();
|
||||
|
||||
/// The point level a category's chart needs, null when it needs the entries
|
||||
/// themselves.
|
||||
///
|
||||
/// Two charts are built on a calendar unit and fix it: a heatmap draws days, a
|
||||
/// week-over-week chart weeks. A distribution bins the values, and binning
|
||||
/// condensed means would narrow the histogram, so it stays on raw entries.
|
||||
MeasurementBucketLevel? chartBucketLevel(MetricType metricType, ChartType chartType) =>
|
||||
switch (metricType.resolveChartType(chartType)) {
|
||||
ChartType.distribution => null,
|
||||
ChartType.heatmap => MeasurementBucketLevel.day,
|
||||
ChartType.delta => MeasurementBucketLevel.week,
|
||||
// The summed types are drawn as daily totals whatever the range
|
||||
_ => metricType.isSummedPerDay ? MeasurementBucketLevel.day : MeasurementBucketLevel.auto,
|
||||
};
|
||||
|
||||
/// The points the chart of [category] draws, over the range it is read for.
|
||||
///
|
||||
/// They reach back beyond the range, so the moving average derived from them
|
||||
/// does not start over at the cutoff. [targetUnit] overrides the category
|
||||
/// unit, for body weight, which is shown in the profile unit.
|
||||
AsyncValue<List<MeasurementChartEntry>> chartPointsFor(
|
||||
WidgetRef ref,
|
||||
MeasurementCategory category,
|
||||
ChartRange range, {
|
||||
String? targetUnit,
|
||||
}) {
|
||||
final unit = targetUnit ?? category.unit;
|
||||
final level = chartBucketLevel(category.metricType, category.chartType);
|
||||
|
||||
// The distribution and its fallback for a series too short to bin read the
|
||||
// entries the category was loaded with, which at that length is what a
|
||||
// bucket would hold anyway
|
||||
if (level == null) {
|
||||
return AsyncValue.data(
|
||||
chartEntriesFor(category.entries, targetUnit: unit, categoryUnit: category.unit),
|
||||
);
|
||||
}
|
||||
|
||||
return ref
|
||||
.watch(measurementChartBucketsProvider(category.id!, range.readCutoff, level))
|
||||
.whenData(
|
||||
(buckets) => chartEntriesForBuckets(
|
||||
buckets,
|
||||
targetUnit: unit,
|
||||
categoryUnit: category.unit,
|
||||
summed: category.metricType.isSummedPerDay,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Draws a category's chart from the aggregated query, keeping what it last
|
||||
/// drew while another range loads.
|
||||
///
|
||||
/// Picking a range watches a different provider, which starts out loading:
|
||||
/// without this the chart would blank for a frame, which is what the range
|
||||
/// switch used to look like.
|
||||
class MeasurementChartPoints extends ConsumerStatefulWidget {
|
||||
const MeasurementChartPoints({
|
||||
required this.category,
|
||||
required this.range,
|
||||
required this.builder,
|
||||
required this.onError,
|
||||
this.targetUnit,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final MeasurementCategory category;
|
||||
final ChartRange range;
|
||||
|
||||
/// Unit the values are converted to, the category's own by default.
|
||||
final String? targetUnit;
|
||||
|
||||
/// Draws the chart for the points that arrived.
|
||||
final List<Widget> Function(BuildContext context, List<MeasurementChartEntry> points) builder;
|
||||
|
||||
/// Drawn when nothing could be read and there is nothing to keep: a card
|
||||
/// leaves the space empty, a detail screen names the error.
|
||||
final List<Widget> Function(BuildContext context, Object error) onError;
|
||||
|
||||
@override
|
||||
ConsumerState<MeasurementChartPoints> createState() => _MeasurementChartPointsState();
|
||||
}
|
||||
|
||||
class _MeasurementChartPointsState extends ConsumerState<MeasurementChartPoints> {
|
||||
List<MeasurementChartEntry>? _last;
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant MeasurementChartPoints oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
// Another category in the same slot of a list has nothing to do with what
|
||||
// is on screen
|
||||
if (oldWidget.category.id != widget.category.id) {
|
||||
_last = null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final points = chartPointsFor(
|
||||
ref,
|
||||
widget.category,
|
||||
widget.range,
|
||||
targetUnit: widget.targetUnit,
|
||||
);
|
||||
if (points.hasValue) {
|
||||
_last = points.value;
|
||||
}
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: switch ((points, _last)) {
|
||||
(_, final List<MeasurementChartEntry> last) => widget.builder(context, last),
|
||||
(AsyncError(:final error), _) => widget.onError(context, error),
|
||||
_ => const [SizedBox(height: 220, child: BoxedProgressIndicator())],
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// What a chart draws over [range]: the points in it, and the moving average
|
||||
/// over them.
|
||||
///
|
||||
/// The average is computed over all of [points], which reach back beyond the
|
||||
/// range, and only then cut, so the first ones average the days before them
|
||||
/// instead of starting over at the cutoff.
|
||||
({List<MeasurementChartEntry> entries, List<MeasurementChartEntry> average}) chartSeriesFor(
|
||||
List<MeasurementChartEntry> points,
|
||||
ChartRange range,
|
||||
ChartSettings settings,
|
||||
) {
|
||||
final average = movingAverage(points, days: settings.averageWindow);
|
||||
final cutoff = range.cutoff;
|
||||
|
||||
return cutoff == null
|
||||
? (entries: points, average: average)
|
||||
: (entries: points.whereDate(cutoff, null), average: average.whereDate(cutoff, null));
|
||||
}
|
||||
|
||||
/// Turns SQL-condensed buckets into chart points, converting to [targetUnit].
|
||||
///
|
||||
/// The counterpart of [chartEntriesFor] for the aggregated read path. A bucket
|
||||
/// arrives once per unit its entries were written in, so the slices are
|
||||
/// converted before they are merged. Their spread becomes the point's range,
|
||||
/// left off where it says nothing (a single reading, a [summed] total).
|
||||
List<MeasurementChartEntry> chartEntriesForBuckets(
|
||||
List<MeasurementBucket> buckets, {
|
||||
required String targetUnit,
|
||||
required String categoryUnit,
|
||||
bool summed = false,
|
||||
}) {
|
||||
return [
|
||||
for (final MapEntry(key: start, value: slices) in groupBy(
|
||||
buckets,
|
||||
(MeasurementBucket b) => b.start,
|
||||
).entries)
|
||||
_mergeSlices(
|
||||
start,
|
||||
slices,
|
||||
targetUnit: targetUnit,
|
||||
categoryUnit: categoryUnit,
|
||||
summed: summed,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/// The one point the [slices] of a bucket stand for, each converted from the
|
||||
/// unit it was written in first.
|
||||
MeasurementChartEntry _mergeSlices(
|
||||
DateTime start,
|
||||
List<MeasurementBucket> slices, {
|
||||
required String targetUnit,
|
||||
required String categoryUnit,
|
||||
required bool summed,
|
||||
}) {
|
||||
double convert(num value, String? from) => convertWeight(
|
||||
value,
|
||||
from: from == null || from.isEmpty ? categoryUnit : from,
|
||||
to: targetUnit,
|
||||
);
|
||||
|
||||
final total = slices.map((s) => convert(s.sum, s.unit)).sum;
|
||||
if (summed) {
|
||||
return MeasurementChartEntry(total, start);
|
||||
}
|
||||
|
||||
final value = total / slices.map((s) => s.count).sum;
|
||||
final low = slices.map((s) => convert(s.min, s.unit)).min;
|
||||
final high = slices.map((s) => convert(s.max, s.unit)).max;
|
||||
final hasRange = low < value || high > value;
|
||||
|
||||
return MeasurementChartEntry(
|
||||
value,
|
||||
start,
|
||||
min: hasRange ? low : null,
|
||||
max: hasRange ? high : null,
|
||||
);
|
||||
}
|
||||
|
||||
/// The readings of a two-component group as ranges: one point per timestamp,
|
||||
/// spanning from the lower component to the upper one.
|
||||
///
|
||||
@@ -244,6 +447,9 @@ List<MeasurementChartEntry> groupRangeEntries(MeasurementCategory group, {DateTi
|
||||
/// All components share the same range, so their lines cover the same span
|
||||
/// even when one of them has fewer readings. Only readings from [cutoff] on
|
||||
/// are returned; null covers the full history.
|
||||
///
|
||||
/// Each component is condensed on its own, like every other dense series: a
|
||||
/// year of blood pressure readings drawn point by point is a picket fence.
|
||||
List<MeasurementChartSeries> groupComponentSeries(
|
||||
BuildContext context,
|
||||
MeasurementCategory group, {
|
||||
@@ -255,7 +461,7 @@ List<MeasurementChartSeries> groupComponentSeries(
|
||||
return group.children
|
||||
.map(
|
||||
(child) => MeasurementChartSeries(
|
||||
cutoff == null ? pointsOf(child) : pointsOf(child).whereDate(cutoff, null),
|
||||
downsample(cutoff == null ? pointsOf(child) : pointsOf(child).whereDate(cutoff, null)),
|
||||
MeasurementSeriesRole.component,
|
||||
label: child.displayName(context),
|
||||
),
|
||||
|
||||
@@ -8,10 +8,11 @@ import 'dart:async' as _i4;
|
||||
import 'package:health_bridge/health.dart' as _i5;
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:mockito/src/dummies.dart' as _i3;
|
||||
import 'package:wger/core/network/auth_credentials_storage.dart' as _i10;
|
||||
import 'package:wger/core/network/auth_state.dart' as _i11;
|
||||
import 'package:wger/core/network/auth_credentials_storage.dart' as _i11;
|
||||
import 'package:wger/core/network/auth_state.dart' as _i12;
|
||||
import 'package:wger/features/health/models/health_reading.dart' as _i6;
|
||||
import 'package:wger/features/health/providers/health_repository.dart' as _i2;
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart' as _i10;
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart' as _i8;
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart' as _i9;
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart' as _i7;
|
||||
@@ -179,6 +180,23 @@ class MockMeasurementRepository extends _i1.Mock implements _i7.MeasurementRepos
|
||||
)
|
||||
as _i4.Stream<Map<String, _i9.MeasurementEntry>>);
|
||||
|
||||
@override
|
||||
_i4.Stream<List<_i10.MeasurementBucket>> watchEntryBuckets(
|
||||
String? categoryId, {
|
||||
DateTime? since,
|
||||
_i10.MeasurementBucketLevel? level = _i10.MeasurementBucketLevel.auto,
|
||||
int? maxPoints = 200,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#watchEntryBuckets,
|
||||
[categoryId],
|
||||
{#since: since, #level: level, #maxPoints: maxPoints},
|
||||
),
|
||||
returnValue: _i4.Stream<List<_i10.MeasurementBucket>>.empty(),
|
||||
)
|
||||
as _i4.Stream<List<_i10.MeasurementBucket>>);
|
||||
|
||||
@override
|
||||
_i4.Future<List<_i8.MeasurementCategory>> getAllOnce() =>
|
||||
(super.noSuchMethod(
|
||||
@@ -269,22 +287,22 @@ class MockMeasurementRepository extends _i1.Mock implements _i7.MeasurementRepos
|
||||
/// A class which mocks [AuthCredentialsStorage].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockAuthCredentialsStorage extends _i1.Mock implements _i10.AuthCredentialsStorage {
|
||||
class MockAuthCredentialsStorage extends _i1.Mock implements _i11.AuthCredentialsStorage {
|
||||
MockAuthCredentialsStorage() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i4.Future<_i10.StoredAuth?> load() =>
|
||||
_i4.Future<_i11.StoredAuth?> load() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#load, []),
|
||||
returnValue: _i4.Future<_i10.StoredAuth?>.value(),
|
||||
returnValue: _i4.Future<_i11.StoredAuth?>.value(),
|
||||
)
|
||||
as _i4.Future<_i10.StoredAuth?>);
|
||||
as _i4.Future<_i11.StoredAuth?>);
|
||||
|
||||
@override
|
||||
_i4.Future<void> saveJwt({
|
||||
required _i11.JwtCredential? credential,
|
||||
required _i12.JwtCredential? credential,
|
||||
required String? serverUrl,
|
||||
String? refreshToken,
|
||||
}) =>
|
||||
@@ -301,7 +319,7 @@ class MockAuthCredentialsStorage extends _i1.Mock implements _i10.AuthCredential
|
||||
|
||||
@override
|
||||
_i4.Future<void> updateJwt({
|
||||
required _i11.JwtCredential? credential,
|
||||
required _i12.JwtCredential? credential,
|
||||
String? refreshToken,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import 'dart:async' as _i3;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart' as _i6;
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart' as _i4;
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart' as _i5;
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart' as _i2;
|
||||
@@ -78,6 +79,23 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
)
|
||||
as _i3.Stream<Map<String, _i5.MeasurementEntry>>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i6.MeasurementBucket>> watchEntryBuckets(
|
||||
String? categoryId, {
|
||||
DateTime? since,
|
||||
_i6.MeasurementBucketLevel? level = _i6.MeasurementBucketLevel.auto,
|
||||
int? maxPoints = 200,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#watchEntryBuckets,
|
||||
[categoryId],
|
||||
{#since: since, #level: level, #maxPoints: maxPoints},
|
||||
),
|
||||
returnValue: _i3.Stream<List<_i6.MeasurementBucket>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i6.MeasurementBucket>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i4.MeasurementCategory>> getAllOnce() =>
|
||||
(super.noSuchMethod(
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
import 'dart:async' as _i3;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/core/network/auth_credentials_storage.dart' as _i6;
|
||||
import 'package:wger/core/network/auth_state.dart' as _i7;
|
||||
import 'package:wger/core/network/auth_credentials_storage.dart' as _i7;
|
||||
import 'package:wger/core/network/auth_state.dart' as _i8;
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart' as _i6;
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart' as _i4;
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart' as _i5;
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart' as _i2;
|
||||
@@ -80,6 +81,23 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
)
|
||||
as _i3.Stream<Map<String, _i5.MeasurementEntry>>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i6.MeasurementBucket>> watchEntryBuckets(
|
||||
String? categoryId, {
|
||||
DateTime? since,
|
||||
_i6.MeasurementBucketLevel? level = _i6.MeasurementBucketLevel.auto,
|
||||
int? maxPoints = 200,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#watchEntryBuckets,
|
||||
[categoryId],
|
||||
{#since: since, #level: level, #maxPoints: maxPoints},
|
||||
),
|
||||
returnValue: _i3.Stream<List<_i6.MeasurementBucket>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i6.MeasurementBucket>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i4.MeasurementCategory>> getAllOnce() =>
|
||||
(super.noSuchMethod(
|
||||
@@ -170,22 +188,22 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
/// A class which mocks [AuthCredentialsStorage].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockAuthCredentialsStorage extends _i1.Mock implements _i6.AuthCredentialsStorage {
|
||||
class MockAuthCredentialsStorage extends _i1.Mock implements _i7.AuthCredentialsStorage {
|
||||
MockAuthCredentialsStorage() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i3.Future<_i6.StoredAuth?> load() =>
|
||||
_i3.Future<_i7.StoredAuth?> load() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#load, []),
|
||||
returnValue: _i3.Future<_i6.StoredAuth?>.value(),
|
||||
returnValue: _i3.Future<_i7.StoredAuth?>.value(),
|
||||
)
|
||||
as _i3.Future<_i6.StoredAuth?>);
|
||||
as _i3.Future<_i7.StoredAuth?>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> saveJwt({
|
||||
required _i7.JwtCredential? credential,
|
||||
required _i8.JwtCredential? credential,
|
||||
required String? serverUrl,
|
||||
String? refreshToken,
|
||||
}) =>
|
||||
@@ -202,7 +220,7 @@ class MockAuthCredentialsStorage extends _i1.Mock implements _i6.AuthCredentials
|
||||
|
||||
@override
|
||||
_i3.Future<void> updateJwt({
|
||||
required _i7.JwtCredential? credential,
|
||||
required _i8.JwtCredential? credential,
|
||||
String? refreshToken,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
|
||||
@@ -20,6 +20,7 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:wger/database/powersync/database.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart';
|
||||
@@ -152,6 +153,33 @@ void main() {
|
||||
|
||||
await iter.cancel();
|
||||
});
|
||||
|
||||
test('coalesces a burst of writes into one emission', () async {
|
||||
// What an import looks like from here: a Drift stream fires per write, and
|
||||
// rebuilding every category from the join on each of them is the cost
|
||||
await db
|
||||
.into(db.measurementCategoryTable)
|
||||
.insert(MeasurementCategory(id: '1', name: 'Body fat', unit: '%').toCompanion());
|
||||
|
||||
final emissions = <List<MeasurementCategory>>[];
|
||||
final sub = repo.watchAll().listen(emissions.add);
|
||||
|
||||
// The leading emission is not held back: a screen waits for it
|
||||
await Future<void>.delayed(const Duration(milliseconds: 50));
|
||||
expect(emissions, hasLength(1));
|
||||
|
||||
for (var day = 1; day <= 5; day++) {
|
||||
await repo.addLocalDrift(
|
||||
MeasurementEntry(categoryId: '1', date: DateTime.utc(2026, 1, day), value: 20, notes: ''),
|
||||
);
|
||||
}
|
||||
await Future<void>.delayed(const Duration(milliseconds: 400));
|
||||
|
||||
expect(emissions.length, lessThanOrEqualTo(2));
|
||||
expect(emissions.last.single.entries, hasLength(5));
|
||||
|
||||
await sub.cancel();
|
||||
});
|
||||
});
|
||||
|
||||
group('watchLatestEntries', () {
|
||||
@@ -221,6 +249,178 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
group('watchEntryBuckets', () {
|
||||
/// Local dates throughout: the query buckets in the local zone, so UTC
|
||||
/// fixtures would put a reading in a different day on every machine.
|
||||
Future<void> seedEntries(
|
||||
List<(DateTime, num)> readings, {
|
||||
Map<String, dynamic>? extraData,
|
||||
}) async {
|
||||
await db
|
||||
.into(db.measurementCategoryTable)
|
||||
.insert(MeasurementCategory(id: '1', name: 'Heart rate', unit: 'bpm').toCompanion());
|
||||
for (final (index, (date, value)) in readings.indexed) {
|
||||
await db
|
||||
.into(db.measurementEntryTable)
|
||||
.insert(
|
||||
MeasurementEntry(
|
||||
id: 'e$index',
|
||||
categoryId: '1',
|
||||
date: date,
|
||||
value: value,
|
||||
notes: '',
|
||||
extraData: extraData,
|
||||
).toCompanion(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
test('a series that fits keeps one bucket per entry', () async {
|
||||
await seedEntries([
|
||||
(DateTime(2026, 5, 4, 8, 30), 60),
|
||||
(DateTime(2026, 5, 4, 20, 15), 70),
|
||||
]);
|
||||
|
||||
final buckets = await repo.watchEntryBuckets('1').first;
|
||||
|
||||
expect(buckets.map((b) => b.start), [
|
||||
DateTime(2026, 5, 4, 8, 30),
|
||||
DateTime(2026, 5, 4, 20, 15),
|
||||
]);
|
||||
expect(buckets.map((b) => b.count), [1, 1]);
|
||||
expect(buckets.map((b) => b.sum), [60, 70]);
|
||||
});
|
||||
|
||||
test('condenses to the finest calendar unit that fits', () async {
|
||||
// Two readings a day over four days: entry level would be eight points,
|
||||
// the hour level still eight, so the day is the first one under the limit
|
||||
await seedEntries([
|
||||
for (var day = 4; day <= 7; day++) ...[
|
||||
(DateTime(2026, 5, day, 8, 0), 60),
|
||||
(DateTime(2026, 5, day, 20, 0), 80),
|
||||
],
|
||||
]);
|
||||
|
||||
final buckets = await repo.watchEntryBuckets('1', maxPoints: 5).first;
|
||||
|
||||
expect(buckets, hasLength(4));
|
||||
expect(buckets.first.start, DateTime(2026, 5, 4));
|
||||
expect(buckets.first.count, 2);
|
||||
expect(buckets.first.sum, 140);
|
||||
expect(buckets.first.min, 60);
|
||||
expect(buckets.first.max, 80);
|
||||
});
|
||||
|
||||
test('a week bucket starts on the Monday of the reading', () async {
|
||||
// 2026-05-04 is a Monday, 2026-05-10 the Sunday closing that week
|
||||
await seedEntries([
|
||||
(DateTime(2026, 5, 4, 12), 60),
|
||||
(DateTime(2026, 5, 10, 12), 80),
|
||||
]);
|
||||
|
||||
final buckets = await repo.watchEntryBuckets('1', level: MeasurementBucketLevel.week).first;
|
||||
|
||||
expect(buckets.single.start, DateTime(2026, 5, 4));
|
||||
expect(buckets.single.count, 2);
|
||||
});
|
||||
|
||||
test('a day bucket is a calendar day whatever the point count', () async {
|
||||
await seedEntries([
|
||||
(DateTime(2026, 5, 4, 23, 30), 60),
|
||||
(DateTime(2026, 5, 5, 0, 30), 80),
|
||||
]);
|
||||
|
||||
final buckets = await repo.watchEntryBuckets('1', level: MeasurementBucketLevel.day).first;
|
||||
|
||||
expect(buckets.map((b) => b.start), [DateTime(2026, 5, 4), DateTime(2026, 5, 5)]);
|
||||
});
|
||||
|
||||
test('an aggregate entry contributes its stored bounds, not its value', () async {
|
||||
// What the health sync writes for heart rate: one row a day, holding the
|
||||
// day's average with the range it summarises
|
||||
await seedEntries(
|
||||
[(DateTime(2026, 5, 4, 12), 70)],
|
||||
extraData: {'min': 48, 'max': 165},
|
||||
);
|
||||
|
||||
final buckets = await repo.watchEntryBuckets('1', level: MeasurementBucketLevel.day).first;
|
||||
|
||||
expect(buckets.single.min, 48);
|
||||
expect(buckets.single.max, 165);
|
||||
expect(buckets.single.sum, 70);
|
||||
});
|
||||
|
||||
test('mixed units are kept apart', () async {
|
||||
// A category holding kg and lb entries: one mean over both would be a
|
||||
// number in neither, so the slices come back separately
|
||||
await db
|
||||
.into(db.measurementCategoryTable)
|
||||
.insert(MeasurementCategory(id: '1', name: 'Weight', unit: 'kg').toCompanion());
|
||||
for (final (index, (value, unit)) in [(80, 'kg'), (180, 'lb')].indexed) {
|
||||
await db
|
||||
.into(db.measurementEntryTable)
|
||||
.insert(
|
||||
MeasurementEntry(
|
||||
id: 'e$index',
|
||||
categoryId: '1',
|
||||
date: DateTime(2026, 5, 4, 8 + index),
|
||||
value: value,
|
||||
notes: '',
|
||||
extraData: {'unit': unit},
|
||||
).toCompanion(),
|
||||
);
|
||||
}
|
||||
|
||||
final buckets = await repo.watchEntryBuckets('1', level: MeasurementBucketLevel.day).first;
|
||||
|
||||
expect(buckets, hasLength(2));
|
||||
expect(buckets.map((b) => b.start).toSet(), {DateTime(2026, 5, 4)});
|
||||
expect(buckets.map((b) => b.unit), ['kg', 'lb']);
|
||||
expect(buckets.map((b) => b.sum), [80, 180]);
|
||||
});
|
||||
|
||||
test('since bounds the entries read', () async {
|
||||
await seedEntries([
|
||||
(DateTime(2026, 1, 1, 12), 60),
|
||||
(DateTime(2026, 5, 4, 12), 80),
|
||||
]);
|
||||
|
||||
final buckets = await repo.watchEntryBuckets('1', since: DateTime(2026, 3, 1)).first;
|
||||
|
||||
expect(buckets.map((b) => b.sum), [80]);
|
||||
});
|
||||
|
||||
test('only the requested category is read', () async {
|
||||
await seedEntries([(DateTime(2026, 5, 4, 12), 60)]);
|
||||
await db
|
||||
.into(db.measurementCategoryTable)
|
||||
.insert(MeasurementCategory(id: '2', name: 'Other', unit: 'cm').toCompanion());
|
||||
await repo.addLocalDrift(
|
||||
MeasurementEntry(categoryId: '2', date: DateTime(2026, 5, 4, 13), value: 99, notes: ''),
|
||||
);
|
||||
|
||||
final buckets = await repo.watchEntryBuckets('1').first;
|
||||
|
||||
expect(buckets.map((b) => b.sum), [60]);
|
||||
});
|
||||
|
||||
test('re-emits when an entry is added', () async {
|
||||
await seedEntries([(DateTime(2026, 5, 4, 12), 60)]);
|
||||
final iter = StreamIterator(repo.watchEntryBuckets('1'));
|
||||
|
||||
await iter.moveNext();
|
||||
expect(iter.current, hasLength(1));
|
||||
|
||||
await repo.addLocalDrift(
|
||||
MeasurementEntry(categoryId: '1', date: DateTime(2026, 5, 5, 12), value: 80, notes: ''),
|
||||
);
|
||||
|
||||
await iter.moveNext();
|
||||
expect(iter.current, hasLength(2));
|
||||
await iter.cancel();
|
||||
});
|
||||
});
|
||||
|
||||
group('watchLocalDriftCategoryById', () {
|
||||
test('returns the matching category', () async {
|
||||
await seedCategoriesAndEntries();
|
||||
|
||||
@@ -22,30 +22,31 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_notifier.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart';
|
||||
import 'package:wger/features/measurements/screens/measurement_categories_screen.dart';
|
||||
import 'package:wger/features/measurements/widgets/charts.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
|
||||
import '../../../../test_data/measurements.dart';
|
||||
import '../../../helpers/measurement_chart_buckets.dart';
|
||||
import 'measurement_categories_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([MeasurementRepository])
|
||||
void main() {
|
||||
Widget createMeasurementScreen({locale = 'en'}) {
|
||||
final categories = [...getMeasurementCategories(), ...getBloodPressureGroup()];
|
||||
final mockRepo = MockMeasurementRepository();
|
||||
when(
|
||||
mockRepo.watchAll(entriesSince: anyNamed('entriesSince')),
|
||||
).thenAnswer(
|
||||
(_) => Stream<List<MeasurementCategory>>.value([
|
||||
...getMeasurementCategories(),
|
||||
...getBloodPressureGroup(),
|
||||
]),
|
||||
);
|
||||
).thenAnswer((_) => Stream<List<MeasurementCategory>>.value(categories));
|
||||
|
||||
return ProviderScope(
|
||||
overrides: [
|
||||
measurementRepositoryProvider.overrideWithValue(mockRepo),
|
||||
// The charts read their points from the aggregated query, not from
|
||||
// the entries the categories carry
|
||||
measurementChartBucketsProvider.overrideWith(chartBucketsFrom(categories)),
|
||||
],
|
||||
child: MaterialApp(
|
||||
locale: Locale(locale),
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import 'dart:async' as _i3;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart' as _i6;
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart' as _i4;
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart' as _i5;
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart' as _i2;
|
||||
@@ -78,6 +79,23 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
)
|
||||
as _i3.Stream<Map<String, _i5.MeasurementEntry>>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i6.MeasurementBucket>> watchEntryBuckets(
|
||||
String? categoryId, {
|
||||
DateTime? since,
|
||||
_i6.MeasurementBucketLevel? level = _i6.MeasurementBucketLevel.auto,
|
||||
int? maxPoints = 200,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#watchEntryBuckets,
|
||||
[categoryId],
|
||||
{#since: since, #level: level, #maxPoints: maxPoints},
|
||||
),
|
||||
returnValue: _i3.Stream<List<_i6.MeasurementBucket>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i6.MeasurementBucket>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i4.MeasurementCategory>> getAllOnce() =>
|
||||
(super.noSuchMethod(
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import 'dart:async' as _i3;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart' as _i6;
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart' as _i4;
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart' as _i5;
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart' as _i2;
|
||||
@@ -78,6 +79,23 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
)
|
||||
as _i3.Stream<Map<String, _i5.MeasurementEntry>>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i6.MeasurementBucket>> watchEntryBuckets(
|
||||
String? categoryId, {
|
||||
DateTime? since,
|
||||
_i6.MeasurementBucketLevel? level = _i6.MeasurementBucketLevel.auto,
|
||||
int? maxPoints = 200,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#watchEntryBuckets,
|
||||
[categoryId],
|
||||
{#since: since, #level: level, #maxPoints: maxPoints},
|
||||
),
|
||||
returnValue: _i3.Stream<List<_i6.MeasurementBucket>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i6.MeasurementBucket>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i4.MeasurementCategory>> getAllOnce() =>
|
||||
(super.noSuchMethod(
|
||||
|
||||
@@ -22,13 +22,16 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_notifier.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart';
|
||||
import 'package:wger/features/measurements/screens/measurement_entries_screen.dart';
|
||||
import 'package:wger/features/measurements/widgets/charts.dart';
|
||||
import 'package:wger/features/nutrition/providers/ingredient_repository.dart';
|
||||
import 'package:wger/features/nutrition/providers/nutrition_repository.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
|
||||
import '../../../../test_data/measurements.dart';
|
||||
import '../../../helpers/measurement_chart_buckets.dart';
|
||||
import 'measurement_entries_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([MeasurementRepository, NutritionRepository, IngredientRepository])
|
||||
@@ -37,6 +40,18 @@ void main() {
|
||||
late MockNutritionRepository mockNutritionRepo;
|
||||
late MockIngredientRepository mockIngredientRepo;
|
||||
|
||||
/// The fixture with its entries moved into the last few days, for the tests
|
||||
/// that need a chart in every range rather than only in the full history
|
||||
MeasurementCategory recentCategory() {
|
||||
final category = getMeasurementCategories()[0];
|
||||
return category.copyWith(
|
||||
entries: [
|
||||
for (final (index, entry) in category.entries.indexed)
|
||||
entry.copyWith(date: DateTime.now().subtract(Duration(days: index))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
setUp(() {
|
||||
mockMeasurementRepo = MockMeasurementRepository();
|
||||
when(
|
||||
@@ -48,12 +63,25 @@ void main() {
|
||||
when(mockIngredientRepo.getById(any)).thenAnswer((_) async => null);
|
||||
});
|
||||
|
||||
Widget createEntriesScreen({locale = 'en'}) {
|
||||
Widget createEntriesScreen({locale = 'en', MeasurementCategory? category}) {
|
||||
final key = GlobalKey<NavigatorState>();
|
||||
if (category != null) {
|
||||
when(
|
||||
mockMeasurementRepo.watchLocalDriftCategoryById(
|
||||
any,
|
||||
entriesSince: anyNamed('entriesSince'),
|
||||
),
|
||||
).thenAnswer((_) => Stream<MeasurementCategory>.value(category));
|
||||
}
|
||||
|
||||
return ProviderScope(
|
||||
overrides: [
|
||||
measurementRepositoryProvider.overrideWithValue(mockMeasurementRepo),
|
||||
// The chart reads its points from the aggregated query, not from the
|
||||
// entries the category carries
|
||||
measurementChartBucketsProvider.overrideWith(
|
||||
chartBucketsFrom([category ?? getMeasurementCategories()[0]]),
|
||||
),
|
||||
nutritionRepositoryProvider.overrideWithValue(mockNutritionRepo),
|
||||
ingredientRepositoryProvider.overrideWithValue(mockIngredientRepo),
|
||||
],
|
||||
@@ -88,18 +116,22 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('switching the range keeps the screen it already drew', (tester) async {
|
||||
await tester.pumpWidget(createEntriesScreen());
|
||||
// Entries in every range, so the switch is between two ranges that both
|
||||
// have something to draw
|
||||
await tester.pumpWidget(createEntriesScreen(category: recentCategory()));
|
||||
await tester.tap(find.byType(TextButton));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(MeasurementChartWidgetFl), findsOneWidget);
|
||||
|
||||
// The new range watches a different provider, which starts out loading:
|
||||
// The new range watches different providers, both starting out loading:
|
||||
// this is the frame in which the screen used to drop everything it had
|
||||
await tester.tap(find.text('1 month'));
|
||||
await tester.ensureVisible(find.text('1 year'));
|
||||
await tester.tap(find.text('1 year'));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Body fat'), findsOneWidget);
|
||||
expect(find.text('30 %'), findsNWidgets(1));
|
||||
expect(find.byType(CircularProgressIndicator), findsNothing);
|
||||
expect(find.byType(MeasurementChartWidgetFl), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Tests the localization of dates - EN', (WidgetTester tester) async {
|
||||
|
||||
@@ -6,18 +6,19 @@
|
||||
import 'dart:async' as _i3;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/core/search_options.dart' as _i14;
|
||||
import 'package:wger/core/search_options.dart' as _i15;
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart' as _i6;
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart' as _i4;
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart' as _i5;
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart' as _i2;
|
||||
import 'package:wger/features/nutrition/models/ingredient.dart' as _i12;
|
||||
import 'package:wger/features/nutrition/models/ingredient_filters.dart' as _i13;
|
||||
import 'package:wger/features/nutrition/models/log.dart' as _i10;
|
||||
import 'package:wger/features/nutrition/models/meal.dart' as _i8;
|
||||
import 'package:wger/features/nutrition/models/meal_item.dart' as _i9;
|
||||
import 'package:wger/features/nutrition/models/nutritional_plan.dart' as _i7;
|
||||
import 'package:wger/features/nutrition/providers/ingredient_repository.dart' as _i11;
|
||||
import 'package:wger/features/nutrition/providers/nutrition_repository.dart' as _i6;
|
||||
import 'package:wger/features/nutrition/models/ingredient.dart' as _i13;
|
||||
import 'package:wger/features/nutrition/models/ingredient_filters.dart' as _i14;
|
||||
import 'package:wger/features/nutrition/models/log.dart' as _i11;
|
||||
import 'package:wger/features/nutrition/models/meal.dart' as _i9;
|
||||
import 'package:wger/features/nutrition/models/meal_item.dart' as _i10;
|
||||
import 'package:wger/features/nutrition/models/nutritional_plan.dart' as _i8;
|
||||
import 'package:wger/features/nutrition/providers/ingredient_repository.dart' as _i12;
|
||||
import 'package:wger/features/nutrition/providers/nutrition_repository.dart' as _i7;
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: avoid_redundant_argument_values
|
||||
@@ -87,6 +88,23 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
)
|
||||
as _i3.Stream<Map<String, _i5.MeasurementEntry>>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i6.MeasurementBucket>> watchEntryBuckets(
|
||||
String? categoryId, {
|
||||
DateTime? since,
|
||||
_i6.MeasurementBucketLevel? level = _i6.MeasurementBucketLevel.auto,
|
||||
int? maxPoints = 200,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#watchEntryBuckets,
|
||||
[categoryId],
|
||||
{#since: since, #level: level, #maxPoints: maxPoints},
|
||||
),
|
||||
returnValue: _i3.Stream<List<_i6.MeasurementBucket>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i6.MeasurementBucket>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i4.MeasurementCategory>> getAllOnce() =>
|
||||
(super.noSuchMethod(
|
||||
@@ -177,21 +195,21 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
/// A class which mocks [NutritionRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockNutritionRepository extends _i1.Mock implements _i6.NutritionRepository {
|
||||
class MockNutritionRepository extends _i1.Mock implements _i7.NutritionRepository {
|
||||
MockNutritionRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i7.NutritionalPlan>> watchAllDrift() =>
|
||||
_i3.Stream<List<_i8.NutritionalPlan>> watchAllDrift() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchAllDrift, []),
|
||||
returnValue: _i3.Stream<List<_i7.NutritionalPlan>>.empty(),
|
||||
returnValue: _i3.Stream<List<_i8.NutritionalPlan>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i7.NutritionalPlan>>);
|
||||
as _i3.Stream<List<_i8.NutritionalPlan>>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> addPlanLocalDrift(_i7.NutritionalPlan? plan) =>
|
||||
_i3.Future<void> addPlanLocalDrift(_i8.NutritionalPlan? plan) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#addPlanLocalDrift, [plan]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -200,7 +218,7 @@ class MockNutritionRepository extends _i1.Mock implements _i6.NutritionRepositor
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> editLocalDrift(_i7.NutritionalPlan? plan) =>
|
||||
_i3.Future<void> editLocalDrift(_i8.NutritionalPlan? plan) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#editLocalDrift, [plan]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -218,15 +236,15 @@ class MockNutritionRepository extends _i1.Mock implements _i6.NutritionRepositor
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i8.Meal>> watchAllMealsHydrated() =>
|
||||
_i3.Stream<List<_i9.Meal>> watchAllMealsHydrated() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchAllMealsHydrated, []),
|
||||
returnValue: _i3.Stream<List<_i8.Meal>>.empty(),
|
||||
returnValue: _i3.Stream<List<_i9.Meal>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i8.Meal>>);
|
||||
as _i3.Stream<List<_i9.Meal>>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> addMealLocalDrift(_i8.Meal? meal) =>
|
||||
_i3.Future<void> addMealLocalDrift(_i9.Meal? meal) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#addMealLocalDrift, [meal]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -235,7 +253,7 @@ class MockNutritionRepository extends _i1.Mock implements _i6.NutritionRepositor
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> editMealLocalDrift(_i8.Meal? meal) =>
|
||||
_i3.Future<void> editMealLocalDrift(_i9.Meal? meal) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#editMealLocalDrift, [meal]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -253,7 +271,7 @@ class MockNutritionRepository extends _i1.Mock implements _i6.NutritionRepositor
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> addMealItemLocalDrift(_i9.MealItem? item) =>
|
||||
_i3.Future<void> addMealItemLocalDrift(_i10.MealItem? item) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#addMealItemLocalDrift, [item]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -262,7 +280,7 @@ class MockNutritionRepository extends _i1.Mock implements _i6.NutritionRepositor
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> editMealItemLocalDrift(_i9.MealItem? item) =>
|
||||
_i3.Future<void> editMealItemLocalDrift(_i10.MealItem? item) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#editMealItemLocalDrift, [item]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -280,15 +298,15 @@ class MockNutritionRepository extends _i1.Mock implements _i6.NutritionRepositor
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i10.LogItem>> watchAllLogsHydrated() =>
|
||||
_i3.Stream<List<_i11.LogItem>> watchAllLogsHydrated() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchAllLogsHydrated, []),
|
||||
returnValue: _i3.Stream<List<_i10.LogItem>>.empty(),
|
||||
returnValue: _i3.Stream<List<_i11.LogItem>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i10.LogItem>>);
|
||||
as _i3.Stream<List<_i11.LogItem>>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> addLogLocalDrift(_i10.LogItem? log) =>
|
||||
_i3.Future<void> addLogLocalDrift(_i11.LogItem? log) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#addLogLocalDrift, [log]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -309,43 +327,43 @@ class MockNutritionRepository extends _i1.Mock implements _i6.NutritionRepositor
|
||||
/// A class which mocks [IngredientRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockIngredientRepository extends _i1.Mock implements _i11.IngredientRepository {
|
||||
class MockIngredientRepository extends _i1.Mock implements _i12.IngredientRepository {
|
||||
MockIngredientRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i3.Stream<_i12.Ingredient?> watchById(int? id) =>
|
||||
_i3.Stream<_i13.Ingredient?> watchById(int? id) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchById, [id]),
|
||||
returnValue: _i3.Stream<_i12.Ingredient?>.empty(),
|
||||
returnValue: _i3.Stream<_i13.Ingredient?>.empty(),
|
||||
)
|
||||
as _i3.Stream<_i12.Ingredient?>);
|
||||
as _i3.Stream<_i13.Ingredient?>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i12.Ingredient>> watchAllDrift({
|
||||
_i13.IngredientFilters? filters = const _i13.IngredientFilters(),
|
||||
_i3.Stream<List<_i13.Ingredient>> watchAllDrift({
|
||||
_i14.IngredientFilters? filters = const _i14.IngredientFilters(),
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchAllDrift, [], {#filters: filters}),
|
||||
returnValue: _i3.Stream<List<_i12.Ingredient>>.empty(),
|
||||
returnValue: _i3.Stream<List<_i13.Ingredient>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i12.Ingredient>>);
|
||||
as _i3.Stream<List<_i13.Ingredient>>);
|
||||
|
||||
@override
|
||||
_i3.Future<_i12.Ingredient?> getById(int? id) =>
|
||||
_i3.Future<_i13.Ingredient?> getById(int? id) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#getById, [id]),
|
||||
returnValue: _i3.Future<_i12.Ingredient?>.value(),
|
||||
returnValue: _i3.Future<_i13.Ingredient?>.value(),
|
||||
)
|
||||
as _i3.Future<_i12.Ingredient?>);
|
||||
as _i3.Future<_i13.Ingredient?>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i12.Ingredient>> searchIngredientLocal(
|
||||
_i3.Future<List<_i13.Ingredient>> searchIngredientLocal(
|
||||
String? term, {
|
||||
bool? isVegan = false,
|
||||
bool? isVegetarian = false,
|
||||
_i12.NutriScore? nutriscoreMax,
|
||||
_i13.NutriScore? nutriscoreMax,
|
||||
int? limit = 100,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
@@ -359,20 +377,20 @@ class MockIngredientRepository extends _i1.Mock implements _i11.IngredientReposi
|
||||
#limit: limit,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<List<_i12.Ingredient>>.value(
|
||||
<_i12.Ingredient>[],
|
||||
returnValue: _i3.Future<List<_i13.Ingredient>>.value(
|
||||
<_i13.Ingredient>[],
|
||||
),
|
||||
)
|
||||
as _i3.Future<List<_i12.Ingredient>>);
|
||||
as _i3.Future<List<_i13.Ingredient>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i12.Ingredient>> searchIngredientServer(
|
||||
_i3.Future<List<_i13.Ingredient>> searchIngredientServer(
|
||||
String? name, {
|
||||
String? languageCode = 'en',
|
||||
_i14.SearchLanguage? searchLanguage = _i14.SearchLanguage.current,
|
||||
_i15.SearchLanguage? searchLanguage = _i15.SearchLanguage.current,
|
||||
bool? isVegan = false,
|
||||
bool? isVegetarian = false,
|
||||
_i12.NutriScore? nutriscoreMax,
|
||||
_i13.NutriScore? nutriscoreMax,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
@@ -386,21 +404,21 @@ class MockIngredientRepository extends _i1.Mock implements _i11.IngredientReposi
|
||||
#nutriscoreMax: nutriscoreMax,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<List<_i12.Ingredient>>.value(
|
||||
<_i12.Ingredient>[],
|
||||
returnValue: _i3.Future<List<_i13.Ingredient>>.value(
|
||||
<_i13.Ingredient>[],
|
||||
),
|
||||
)
|
||||
as _i3.Future<List<_i12.Ingredient>>);
|
||||
as _i3.Future<List<_i13.Ingredient>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i12.Ingredient>> search(
|
||||
_i3.Future<List<_i13.Ingredient>> search(
|
||||
String? name, {
|
||||
required bool? isOnline,
|
||||
String? languageCode = 'en',
|
||||
_i14.SearchLanguage? searchLanguage = _i14.SearchLanguage.current,
|
||||
_i15.SearchLanguage? searchLanguage = _i15.SearchLanguage.current,
|
||||
bool? isVegan = false,
|
||||
bool? isVegetarian = false,
|
||||
_i12.NutriScore? nutriscoreMax,
|
||||
_i13.NutriScore? nutriscoreMax,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
@@ -415,17 +433,17 @@ class MockIngredientRepository extends _i1.Mock implements _i11.IngredientReposi
|
||||
#nutriscoreMax: nutriscoreMax,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<List<_i12.Ingredient>>.value(
|
||||
<_i12.Ingredient>[],
|
||||
returnValue: _i3.Future<List<_i13.Ingredient>>.value(
|
||||
<_i13.Ingredient>[],
|
||||
),
|
||||
)
|
||||
as _i3.Future<List<_i12.Ingredient>>);
|
||||
as _i3.Future<List<_i13.Ingredient>>);
|
||||
|
||||
@override
|
||||
_i3.Future<_i12.Ingredient?> searchIngredientByBarcode(String? barcode) =>
|
||||
_i3.Future<_i13.Ingredient?> searchIngredientByBarcode(String? barcode) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#searchIngredientByBarcode, [barcode]),
|
||||
returnValue: _i3.Future<_i12.Ingredient?>.value(),
|
||||
returnValue: _i3.Future<_i13.Ingredient?>.value(),
|
||||
)
|
||||
as _i3.Future<_i12.Ingredient?>);
|
||||
as _i3.Future<_i13.Ingredient?>);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import 'package:mockito/mockito.dart';
|
||||
import 'package:wger/core/form_screen.dart';
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_notifier.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart';
|
||||
import 'package:wger/features/measurements/screens/weight_screen.dart';
|
||||
import 'package:wger/features/measurements/widgets/chart_range_selector.dart';
|
||||
@@ -35,6 +36,7 @@ import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
|
||||
import '../../../../test_data/body_weight.dart';
|
||||
import '../../../../test_data/profile.dart';
|
||||
import '../../../helpers/measurement_chart_buckets.dart';
|
||||
import 'weight_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([
|
||||
@@ -77,6 +79,11 @@ void main() {
|
||||
return ProviderScope(
|
||||
overrides: [
|
||||
measurementRepositoryProvider.overrideWithValue(mockMeasurementRepository),
|
||||
// The chart reads its points from the aggregated query, not from the
|
||||
// entries the category carries
|
||||
measurementChartBucketsProvider.overrideWith(
|
||||
chartBucketsFrom([getBodyWeightCategory()]),
|
||||
),
|
||||
userProfileRepositoryProvider.overrideWithValue(mockUserProfileRepository),
|
||||
nutritionRepositoryProvider.overrideWithValue(mockNutritionRepo),
|
||||
ingredientRepositoryProvider.overrideWithValue(mockIngredientRepo),
|
||||
|
||||
@@ -7,8 +7,9 @@ import 'dart:async' as _i3;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/core/search_options.dart' as _i11;
|
||||
import 'package:wger/features/account/models/user_profile.dart' as _i16;
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart' as _i15;
|
||||
import 'package:wger/features/account/models/user_profile.dart' as _i17;
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart' as _i16;
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart' as _i15;
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart' as _i13;
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart' as _i14;
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart' as _i12;
|
||||
@@ -345,6 +346,23 @@ class MockMeasurementRepository extends _i1.Mock implements _i12.MeasurementRepo
|
||||
)
|
||||
as _i3.Stream<Map<String, _i14.MeasurementEntry>>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i15.MeasurementBucket>> watchEntryBuckets(
|
||||
String? categoryId, {
|
||||
DateTime? since,
|
||||
_i15.MeasurementBucketLevel? level = _i15.MeasurementBucketLevel.auto,
|
||||
int? maxPoints = 200,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#watchEntryBuckets,
|
||||
[categoryId],
|
||||
{#since: since, #level: level, #maxPoints: maxPoints},
|
||||
),
|
||||
returnValue: _i3.Stream<List<_i15.MeasurementBucket>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i15.MeasurementBucket>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i13.MeasurementCategory>> getAllOnce() =>
|
||||
(super.noSuchMethod(
|
||||
@@ -435,21 +453,21 @@ class MockMeasurementRepository extends _i1.Mock implements _i12.MeasurementRepo
|
||||
/// A class which mocks [UserProfileRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockUserProfileRepository extends _i1.Mock implements _i15.UserProfileRepository {
|
||||
class MockUserProfileRepository extends _i1.Mock implements _i16.UserProfileRepository {
|
||||
MockUserProfileRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i3.Stream<_i16.UserProfile?> watchDrift() =>
|
||||
_i3.Stream<_i17.UserProfile?> watchDrift() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchDrift, []),
|
||||
returnValue: _i3.Stream<_i16.UserProfile?>.empty(),
|
||||
returnValue: _i3.Stream<_i17.UserProfile?>.empty(),
|
||||
)
|
||||
as _i3.Stream<_i16.UserProfile?>);
|
||||
as _i3.Stream<_i17.UserProfile?>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> editLocalDrift(_i16.UserProfile? profile) =>
|
||||
_i3.Future<void> editLocalDrift(_i17.UserProfile? profile) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#editLocalDrift, [profile]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
|
||||
@@ -28,11 +28,19 @@ import 'package:wger/features/measurements/widgets/chart_range_selector.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
|
||||
import '../../../../test_data/measurements.dart';
|
||||
import '../../../helpers/measurement_chart_buckets.dart';
|
||||
|
||||
Widget _wrap(Widget child, {Map<String, MeasurementEntry> latest = const {}}) => ProviderScope(
|
||||
Widget _wrap(
|
||||
Widget child, {
|
||||
Map<String, MeasurementEntry> latest = const {},
|
||||
List<MeasurementCategory> categories = const [],
|
||||
}) => ProviderScope(
|
||||
overrides: [
|
||||
// The component rows read their last known value from its own query
|
||||
latestMeasurementEntriesProvider.overrideWith((ref) => Stream.value(latest)),
|
||||
// The chart reads its points from the aggregated query, not from the
|
||||
// entries the category carries
|
||||
measurementChartBucketsProvider.overrideWith(chartBucketsFrom(categories)),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
@@ -49,8 +57,11 @@ Map<String, MeasurementEntry> _latestOf(MeasurementCategory group) => {
|
||||
|
||||
/// The fixtures have fixed dates, so the card charts the full history instead
|
||||
/// of the range it defaults to
|
||||
Widget _card(MeasurementCategory category) =>
|
||||
_wrap(CategoriesCard(category, range: ChartRange.all), latest: _latestOf(category));
|
||||
Widget _card(MeasurementCategory category) => _wrap(
|
||||
CategoriesCard(category, range: ChartRange.all),
|
||||
latest: _latestOf(category),
|
||||
categories: [category],
|
||||
);
|
||||
|
||||
MeasurementCategory _bpGroup({bool withEntries = false}) {
|
||||
final sysEntries = withEntries ? [testNeasurementEntry9] : <MeasurementEntry>[];
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import 'dart:async' as _i3;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart' as _i6;
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart' as _i4;
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart' as _i5;
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart' as _i2;
|
||||
@@ -78,6 +79,23 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
)
|
||||
as _i3.Stream<Map<String, _i5.MeasurementEntry>>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i6.MeasurementBucket>> watchEntryBuckets(
|
||||
String? categoryId, {
|
||||
DateTime? since,
|
||||
_i6.MeasurementBucketLevel? level = _i6.MeasurementBucketLevel.auto,
|
||||
int? maxPoints = 200,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#watchEntryBuckets,
|
||||
[categoryId],
|
||||
{#since: since, #level: level, #maxPoints: maxPoints},
|
||||
),
|
||||
returnValue: _i3.Stream<List<_i6.MeasurementBucket>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i6.MeasurementBucket>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i4.MeasurementCategory>> getAllOnce() =>
|
||||
(super.noSuchMethod(
|
||||
|
||||
@@ -23,6 +23,7 @@ import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_notifier.dart';
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart';
|
||||
import 'package:wger/features/measurements/widgets/chart_range_selector.dart';
|
||||
import 'package:wger/features/measurements/widgets/charts.dart';
|
||||
@@ -31,6 +32,7 @@ import 'package:wger/features/nutrition/providers/ingredient_repository.dart';
|
||||
import 'package:wger/features/nutrition/providers/nutrition_repository.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
|
||||
import '../../../helpers/measurement_chart_buckets.dart';
|
||||
import 'entries_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([MeasurementRepository, NutritionRepository, IngredientRepository])
|
||||
@@ -61,6 +63,9 @@ void main() {
|
||||
measurementRepositoryProvider.overrideWithValue(mockRepo),
|
||||
nutritionRepositoryProvider.overrideWithValue(MockNutritionRepository()),
|
||||
ingredientRepositoryProvider.overrideWithValue(MockIngredientRepository()),
|
||||
// The chart reads its points from the aggregated query, not from the
|
||||
// entries the category carries
|
||||
measurementChartBucketsProvider.overrideWith(chartBucketsFrom([category])),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
|
||||
@@ -6,18 +6,19 @@
|
||||
import 'dart:async' as _i3;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/core/search_options.dart' as _i14;
|
||||
import 'package:wger/core/search_options.dart' as _i15;
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart' as _i6;
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart' as _i4;
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart' as _i5;
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart' as _i2;
|
||||
import 'package:wger/features/nutrition/models/ingredient.dart' as _i12;
|
||||
import 'package:wger/features/nutrition/models/ingredient_filters.dart' as _i13;
|
||||
import 'package:wger/features/nutrition/models/log.dart' as _i10;
|
||||
import 'package:wger/features/nutrition/models/meal.dart' as _i8;
|
||||
import 'package:wger/features/nutrition/models/meal_item.dart' as _i9;
|
||||
import 'package:wger/features/nutrition/models/nutritional_plan.dart' as _i7;
|
||||
import 'package:wger/features/nutrition/providers/ingredient_repository.dart' as _i11;
|
||||
import 'package:wger/features/nutrition/providers/nutrition_repository.dart' as _i6;
|
||||
import 'package:wger/features/nutrition/models/ingredient.dart' as _i13;
|
||||
import 'package:wger/features/nutrition/models/ingredient_filters.dart' as _i14;
|
||||
import 'package:wger/features/nutrition/models/log.dart' as _i11;
|
||||
import 'package:wger/features/nutrition/models/meal.dart' as _i9;
|
||||
import 'package:wger/features/nutrition/models/meal_item.dart' as _i10;
|
||||
import 'package:wger/features/nutrition/models/nutritional_plan.dart' as _i8;
|
||||
import 'package:wger/features/nutrition/providers/ingredient_repository.dart' as _i12;
|
||||
import 'package:wger/features/nutrition/providers/nutrition_repository.dart' as _i7;
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: avoid_redundant_argument_values
|
||||
@@ -87,6 +88,23 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
)
|
||||
as _i3.Stream<Map<String, _i5.MeasurementEntry>>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i6.MeasurementBucket>> watchEntryBuckets(
|
||||
String? categoryId, {
|
||||
DateTime? since,
|
||||
_i6.MeasurementBucketLevel? level = _i6.MeasurementBucketLevel.auto,
|
||||
int? maxPoints = 200,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#watchEntryBuckets,
|
||||
[categoryId],
|
||||
{#since: since, #level: level, #maxPoints: maxPoints},
|
||||
),
|
||||
returnValue: _i3.Stream<List<_i6.MeasurementBucket>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i6.MeasurementBucket>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i4.MeasurementCategory>> getAllOnce() =>
|
||||
(super.noSuchMethod(
|
||||
@@ -177,21 +195,21 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
/// A class which mocks [NutritionRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockNutritionRepository extends _i1.Mock implements _i6.NutritionRepository {
|
||||
class MockNutritionRepository extends _i1.Mock implements _i7.NutritionRepository {
|
||||
MockNutritionRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i7.NutritionalPlan>> watchAllDrift() =>
|
||||
_i3.Stream<List<_i8.NutritionalPlan>> watchAllDrift() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchAllDrift, []),
|
||||
returnValue: _i3.Stream<List<_i7.NutritionalPlan>>.empty(),
|
||||
returnValue: _i3.Stream<List<_i8.NutritionalPlan>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i7.NutritionalPlan>>);
|
||||
as _i3.Stream<List<_i8.NutritionalPlan>>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> addPlanLocalDrift(_i7.NutritionalPlan? plan) =>
|
||||
_i3.Future<void> addPlanLocalDrift(_i8.NutritionalPlan? plan) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#addPlanLocalDrift, [plan]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -200,7 +218,7 @@ class MockNutritionRepository extends _i1.Mock implements _i6.NutritionRepositor
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> editLocalDrift(_i7.NutritionalPlan? plan) =>
|
||||
_i3.Future<void> editLocalDrift(_i8.NutritionalPlan? plan) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#editLocalDrift, [plan]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -218,15 +236,15 @@ class MockNutritionRepository extends _i1.Mock implements _i6.NutritionRepositor
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i8.Meal>> watchAllMealsHydrated() =>
|
||||
_i3.Stream<List<_i9.Meal>> watchAllMealsHydrated() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchAllMealsHydrated, []),
|
||||
returnValue: _i3.Stream<List<_i8.Meal>>.empty(),
|
||||
returnValue: _i3.Stream<List<_i9.Meal>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i8.Meal>>);
|
||||
as _i3.Stream<List<_i9.Meal>>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> addMealLocalDrift(_i8.Meal? meal) =>
|
||||
_i3.Future<void> addMealLocalDrift(_i9.Meal? meal) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#addMealLocalDrift, [meal]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -235,7 +253,7 @@ class MockNutritionRepository extends _i1.Mock implements _i6.NutritionRepositor
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> editMealLocalDrift(_i8.Meal? meal) =>
|
||||
_i3.Future<void> editMealLocalDrift(_i9.Meal? meal) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#editMealLocalDrift, [meal]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -253,7 +271,7 @@ class MockNutritionRepository extends _i1.Mock implements _i6.NutritionRepositor
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> addMealItemLocalDrift(_i9.MealItem? item) =>
|
||||
_i3.Future<void> addMealItemLocalDrift(_i10.MealItem? item) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#addMealItemLocalDrift, [item]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -262,7 +280,7 @@ class MockNutritionRepository extends _i1.Mock implements _i6.NutritionRepositor
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> editMealItemLocalDrift(_i9.MealItem? item) =>
|
||||
_i3.Future<void> editMealItemLocalDrift(_i10.MealItem? item) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#editMealItemLocalDrift, [item]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -280,15 +298,15 @@ class MockNutritionRepository extends _i1.Mock implements _i6.NutritionRepositor
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i10.LogItem>> watchAllLogsHydrated() =>
|
||||
_i3.Stream<List<_i11.LogItem>> watchAllLogsHydrated() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchAllLogsHydrated, []),
|
||||
returnValue: _i3.Stream<List<_i10.LogItem>>.empty(),
|
||||
returnValue: _i3.Stream<List<_i11.LogItem>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i10.LogItem>>);
|
||||
as _i3.Stream<List<_i11.LogItem>>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> addLogLocalDrift(_i10.LogItem? log) =>
|
||||
_i3.Future<void> addLogLocalDrift(_i11.LogItem? log) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#addLogLocalDrift, [log]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -309,43 +327,43 @@ class MockNutritionRepository extends _i1.Mock implements _i6.NutritionRepositor
|
||||
/// A class which mocks [IngredientRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockIngredientRepository extends _i1.Mock implements _i11.IngredientRepository {
|
||||
class MockIngredientRepository extends _i1.Mock implements _i12.IngredientRepository {
|
||||
MockIngredientRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i3.Stream<_i12.Ingredient?> watchById(int? id) =>
|
||||
_i3.Stream<_i13.Ingredient?> watchById(int? id) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchById, [id]),
|
||||
returnValue: _i3.Stream<_i12.Ingredient?>.empty(),
|
||||
returnValue: _i3.Stream<_i13.Ingredient?>.empty(),
|
||||
)
|
||||
as _i3.Stream<_i12.Ingredient?>);
|
||||
as _i3.Stream<_i13.Ingredient?>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i12.Ingredient>> watchAllDrift({
|
||||
_i13.IngredientFilters? filters = const _i13.IngredientFilters(),
|
||||
_i3.Stream<List<_i13.Ingredient>> watchAllDrift({
|
||||
_i14.IngredientFilters? filters = const _i14.IngredientFilters(),
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchAllDrift, [], {#filters: filters}),
|
||||
returnValue: _i3.Stream<List<_i12.Ingredient>>.empty(),
|
||||
returnValue: _i3.Stream<List<_i13.Ingredient>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i12.Ingredient>>);
|
||||
as _i3.Stream<List<_i13.Ingredient>>);
|
||||
|
||||
@override
|
||||
_i3.Future<_i12.Ingredient?> getById(int? id) =>
|
||||
_i3.Future<_i13.Ingredient?> getById(int? id) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#getById, [id]),
|
||||
returnValue: _i3.Future<_i12.Ingredient?>.value(),
|
||||
returnValue: _i3.Future<_i13.Ingredient?>.value(),
|
||||
)
|
||||
as _i3.Future<_i12.Ingredient?>);
|
||||
as _i3.Future<_i13.Ingredient?>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i12.Ingredient>> searchIngredientLocal(
|
||||
_i3.Future<List<_i13.Ingredient>> searchIngredientLocal(
|
||||
String? term, {
|
||||
bool? isVegan = false,
|
||||
bool? isVegetarian = false,
|
||||
_i12.NutriScore? nutriscoreMax,
|
||||
_i13.NutriScore? nutriscoreMax,
|
||||
int? limit = 100,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
@@ -359,20 +377,20 @@ class MockIngredientRepository extends _i1.Mock implements _i11.IngredientReposi
|
||||
#limit: limit,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<List<_i12.Ingredient>>.value(
|
||||
<_i12.Ingredient>[],
|
||||
returnValue: _i3.Future<List<_i13.Ingredient>>.value(
|
||||
<_i13.Ingredient>[],
|
||||
),
|
||||
)
|
||||
as _i3.Future<List<_i12.Ingredient>>);
|
||||
as _i3.Future<List<_i13.Ingredient>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i12.Ingredient>> searchIngredientServer(
|
||||
_i3.Future<List<_i13.Ingredient>> searchIngredientServer(
|
||||
String? name, {
|
||||
String? languageCode = 'en',
|
||||
_i14.SearchLanguage? searchLanguage = _i14.SearchLanguage.current,
|
||||
_i15.SearchLanguage? searchLanguage = _i15.SearchLanguage.current,
|
||||
bool? isVegan = false,
|
||||
bool? isVegetarian = false,
|
||||
_i12.NutriScore? nutriscoreMax,
|
||||
_i13.NutriScore? nutriscoreMax,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
@@ -386,21 +404,21 @@ class MockIngredientRepository extends _i1.Mock implements _i11.IngredientReposi
|
||||
#nutriscoreMax: nutriscoreMax,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<List<_i12.Ingredient>>.value(
|
||||
<_i12.Ingredient>[],
|
||||
returnValue: _i3.Future<List<_i13.Ingredient>>.value(
|
||||
<_i13.Ingredient>[],
|
||||
),
|
||||
)
|
||||
as _i3.Future<List<_i12.Ingredient>>);
|
||||
as _i3.Future<List<_i13.Ingredient>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i12.Ingredient>> search(
|
||||
_i3.Future<List<_i13.Ingredient>> search(
|
||||
String? name, {
|
||||
required bool? isOnline,
|
||||
String? languageCode = 'en',
|
||||
_i14.SearchLanguage? searchLanguage = _i14.SearchLanguage.current,
|
||||
_i15.SearchLanguage? searchLanguage = _i15.SearchLanguage.current,
|
||||
bool? isVegan = false,
|
||||
bool? isVegetarian = false,
|
||||
_i12.NutriScore? nutriscoreMax,
|
||||
_i13.NutriScore? nutriscoreMax,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
@@ -415,17 +433,17 @@ class MockIngredientRepository extends _i1.Mock implements _i11.IngredientReposi
|
||||
#nutriscoreMax: nutriscoreMax,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<List<_i12.Ingredient>>.value(
|
||||
<_i12.Ingredient>[],
|
||||
returnValue: _i3.Future<List<_i13.Ingredient>>.value(
|
||||
<_i13.Ingredient>[],
|
||||
),
|
||||
)
|
||||
as _i3.Future<List<_i12.Ingredient>>);
|
||||
as _i3.Future<List<_i13.Ingredient>>);
|
||||
|
||||
@override
|
||||
_i3.Future<_i12.Ingredient?> searchIngredientByBarcode(String? barcode) =>
|
||||
_i3.Future<_i13.Ingredient?> searchIngredientByBarcode(String? barcode) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#searchIngredientByBarcode, [barcode]),
|
||||
returnValue: _i3.Future<_i12.Ingredient?>.value(),
|
||||
returnValue: _i3.Future<_i13.Ingredient?>.value(),
|
||||
)
|
||||
as _i3.Future<_i12.Ingredient?>);
|
||||
as _i3.Future<_i13.Ingredient?>);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import 'dart:async' as _i3;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart' as _i6;
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart' as _i4;
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart' as _i5;
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart' as _i2;
|
||||
@@ -78,6 +79,23 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
)
|
||||
as _i3.Stream<Map<String, _i5.MeasurementEntry>>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i6.MeasurementBucket>> watchEntryBuckets(
|
||||
String? categoryId, {
|
||||
DateTime? since,
|
||||
_i6.MeasurementBucketLevel? level = _i6.MeasurementBucketLevel.auto,
|
||||
int? maxPoints = 200,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#watchEntryBuckets,
|
||||
[categoryId],
|
||||
{#since: since, #level: level, #maxPoints: maxPoints},
|
||||
),
|
||||
returnValue: _i3.Stream<List<_i6.MeasurementBucket>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i6.MeasurementBucket>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i4.MeasurementCategory>> getAllOnce() =>
|
||||
(super.noSuchMethod(
|
||||
|
||||
@@ -19,8 +19,10 @@
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart';
|
||||
import 'package:wger/features/measurements/widgets/chart_range_selector.dart';
|
||||
import 'package:wger/features/measurements/widgets/charts.dart';
|
||||
import 'package:wger/features/measurements/widgets/helpers.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
@@ -100,6 +102,142 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
group('chartEntriesForBuckets', () {
|
||||
MeasurementBucket bucket(
|
||||
num sum, {
|
||||
int count = 1,
|
||||
String? unit,
|
||||
num? min,
|
||||
num? max,
|
||||
DateTime? start,
|
||||
}) => MeasurementBucket(
|
||||
start: start ?? DateTime(2026, 1, 1),
|
||||
unit: unit,
|
||||
count: count,
|
||||
sum: sum,
|
||||
min: min ?? sum / count,
|
||||
max: max ?? sum / count,
|
||||
);
|
||||
|
||||
test('a bucket becomes its mean, spanning the values it stands for', () {
|
||||
final points = chartEntriesForBuckets(
|
||||
[bucket(300, count: 4, min: 60, max: 90)],
|
||||
targetUnit: 'bpm',
|
||||
categoryUnit: 'bpm',
|
||||
);
|
||||
|
||||
expect(points.single.value, 75);
|
||||
expect(points.single.min, 60);
|
||||
expect(points.single.max, 90);
|
||||
});
|
||||
|
||||
test('a single reading gets no band', () {
|
||||
// A zero-width band is a line drawn twice
|
||||
final points = chartEntriesForBuckets(
|
||||
[bucket(80)],
|
||||
targetUnit: 'kg',
|
||||
categoryUnit: 'kg',
|
||||
);
|
||||
|
||||
expect(points.single.value, 80);
|
||||
expect(points.single.hasRange, isFalse);
|
||||
});
|
||||
|
||||
test('slices are converted before they are merged', () {
|
||||
// The kg and lb halves of one day: averaging the stored numbers first
|
||||
// would produce a value in neither unit
|
||||
final points = chartEntriesForBuckets(
|
||||
[
|
||||
bucket(80, unit: 'kg'),
|
||||
bucket(180, unit: 'lb'),
|
||||
],
|
||||
targetUnit: 'kg',
|
||||
categoryUnit: 'kg',
|
||||
);
|
||||
|
||||
// 180 lb is 81.65 kg, so the day averages the two
|
||||
expect(points.single.value, closeTo(80.83, 0.01));
|
||||
expect(points.single.min, 80);
|
||||
expect(points.single.max, 81.65);
|
||||
});
|
||||
|
||||
test('the mean is weighted by how many readings each slice holds', () {
|
||||
final points = chartEntriesForBuckets(
|
||||
[
|
||||
bucket(300, count: 4, unit: 'kg'),
|
||||
bucket(100, count: 1, unit: 'kg'),
|
||||
],
|
||||
targetUnit: 'kg',
|
||||
categoryUnit: 'kg',
|
||||
);
|
||||
|
||||
// 400 over five readings, not the 87.5 an unweighted mean would give
|
||||
expect(points.single.value, 80);
|
||||
});
|
||||
|
||||
test('a slice without a unit falls back to the category one', () {
|
||||
final points = chartEntriesForBuckets(
|
||||
[bucket(180)],
|
||||
targetUnit: 'kg',
|
||||
categoryUnit: 'lb',
|
||||
);
|
||||
|
||||
expect(points.single.value, closeTo(81.65, 0.01));
|
||||
});
|
||||
|
||||
test('a summed metric totals its slices and gets no band', () {
|
||||
// A band around a daily step count is a spread the total has not
|
||||
final points = chartEntriesForBuckets(
|
||||
[bucket(6000, count: 3, min: 1000, max: 3000)],
|
||||
targetUnit: 'steps',
|
||||
categoryUnit: 'steps',
|
||||
summed: true,
|
||||
);
|
||||
|
||||
expect(points.single.value, 6000);
|
||||
expect(points.single.hasRange, isFalse);
|
||||
});
|
||||
|
||||
test('buckets of different starts stay separate points', () {
|
||||
final points = chartEntriesForBuckets(
|
||||
[
|
||||
bucket(80, start: DateTime(2026, 1, 1)),
|
||||
bucket(81, start: DateTime(2026, 1, 2)),
|
||||
],
|
||||
targetUnit: 'kg',
|
||||
categoryUnit: 'kg',
|
||||
);
|
||||
|
||||
expect(points.map((p) => p.date), [DateTime(2026, 1, 1), DateTime(2026, 1, 2)]);
|
||||
expect(points.map((p) => p.value), [80, 81]);
|
||||
});
|
||||
});
|
||||
|
||||
group('chartSeriesFor', () {
|
||||
test('cuts both series at the range, after averaging over all points', () {
|
||||
// The points reach back beyond the range so the first ones in it average
|
||||
// the days before them instead of starting over at the cutoff
|
||||
final points = [
|
||||
for (var day = 0; day < 20; day++)
|
||||
MeasurementChartEntry(
|
||||
day.isEven ? 70 : 80,
|
||||
DateTime.now().subtract(Duration(days: 19 - day)),
|
||||
),
|
||||
];
|
||||
|
||||
final (:entries, :average) = chartSeriesFor(
|
||||
points,
|
||||
ChartRange.lastMonth,
|
||||
const ChartSettings(),
|
||||
);
|
||||
|
||||
expect(entries, hasLength(20));
|
||||
expect(average, hasLength(20));
|
||||
// The last point averages a full window, not just itself
|
||||
expect(average.last.value, closeTo(75, 1));
|
||||
});
|
||||
});
|
||||
|
||||
group('sensibleRange', () {
|
||||
test('averages over the window the category configured', () {
|
||||
final points = [
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
import 'dart:async' as _i3;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/core/network/auth_credentials_storage.dart' as _i6;
|
||||
import 'package:wger/core/network/auth_state.dart' as _i7;
|
||||
import 'package:wger/core/network/auth_credentials_storage.dart' as _i7;
|
||||
import 'package:wger/core/network/auth_state.dart' as _i8;
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart' as _i6;
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart' as _i4;
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart' as _i5;
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart' as _i2;
|
||||
@@ -80,6 +81,23 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
)
|
||||
as _i3.Stream<Map<String, _i5.MeasurementEntry>>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i6.MeasurementBucket>> watchEntryBuckets(
|
||||
String? categoryId, {
|
||||
DateTime? since,
|
||||
_i6.MeasurementBucketLevel? level = _i6.MeasurementBucketLevel.auto,
|
||||
int? maxPoints = 200,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#watchEntryBuckets,
|
||||
[categoryId],
|
||||
{#since: since, #level: level, #maxPoints: maxPoints},
|
||||
),
|
||||
returnValue: _i3.Stream<List<_i6.MeasurementBucket>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i6.MeasurementBucket>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i4.MeasurementCategory>> getAllOnce() =>
|
||||
(super.noSuchMethod(
|
||||
@@ -170,22 +188,22 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
/// A class which mocks [AuthCredentialsStorage].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockAuthCredentialsStorage extends _i1.Mock implements _i6.AuthCredentialsStorage {
|
||||
class MockAuthCredentialsStorage extends _i1.Mock implements _i7.AuthCredentialsStorage {
|
||||
MockAuthCredentialsStorage() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i3.Future<_i6.StoredAuth?> load() =>
|
||||
_i3.Future<_i7.StoredAuth?> load() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#load, []),
|
||||
returnValue: _i3.Future<_i6.StoredAuth?>.value(),
|
||||
returnValue: _i3.Future<_i7.StoredAuth?>.value(),
|
||||
)
|
||||
as _i3.Future<_i6.StoredAuth?>);
|
||||
as _i3.Future<_i7.StoredAuth?>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> saveJwt({
|
||||
required _i7.JwtCredential? credential,
|
||||
required _i8.JwtCredential? credential,
|
||||
required String? serverUrl,
|
||||
String? refreshToken,
|
||||
}) =>
|
||||
@@ -202,7 +220,7 @@ class MockAuthCredentialsStorage extends _i1.Mock implements _i6.AuthCredentials
|
||||
|
||||
@override
|
||||
_i3.Future<void> updateJwt({
|
||||
required _i7.JwtCredential? credential,
|
||||
required _i8.JwtCredential? credential,
|
||||
String? refreshToken,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
import 'dart:async' as _i3;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/features/account/models/user_profile.dart' as _i7;
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart' as _i6;
|
||||
import 'package:wger/features/account/models/user_profile.dart' as _i8;
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart' as _i7;
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart' as _i6;
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart' as _i4;
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart' as _i5;
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart' as _i2;
|
||||
@@ -80,6 +81,23 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
)
|
||||
as _i3.Stream<Map<String, _i5.MeasurementEntry>>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i6.MeasurementBucket>> watchEntryBuckets(
|
||||
String? categoryId, {
|
||||
DateTime? since,
|
||||
_i6.MeasurementBucketLevel? level = _i6.MeasurementBucketLevel.auto,
|
||||
int? maxPoints = 200,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#watchEntryBuckets,
|
||||
[categoryId],
|
||||
{#since: since, #level: level, #maxPoints: maxPoints},
|
||||
),
|
||||
returnValue: _i3.Stream<List<_i6.MeasurementBucket>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i6.MeasurementBucket>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i4.MeasurementCategory>> getAllOnce() =>
|
||||
(super.noSuchMethod(
|
||||
@@ -170,21 +188,21 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
/// A class which mocks [UserProfileRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockUserProfileRepository extends _i1.Mock implements _i6.UserProfileRepository {
|
||||
class MockUserProfileRepository extends _i1.Mock implements _i7.UserProfileRepository {
|
||||
MockUserProfileRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i3.Stream<_i7.UserProfile?> watchDrift() =>
|
||||
_i3.Stream<_i8.UserProfile?> watchDrift() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchDrift, []),
|
||||
returnValue: _i3.Stream<_i7.UserProfile?>.empty(),
|
||||
returnValue: _i3.Stream<_i8.UserProfile?>.empty(),
|
||||
)
|
||||
as _i3.Stream<_i7.UserProfile?>);
|
||||
as _i3.Stream<_i8.UserProfile?>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> editLocalDrift(_i7.UserProfile? profile) =>
|
||||
_i3.Future<void> editLocalDrift(_i8.UserProfile? profile) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#editLocalDrift, [profile]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
|
||||
@@ -11,6 +11,7 @@ import 'package:http/http.dart' as _i2;
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:mockito/src/dummies.dart' as _i14;
|
||||
import 'package:wger/core/search_options.dart' as _i12;
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart' as _i19;
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart' as _i17;
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart' as _i18;
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart' as _i16;
|
||||
@@ -538,6 +539,23 @@ class MockMeasurementRepository extends _i1.Mock implements _i16.MeasurementRepo
|
||||
)
|
||||
as _i4.Stream<Map<String, _i18.MeasurementEntry>>);
|
||||
|
||||
@override
|
||||
_i4.Stream<List<_i19.MeasurementBucket>> watchEntryBuckets(
|
||||
String? categoryId, {
|
||||
DateTime? since,
|
||||
_i19.MeasurementBucketLevel? level = _i19.MeasurementBucketLevel.auto,
|
||||
int? maxPoints = 200,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#watchEntryBuckets,
|
||||
[categoryId],
|
||||
{#since: since, #level: level, #maxPoints: maxPoints},
|
||||
),
|
||||
returnValue: _i4.Stream<List<_i19.MeasurementBucket>>.empty(),
|
||||
)
|
||||
as _i4.Stream<List<_i19.MeasurementBucket>>);
|
||||
|
||||
@override
|
||||
_i4.Future<List<_i17.MeasurementCategory>> getAllOnce() =>
|
||||
(super.noSuchMethod(
|
||||
|
||||
@@ -11,8 +11,9 @@ import 'package:http/http.dart' as _i2;
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:mockito/src/dummies.dart' as _i14;
|
||||
import 'package:wger/core/search_options.dart' as _i12;
|
||||
import 'package:wger/features/account/models/user_profile.dart' as _i20;
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart' as _i19;
|
||||
import 'package:wger/features/account/models/user_profile.dart' as _i21;
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart' as _i20;
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart' as _i19;
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart' as _i17;
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart' as _i18;
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart' as _i16;
|
||||
@@ -540,6 +541,23 @@ class MockMeasurementRepository extends _i1.Mock implements _i16.MeasurementRepo
|
||||
)
|
||||
as _i4.Stream<Map<String, _i18.MeasurementEntry>>);
|
||||
|
||||
@override
|
||||
_i4.Stream<List<_i19.MeasurementBucket>> watchEntryBuckets(
|
||||
String? categoryId, {
|
||||
DateTime? since,
|
||||
_i19.MeasurementBucketLevel? level = _i19.MeasurementBucketLevel.auto,
|
||||
int? maxPoints = 200,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#watchEntryBuckets,
|
||||
[categoryId],
|
||||
{#since: since, #level: level, #maxPoints: maxPoints},
|
||||
),
|
||||
returnValue: _i4.Stream<List<_i19.MeasurementBucket>>.empty(),
|
||||
)
|
||||
as _i4.Stream<List<_i19.MeasurementBucket>>);
|
||||
|
||||
@override
|
||||
_i4.Future<List<_i17.MeasurementCategory>> getAllOnce() =>
|
||||
(super.noSuchMethod(
|
||||
@@ -630,21 +648,21 @@ class MockMeasurementRepository extends _i1.Mock implements _i16.MeasurementRepo
|
||||
/// A class which mocks [UserProfileRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockUserProfileRepository extends _i1.Mock implements _i19.UserProfileRepository {
|
||||
class MockUserProfileRepository extends _i1.Mock implements _i20.UserProfileRepository {
|
||||
MockUserProfileRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i4.Stream<_i20.UserProfile?> watchDrift() =>
|
||||
_i4.Stream<_i21.UserProfile?> watchDrift() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchDrift, []),
|
||||
returnValue: _i4.Stream<_i20.UserProfile?>.empty(),
|
||||
returnValue: _i4.Stream<_i21.UserProfile?>.empty(),
|
||||
)
|
||||
as _i4.Stream<_i20.UserProfile?>);
|
||||
as _i4.Stream<_i21.UserProfile?>);
|
||||
|
||||
@override
|
||||
_i4.Future<void> editLocalDrift(_i20.UserProfile? profile) =>
|
||||
_i4.Future<void> editLocalDrift(_i21.UserProfile? profile) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#editLocalDrift, [profile]),
|
||||
returnValue: _i4.Future<void>.value(),
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
import 'dart:async' as _i3;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/features/account/models/user_profile.dart' as _i7;
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart' as _i6;
|
||||
import 'package:wger/features/account/models/user_profile.dart' as _i8;
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart' as _i7;
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart' as _i6;
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart' as _i4;
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart' as _i5;
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart' as _i2;
|
||||
@@ -80,6 +81,23 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
)
|
||||
as _i3.Stream<Map<String, _i5.MeasurementEntry>>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i6.MeasurementBucket>> watchEntryBuckets(
|
||||
String? categoryId, {
|
||||
DateTime? since,
|
||||
_i6.MeasurementBucketLevel? level = _i6.MeasurementBucketLevel.auto,
|
||||
int? maxPoints = 200,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#watchEntryBuckets,
|
||||
[categoryId],
|
||||
{#since: since, #level: level, #maxPoints: maxPoints},
|
||||
),
|
||||
returnValue: _i3.Stream<List<_i6.MeasurementBucket>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i6.MeasurementBucket>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i4.MeasurementCategory>> getAllOnce() =>
|
||||
(super.noSuchMethod(
|
||||
@@ -170,21 +188,21 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
/// A class which mocks [UserProfileRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockUserProfileRepository extends _i1.Mock implements _i6.UserProfileRepository {
|
||||
class MockUserProfileRepository extends _i1.Mock implements _i7.UserProfileRepository {
|
||||
MockUserProfileRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i3.Stream<_i7.UserProfile?> watchDrift() =>
|
||||
_i3.Stream<_i8.UserProfile?> watchDrift() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchDrift, []),
|
||||
returnValue: _i3.Stream<_i7.UserProfile?>.empty(),
|
||||
returnValue: _i3.Stream<_i8.UserProfile?>.empty(),
|
||||
)
|
||||
as _i3.Stream<_i7.UserProfile?>);
|
||||
as _i3.Stream<_i8.UserProfile?>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> editLocalDrift(_i7.UserProfile? profile) =>
|
||||
_i3.Future<void> editLocalDrift(_i8.UserProfile? profile) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#editLocalDrift, [profile]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
|
||||
61
test/helpers/measurement_chart_buckets.dart
Normal file
61
test/helpers/measurement_chart_buckets.dart
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is part of wger Workout Manager <https://github.com/wger-project>.
|
||||
* Copyright (c) 2026 wger Team
|
||||
*
|
||||
* wger Workout Manager is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart';
|
||||
|
||||
/// One bucket per entry, oldest first: what the aggregated query returns for a
|
||||
/// series short enough not to be condensed, which every widget fixture is.
|
||||
/// Condensing is covered where it happens, in the repository and `downsample`.
|
||||
List<MeasurementBucket> entryBuckets(Iterable<MeasurementEntry> entries, {DateTime? since}) => [
|
||||
for (final entry in entries)
|
||||
if (since == null || !entry.date.isBefore(since))
|
||||
MeasurementBucket(
|
||||
start: entry.date,
|
||||
unit: entry.extraData?['unit'] as String?,
|
||||
count: 1,
|
||||
sum: entry.value,
|
||||
min: entry.extraData?['min'] as num? ?? entry.value,
|
||||
max: entry.extraData?['max'] as num? ?? entry.value,
|
||||
),
|
||||
]..sort((a, b) => a.start.compareTo(b.start));
|
||||
|
||||
/// What `measurementChartBucketsProvider.overrideWith` takes.
|
||||
typedef ChartBucketsStub =
|
||||
Stream<List<MeasurementBucket>> Function(
|
||||
Ref,
|
||||
(String, DateTime?, MeasurementBucketLevel),
|
||||
);
|
||||
|
||||
/// Serves the chart query from the entries [categories] already carry, group
|
||||
/// components included, so a widget test seeds one list rather than two.
|
||||
ChartBucketsStub chartBucketsFrom(List<MeasurementCategory> categories) {
|
||||
final byId = {
|
||||
for (final category in categories) ...{
|
||||
category.id: category,
|
||||
for (final child in category.children) child.id: child,
|
||||
},
|
||||
};
|
||||
|
||||
return (ref, args) {
|
||||
final (categoryId, since, _) = args;
|
||||
return Stream.value(entryBuckets(byId[categoryId]?.entries ?? const [], since: since));
|
||||
};
|
||||
}
|
||||
@@ -7,13 +7,14 @@ import 'dart:async' as _i10;
|
||||
|
||||
import 'package:image_picker/image_picker.dart' as _i11;
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:mockito/src/dummies.dart' as _i30;
|
||||
import 'package:mockito/src/dummies.dart' as _i31;
|
||||
import 'package:wger/core/network/base_provider.dart' as _i8;
|
||||
import 'package:wger/core/search_options.dart' as _i20;
|
||||
import 'package:wger/features/account/models/user_profile.dart' as _i25;
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart' as _i24;
|
||||
import 'package:wger/features/account/models/user_profile.dart' as _i26;
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart' as _i25;
|
||||
import 'package:wger/features/gallery/models/image.dart' as _i2;
|
||||
import 'package:wger/features/gallery/providers/gallery_repository.dart' as _i9;
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart' as _i24;
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart' as _i22;
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart' as _i23;
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart' as _i21;
|
||||
@@ -27,16 +28,16 @@ import 'package:wger/features/nutrition/providers/ingredient_repository.dart' as
|
||||
import 'package:wger/features/nutrition/providers/nutrition_repository.dart' as _i12;
|
||||
import 'package:wger/features/routines/models/base_config.dart' as _i7;
|
||||
import 'package:wger/features/routines/models/day.dart' as _i4;
|
||||
import 'package:wger/features/routines/models/repetition_unit.dart' as _i28;
|
||||
import 'package:wger/features/routines/models/repetition_unit.dart' as _i29;
|
||||
import 'package:wger/features/routines/models/routine.dart' as _i3;
|
||||
import 'package:wger/features/routines/models/slot.dart' as _i5;
|
||||
import 'package:wger/features/routines/models/slot_entry.dart' as _i6;
|
||||
import 'package:wger/features/routines/models/weight_unit.dart' as _i27;
|
||||
import 'package:wger/features/routines/providers/routines_repository.dart' as _i26;
|
||||
import 'package:wger/features/trophies/models/trophy.dart' as _i31;
|
||||
import 'package:wger/features/trophies/models/user_trophy.dart' as _i32;
|
||||
import 'package:wger/features/trophies/models/user_trophy_progression.dart' as _i33;
|
||||
import 'package:wger/features/trophies/providers/trophy_repository.dart' as _i29;
|
||||
import 'package:wger/features/routines/models/weight_unit.dart' as _i28;
|
||||
import 'package:wger/features/routines/providers/routines_repository.dart' as _i27;
|
||||
import 'package:wger/features/trophies/models/trophy.dart' as _i32;
|
||||
import 'package:wger/features/trophies/models/user_trophy.dart' as _i33;
|
||||
import 'package:wger/features/trophies/models/user_trophy_progression.dart' as _i34;
|
||||
import 'package:wger/features/trophies/providers/trophy_repository.dart' as _i30;
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: avoid_redundant_argument_values
|
||||
@@ -453,6 +454,23 @@ class MockMeasurementRepository extends _i1.Mock implements _i21.MeasurementRepo
|
||||
)
|
||||
as _i10.Stream<Map<String, _i23.MeasurementEntry>>);
|
||||
|
||||
@override
|
||||
_i10.Stream<List<_i24.MeasurementBucket>> watchEntryBuckets(
|
||||
String? categoryId, {
|
||||
DateTime? since,
|
||||
_i24.MeasurementBucketLevel? level = _i24.MeasurementBucketLevel.auto,
|
||||
int? maxPoints = 200,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#watchEntryBuckets,
|
||||
[categoryId],
|
||||
{#since: since, #level: level, #maxPoints: maxPoints},
|
||||
),
|
||||
returnValue: _i10.Stream<List<_i24.MeasurementBucket>>.empty(),
|
||||
)
|
||||
as _i10.Stream<List<_i24.MeasurementBucket>>);
|
||||
|
||||
@override
|
||||
_i10.Future<List<_i22.MeasurementCategory>> getAllOnce() =>
|
||||
(super.noSuchMethod(
|
||||
@@ -543,21 +561,21 @@ class MockMeasurementRepository extends _i1.Mock implements _i21.MeasurementRepo
|
||||
/// A class which mocks [UserProfileRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockUserProfileRepository extends _i1.Mock implements _i24.UserProfileRepository {
|
||||
class MockUserProfileRepository extends _i1.Mock implements _i25.UserProfileRepository {
|
||||
MockUserProfileRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i10.Stream<_i25.UserProfile?> watchDrift() =>
|
||||
_i10.Stream<_i26.UserProfile?> watchDrift() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchDrift, []),
|
||||
returnValue: _i10.Stream<_i25.UserProfile?>.empty(),
|
||||
returnValue: _i10.Stream<_i26.UserProfile?>.empty(),
|
||||
)
|
||||
as _i10.Stream<_i25.UserProfile?>);
|
||||
as _i10.Stream<_i26.UserProfile?>);
|
||||
|
||||
@override
|
||||
_i10.Future<void> editLocalDrift(_i25.UserProfile? profile) =>
|
||||
_i10.Future<void> editLocalDrift(_i26.UserProfile? profile) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#editLocalDrift, [profile]),
|
||||
returnValue: _i10.Future<void>.value(),
|
||||
@@ -569,7 +587,7 @@ class MockUserProfileRepository extends _i1.Mock implements _i24.UserProfileRepo
|
||||
/// A class which mocks [RoutinesRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockRoutinesRepository extends _i1.Mock implements _i26.RoutinesRepository {
|
||||
class MockRoutinesRepository extends _i1.Mock implements _i27.RoutinesRepository {
|
||||
MockRoutinesRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
@@ -627,20 +645,20 @@ class MockRoutinesRepository extends _i1.Mock implements _i26.RoutinesRepository
|
||||
as _i10.Future<void>);
|
||||
|
||||
@override
|
||||
_i10.Stream<List<_i27.WeightUnit>> watchWeightUnitsDrift() =>
|
||||
_i10.Stream<List<_i28.WeightUnit>> watchWeightUnitsDrift() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchWeightUnitsDrift, []),
|
||||
returnValue: _i10.Stream<List<_i27.WeightUnit>>.empty(),
|
||||
returnValue: _i10.Stream<List<_i28.WeightUnit>>.empty(),
|
||||
)
|
||||
as _i10.Stream<List<_i27.WeightUnit>>);
|
||||
as _i10.Stream<List<_i28.WeightUnit>>);
|
||||
|
||||
@override
|
||||
_i10.Stream<List<_i28.RepetitionUnit>> watchRepetitionUnitsDrift() =>
|
||||
_i10.Stream<List<_i29.RepetitionUnit>> watchRepetitionUnitsDrift() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchRepetitionUnitsDrift, []),
|
||||
returnValue: _i10.Stream<List<_i28.RepetitionUnit>>.empty(),
|
||||
returnValue: _i10.Stream<List<_i29.RepetitionUnit>>.empty(),
|
||||
)
|
||||
as _i10.Stream<List<_i28.RepetitionUnit>>);
|
||||
as _i10.Stream<List<_i29.RepetitionUnit>>);
|
||||
|
||||
@override
|
||||
_i10.Future<_i4.Day> addDayServer(_i4.Day? day) =>
|
||||
@@ -787,7 +805,7 @@ class MockRoutinesRepository extends _i1.Mock implements _i26.RoutinesRepository
|
||||
/// A class which mocks [TrophyRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockTrophyRepository extends _i1.Mock implements _i29.TrophyRepository {
|
||||
class MockTrophyRepository extends _i1.Mock implements _i30.TrophyRepository {
|
||||
MockTrophyRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
@@ -807,7 +825,7 @@ class MockTrophyRepository extends _i1.Mock implements _i29.TrophyRepository {
|
||||
String get trophiesPath =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#trophiesPath),
|
||||
returnValue: _i30.dummyValue<String>(
|
||||
returnValue: _i31.dummyValue<String>(
|
||||
this,
|
||||
Invocation.getter(#trophiesPath),
|
||||
),
|
||||
@@ -818,7 +836,7 @@ class MockTrophyRepository extends _i1.Mock implements _i29.TrophyRepository {
|
||||
String get userTrophiesPath =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#userTrophiesPath),
|
||||
returnValue: _i30.dummyValue<String>(
|
||||
returnValue: _i31.dummyValue<String>(
|
||||
this,
|
||||
Invocation.getter(#userTrophiesPath),
|
||||
),
|
||||
@@ -829,7 +847,7 @@ class MockTrophyRepository extends _i1.Mock implements _i29.TrophyRepository {
|
||||
String get userTrophyProgressionPath =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#userTrophyProgressionPath),
|
||||
returnValue: _i30.dummyValue<String>(
|
||||
returnValue: _i31.dummyValue<String>(
|
||||
this,
|
||||
Invocation.getter(#userTrophyProgressionPath),
|
||||
),
|
||||
@@ -837,15 +855,15 @@ class MockTrophyRepository extends _i1.Mock implements _i29.TrophyRepository {
|
||||
as String);
|
||||
|
||||
@override
|
||||
_i10.Future<List<_i31.Trophy>> fetchTrophies({String? language}) =>
|
||||
_i10.Future<List<_i32.Trophy>> fetchTrophies({String? language}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#fetchTrophies, [], {#language: language}),
|
||||
returnValue: _i10.Future<List<_i31.Trophy>>.value(<_i31.Trophy>[]),
|
||||
returnValue: _i10.Future<List<_i32.Trophy>>.value(<_i32.Trophy>[]),
|
||||
)
|
||||
as _i10.Future<List<_i31.Trophy>>);
|
||||
as _i10.Future<List<_i32.Trophy>>);
|
||||
|
||||
@override
|
||||
_i10.Future<List<_i32.UserTrophy>> fetchUserTrophies({
|
||||
_i10.Future<List<_i33.UserTrophy>> fetchUserTrophies({
|
||||
Map<String, String>? filterQuery,
|
||||
String? language,
|
||||
}) =>
|
||||
@@ -854,14 +872,14 @@ class MockTrophyRepository extends _i1.Mock implements _i29.TrophyRepository {
|
||||
#filterQuery: filterQuery,
|
||||
#language: language,
|
||||
}),
|
||||
returnValue: _i10.Future<List<_i32.UserTrophy>>.value(
|
||||
<_i32.UserTrophy>[],
|
||||
returnValue: _i10.Future<List<_i33.UserTrophy>>.value(
|
||||
<_i33.UserTrophy>[],
|
||||
),
|
||||
)
|
||||
as _i10.Future<List<_i32.UserTrophy>>);
|
||||
as _i10.Future<List<_i33.UserTrophy>>);
|
||||
|
||||
@override
|
||||
_i10.Future<List<_i33.UserTrophyProgression>> fetchProgression({
|
||||
_i10.Future<List<_i34.UserTrophyProgression>> fetchProgression({
|
||||
Map<String, String>? filterQuery,
|
||||
String? language,
|
||||
}) =>
|
||||
@@ -870,9 +888,9 @@ class MockTrophyRepository extends _i1.Mock implements _i29.TrophyRepository {
|
||||
#filterQuery: filterQuery,
|
||||
#language: language,
|
||||
}),
|
||||
returnValue: _i10.Future<List<_i33.UserTrophyProgression>>.value(
|
||||
<_i33.UserTrophyProgression>[],
|
||||
returnValue: _i10.Future<List<_i34.UserTrophyProgression>>.value(
|
||||
<_i34.UserTrophyProgression>[],
|
||||
),
|
||||
)
|
||||
as _i10.Future<List<_i33.UserTrophyProgression>>);
|
||||
as _i10.Future<List<_i34.UserTrophyProgression>>);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import 'dart:async' as _i3;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart' as _i6;
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart' as _i4;
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart' as _i5;
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart' as _i2;
|
||||
@@ -78,6 +79,23 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
)
|
||||
as _i3.Stream<Map<String, _i5.MeasurementEntry>>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i6.MeasurementBucket>> watchEntryBuckets(
|
||||
String? categoryId, {
|
||||
DateTime? since,
|
||||
_i6.MeasurementBucketLevel? level = _i6.MeasurementBucketLevel.auto,
|
||||
int? maxPoints = 200,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#watchEntryBuckets,
|
||||
[categoryId],
|
||||
{#since: since, #level: level, #maxPoints: maxPoints},
|
||||
),
|
||||
returnValue: _i3.Stream<List<_i6.MeasurementBucket>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i6.MeasurementBucket>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i4.MeasurementCategory>> getAllOnce() =>
|
||||
(super.noSuchMethod(
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'dart:async' as _i3;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/core/search_options.dart' as _i11;
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart' as _i15;
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart' as _i13;
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart' as _i14;
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart' as _i12;
|
||||
@@ -343,6 +344,23 @@ class MockMeasurementRepository extends _i1.Mock implements _i12.MeasurementRepo
|
||||
)
|
||||
as _i3.Stream<Map<String, _i14.MeasurementEntry>>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i15.MeasurementBucket>> watchEntryBuckets(
|
||||
String? categoryId, {
|
||||
DateTime? since,
|
||||
_i15.MeasurementBucketLevel? level = _i15.MeasurementBucketLevel.auto,
|
||||
int? maxPoints = 200,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#watchEntryBuckets,
|
||||
[categoryId],
|
||||
{#since: since, #level: level, #maxPoints: maxPoints},
|
||||
),
|
||||
returnValue: _i3.Stream<List<_i15.MeasurementBucket>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i15.MeasurementBucket>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i13.MeasurementCategory>> getAllOnce() =>
|
||||
(super.noSuchMethod(
|
||||
|
||||
@@ -6,20 +6,21 @@
|
||||
import 'dart:async' as _i3;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:wger/core/search_options.dart' as _i16;
|
||||
import 'package:wger/features/account/models/user_profile.dart' as _i7;
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart' as _i6;
|
||||
import 'package:wger/core/search_options.dart' as _i17;
|
||||
import 'package:wger/features/account/models/user_profile.dart' as _i8;
|
||||
import 'package:wger/features/account/providers/user_profile_repository.dart' as _i7;
|
||||
import 'package:wger/features/measurements/models/measurement_bucket.dart' as _i6;
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart' as _i4;
|
||||
import 'package:wger/features/measurements/models/measurement_entry.dart' as _i5;
|
||||
import 'package:wger/features/measurements/providers/measurement_repository.dart' as _i2;
|
||||
import 'package:wger/features/nutrition/models/ingredient.dart' as _i14;
|
||||
import 'package:wger/features/nutrition/models/ingredient_filters.dart' as _i15;
|
||||
import 'package:wger/features/nutrition/models/log.dart' as _i12;
|
||||
import 'package:wger/features/nutrition/models/meal.dart' as _i10;
|
||||
import 'package:wger/features/nutrition/models/meal_item.dart' as _i11;
|
||||
import 'package:wger/features/nutrition/models/nutritional_plan.dart' as _i9;
|
||||
import 'package:wger/features/nutrition/providers/ingredient_repository.dart' as _i13;
|
||||
import 'package:wger/features/nutrition/providers/nutrition_repository.dart' as _i8;
|
||||
import 'package:wger/features/nutrition/models/ingredient.dart' as _i15;
|
||||
import 'package:wger/features/nutrition/models/ingredient_filters.dart' as _i16;
|
||||
import 'package:wger/features/nutrition/models/log.dart' as _i13;
|
||||
import 'package:wger/features/nutrition/models/meal.dart' as _i11;
|
||||
import 'package:wger/features/nutrition/models/meal_item.dart' as _i12;
|
||||
import 'package:wger/features/nutrition/models/nutritional_plan.dart' as _i10;
|
||||
import 'package:wger/features/nutrition/providers/ingredient_repository.dart' as _i14;
|
||||
import 'package:wger/features/nutrition/providers/nutrition_repository.dart' as _i9;
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: avoid_redundant_argument_values
|
||||
@@ -89,6 +90,23 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
)
|
||||
as _i3.Stream<Map<String, _i5.MeasurementEntry>>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i6.MeasurementBucket>> watchEntryBuckets(
|
||||
String? categoryId, {
|
||||
DateTime? since,
|
||||
_i6.MeasurementBucketLevel? level = _i6.MeasurementBucketLevel.auto,
|
||||
int? maxPoints = 200,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#watchEntryBuckets,
|
||||
[categoryId],
|
||||
{#since: since, #level: level, #maxPoints: maxPoints},
|
||||
),
|
||||
returnValue: _i3.Stream<List<_i6.MeasurementBucket>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i6.MeasurementBucket>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i4.MeasurementCategory>> getAllOnce() =>
|
||||
(super.noSuchMethod(
|
||||
@@ -179,21 +197,21 @@ class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepos
|
||||
/// A class which mocks [UserProfileRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockUserProfileRepository extends _i1.Mock implements _i6.UserProfileRepository {
|
||||
class MockUserProfileRepository extends _i1.Mock implements _i7.UserProfileRepository {
|
||||
MockUserProfileRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i3.Stream<_i7.UserProfile?> watchDrift() =>
|
||||
_i3.Stream<_i8.UserProfile?> watchDrift() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchDrift, []),
|
||||
returnValue: _i3.Stream<_i7.UserProfile?>.empty(),
|
||||
returnValue: _i3.Stream<_i8.UserProfile?>.empty(),
|
||||
)
|
||||
as _i3.Stream<_i7.UserProfile?>);
|
||||
as _i3.Stream<_i8.UserProfile?>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> editLocalDrift(_i7.UserProfile? profile) =>
|
||||
_i3.Future<void> editLocalDrift(_i8.UserProfile? profile) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#editLocalDrift, [profile]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -205,21 +223,21 @@ class MockUserProfileRepository extends _i1.Mock implements _i6.UserProfileRepos
|
||||
/// A class which mocks [NutritionRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockNutritionRepository extends _i1.Mock implements _i8.NutritionRepository {
|
||||
class MockNutritionRepository extends _i1.Mock implements _i9.NutritionRepository {
|
||||
MockNutritionRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i9.NutritionalPlan>> watchAllDrift() =>
|
||||
_i3.Stream<List<_i10.NutritionalPlan>> watchAllDrift() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchAllDrift, []),
|
||||
returnValue: _i3.Stream<List<_i9.NutritionalPlan>>.empty(),
|
||||
returnValue: _i3.Stream<List<_i10.NutritionalPlan>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i9.NutritionalPlan>>);
|
||||
as _i3.Stream<List<_i10.NutritionalPlan>>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> addPlanLocalDrift(_i9.NutritionalPlan? plan) =>
|
||||
_i3.Future<void> addPlanLocalDrift(_i10.NutritionalPlan? plan) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#addPlanLocalDrift, [plan]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -228,7 +246,7 @@ class MockNutritionRepository extends _i1.Mock implements _i8.NutritionRepositor
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> editLocalDrift(_i9.NutritionalPlan? plan) =>
|
||||
_i3.Future<void> editLocalDrift(_i10.NutritionalPlan? plan) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#editLocalDrift, [plan]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -246,15 +264,15 @@ class MockNutritionRepository extends _i1.Mock implements _i8.NutritionRepositor
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i10.Meal>> watchAllMealsHydrated() =>
|
||||
_i3.Stream<List<_i11.Meal>> watchAllMealsHydrated() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchAllMealsHydrated, []),
|
||||
returnValue: _i3.Stream<List<_i10.Meal>>.empty(),
|
||||
returnValue: _i3.Stream<List<_i11.Meal>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i10.Meal>>);
|
||||
as _i3.Stream<List<_i11.Meal>>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> addMealLocalDrift(_i10.Meal? meal) =>
|
||||
_i3.Future<void> addMealLocalDrift(_i11.Meal? meal) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#addMealLocalDrift, [meal]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -263,7 +281,7 @@ class MockNutritionRepository extends _i1.Mock implements _i8.NutritionRepositor
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> editMealLocalDrift(_i10.Meal? meal) =>
|
||||
_i3.Future<void> editMealLocalDrift(_i11.Meal? meal) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#editMealLocalDrift, [meal]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -281,7 +299,7 @@ class MockNutritionRepository extends _i1.Mock implements _i8.NutritionRepositor
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> addMealItemLocalDrift(_i11.MealItem? item) =>
|
||||
_i3.Future<void> addMealItemLocalDrift(_i12.MealItem? item) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#addMealItemLocalDrift, [item]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -290,7 +308,7 @@ class MockNutritionRepository extends _i1.Mock implements _i8.NutritionRepositor
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> editMealItemLocalDrift(_i11.MealItem? item) =>
|
||||
_i3.Future<void> editMealItemLocalDrift(_i12.MealItem? item) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#editMealItemLocalDrift, [item]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -308,15 +326,15 @@ class MockNutritionRepository extends _i1.Mock implements _i8.NutritionRepositor
|
||||
as _i3.Future<void>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i12.LogItem>> watchAllLogsHydrated() =>
|
||||
_i3.Stream<List<_i13.LogItem>> watchAllLogsHydrated() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchAllLogsHydrated, []),
|
||||
returnValue: _i3.Stream<List<_i12.LogItem>>.empty(),
|
||||
returnValue: _i3.Stream<List<_i13.LogItem>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i12.LogItem>>);
|
||||
as _i3.Stream<List<_i13.LogItem>>);
|
||||
|
||||
@override
|
||||
_i3.Future<void> addLogLocalDrift(_i12.LogItem? log) =>
|
||||
_i3.Future<void> addLogLocalDrift(_i13.LogItem? log) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#addLogLocalDrift, [log]),
|
||||
returnValue: _i3.Future<void>.value(),
|
||||
@@ -337,43 +355,43 @@ class MockNutritionRepository extends _i1.Mock implements _i8.NutritionRepositor
|
||||
/// A class which mocks [IngredientRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockIngredientRepository extends _i1.Mock implements _i13.IngredientRepository {
|
||||
class MockIngredientRepository extends _i1.Mock implements _i14.IngredientRepository {
|
||||
MockIngredientRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i3.Stream<_i14.Ingredient?> watchById(int? id) =>
|
||||
_i3.Stream<_i15.Ingredient?> watchById(int? id) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchById, [id]),
|
||||
returnValue: _i3.Stream<_i14.Ingredient?>.empty(),
|
||||
returnValue: _i3.Stream<_i15.Ingredient?>.empty(),
|
||||
)
|
||||
as _i3.Stream<_i14.Ingredient?>);
|
||||
as _i3.Stream<_i15.Ingredient?>);
|
||||
|
||||
@override
|
||||
_i3.Stream<List<_i14.Ingredient>> watchAllDrift({
|
||||
_i15.IngredientFilters? filters = const _i15.IngredientFilters(),
|
||||
_i3.Stream<List<_i15.Ingredient>> watchAllDrift({
|
||||
_i16.IngredientFilters? filters = const _i16.IngredientFilters(),
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#watchAllDrift, [], {#filters: filters}),
|
||||
returnValue: _i3.Stream<List<_i14.Ingredient>>.empty(),
|
||||
returnValue: _i3.Stream<List<_i15.Ingredient>>.empty(),
|
||||
)
|
||||
as _i3.Stream<List<_i14.Ingredient>>);
|
||||
as _i3.Stream<List<_i15.Ingredient>>);
|
||||
|
||||
@override
|
||||
_i3.Future<_i14.Ingredient?> getById(int? id) =>
|
||||
_i3.Future<_i15.Ingredient?> getById(int? id) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#getById, [id]),
|
||||
returnValue: _i3.Future<_i14.Ingredient?>.value(),
|
||||
returnValue: _i3.Future<_i15.Ingredient?>.value(),
|
||||
)
|
||||
as _i3.Future<_i14.Ingredient?>);
|
||||
as _i3.Future<_i15.Ingredient?>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i14.Ingredient>> searchIngredientLocal(
|
||||
_i3.Future<List<_i15.Ingredient>> searchIngredientLocal(
|
||||
String? term, {
|
||||
bool? isVegan = false,
|
||||
bool? isVegetarian = false,
|
||||
_i14.NutriScore? nutriscoreMax,
|
||||
_i15.NutriScore? nutriscoreMax,
|
||||
int? limit = 100,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
@@ -387,20 +405,20 @@ class MockIngredientRepository extends _i1.Mock implements _i13.IngredientReposi
|
||||
#limit: limit,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<List<_i14.Ingredient>>.value(
|
||||
<_i14.Ingredient>[],
|
||||
returnValue: _i3.Future<List<_i15.Ingredient>>.value(
|
||||
<_i15.Ingredient>[],
|
||||
),
|
||||
)
|
||||
as _i3.Future<List<_i14.Ingredient>>);
|
||||
as _i3.Future<List<_i15.Ingredient>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i14.Ingredient>> searchIngredientServer(
|
||||
_i3.Future<List<_i15.Ingredient>> searchIngredientServer(
|
||||
String? name, {
|
||||
String? languageCode = 'en',
|
||||
_i16.SearchLanguage? searchLanguage = _i16.SearchLanguage.current,
|
||||
_i17.SearchLanguage? searchLanguage = _i17.SearchLanguage.current,
|
||||
bool? isVegan = false,
|
||||
bool? isVegetarian = false,
|
||||
_i14.NutriScore? nutriscoreMax,
|
||||
_i15.NutriScore? nutriscoreMax,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
@@ -414,21 +432,21 @@ class MockIngredientRepository extends _i1.Mock implements _i13.IngredientReposi
|
||||
#nutriscoreMax: nutriscoreMax,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<List<_i14.Ingredient>>.value(
|
||||
<_i14.Ingredient>[],
|
||||
returnValue: _i3.Future<List<_i15.Ingredient>>.value(
|
||||
<_i15.Ingredient>[],
|
||||
),
|
||||
)
|
||||
as _i3.Future<List<_i14.Ingredient>>);
|
||||
as _i3.Future<List<_i15.Ingredient>>);
|
||||
|
||||
@override
|
||||
_i3.Future<List<_i14.Ingredient>> search(
|
||||
_i3.Future<List<_i15.Ingredient>> search(
|
||||
String? name, {
|
||||
required bool? isOnline,
|
||||
String? languageCode = 'en',
|
||||
_i16.SearchLanguage? searchLanguage = _i16.SearchLanguage.current,
|
||||
_i17.SearchLanguage? searchLanguage = _i17.SearchLanguage.current,
|
||||
bool? isVegan = false,
|
||||
bool? isVegetarian = false,
|
||||
_i14.NutriScore? nutriscoreMax,
|
||||
_i15.NutriScore? nutriscoreMax,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
@@ -443,17 +461,17 @@ class MockIngredientRepository extends _i1.Mock implements _i13.IngredientReposi
|
||||
#nutriscoreMax: nutriscoreMax,
|
||||
},
|
||||
),
|
||||
returnValue: _i3.Future<List<_i14.Ingredient>>.value(
|
||||
<_i14.Ingredient>[],
|
||||
returnValue: _i3.Future<List<_i15.Ingredient>>.value(
|
||||
<_i15.Ingredient>[],
|
||||
),
|
||||
)
|
||||
as _i3.Future<List<_i14.Ingredient>>);
|
||||
as _i3.Future<List<_i15.Ingredient>>);
|
||||
|
||||
@override
|
||||
_i3.Future<_i14.Ingredient?> searchIngredientByBarcode(String? barcode) =>
|
||||
_i3.Future<_i15.Ingredient?> searchIngredientByBarcode(String? barcode) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(#searchIngredientByBarcode, [barcode]),
|
||||
returnValue: _i3.Future<_i14.Ingredient?>.value(),
|
||||
returnValue: _i3.Future<_i15.Ingredient?>.value(),
|
||||
)
|
||||
as _i3.Future<_i14.Ingredient?>);
|
||||
as _i3.Future<_i15.Ingredient?>);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user