mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-04 20:52:26 +01:00
Cleanups
This commit is contained in:
@@ -28,6 +28,7 @@ import 'package:wger/features/account/providers/user_profile_notifier.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';
|
||||
import 'package:wger/features/measurements/widgets/charts.dart';
|
||||
import 'package:wger/features/nutrition/models/nutritional_plan.dart';
|
||||
import 'package:wger/features/nutrition/providers/nutrition_notifier.dart';
|
||||
import 'package:wger/features/routines/models/session.dart';
|
||||
@@ -93,6 +94,8 @@ class _DashboardCalendarWidgetState extends riverpod.ConsumerState<DashboardCale
|
||||
// display unit; other measurements show in the category unit
|
||||
final isBodyWeight = category.isOfficialBodyWeight;
|
||||
final displayUnit = isBodyWeight ? weightDisplayUnit(isMetric) : category.unit;
|
||||
// the conversion needs the wire unit, the label the localized one
|
||||
final unitLabel = isBodyWeight ? weightUnit(isMetric, context) : category.unit;
|
||||
|
||||
for (final entry in category.entries) {
|
||||
final date = DateFormatLists.format(entry.date);
|
||||
@@ -102,8 +105,8 @@ class _DashboardCalendarWidgetState extends riverpod.ConsumerState<DashboardCale
|
||||
events.putIfAbsent(date, () => []);
|
||||
events[date]!.add(
|
||||
isBodyWeight
|
||||
? Event(EventType.weight, '$value $displayUnit')
|
||||
: Event(EventType.measurement, '${category.name}: $value $displayUnit'),
|
||||
? Event(EventType.weight, '$value $unitLabel')
|
||||
: Event(EventType.measurement, '${category.name}: $value $unitLabel'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wger/core/form_screen.dart';
|
||||
import 'package:wger/core/formatting/formatting.dart';
|
||||
import 'package:wger/features/measurements/models/measurement_category.dart';
|
||||
import 'package:wger/features/measurements/models/unit_conversion.dart';
|
||||
import 'package:wger/features/measurements/screens/measurement_entries_screen.dart';
|
||||
@@ -156,7 +157,7 @@ class CategoriesCard extends StatelessWidget {
|
||||
title: Text(child.name),
|
||||
trailing: Text(
|
||||
latest != null
|
||||
? '${latest.valueIn(child.unit, categoryUnit: child.unit)} ${child.unit}'
|
||||
? '${localizedNumberFormat(context).format(latest.valueIn(child.unit, categoryUnit: child.unit))} ${child.unit}'
|
||||
: '—',
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
|
||||
87
test/database/converters/json_map_converter_test.dart
Normal file
87
test/database/converters/json_map_converter_test.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/>.
|
||||
*/
|
||||
|
||||
import 'package:drift/drift.dart' hide isNull;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:wger/database/converters/json_map_converter.dart';
|
||||
import 'package:wger/database/powersync/database.dart';
|
||||
|
||||
import '../../helpers/in_memory_drift.dart';
|
||||
|
||||
void main() {
|
||||
const converter = JsonMapConverter();
|
||||
|
||||
group('JsonMapConverter', () {
|
||||
test('decodes a JSON object', () {
|
||||
expect(converter.fromSql('{"unit": "lb", "device": "Scale"}'), {
|
||||
'unit': 'lb',
|
||||
'device': 'Scale',
|
||||
});
|
||||
});
|
||||
|
||||
test('anything that is not a JSON object reads as an empty map', () {
|
||||
expect(converter.fromSql(''), <String, dynamic>{});
|
||||
expect(converter.fromSql('{not json'), <String, dynamic>{});
|
||||
expect(converter.fromSql('[1, 2]'), <String, dynamic>{});
|
||||
expect(converter.fromSql('"kg"'), <String, dynamic>{});
|
||||
expect(converter.fromSql('42'), <String, dynamic>{});
|
||||
});
|
||||
});
|
||||
|
||||
group('extra_data through the Drift database', () {
|
||||
late DriftPowersyncDatabase db;
|
||||
|
||||
setUp(() async {
|
||||
db = await openTestDatabase();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
await db.close();
|
||||
});
|
||||
|
||||
test('a written map survives the roundtrip', () async {
|
||||
await db
|
||||
.into(db.measurementEntryTable)
|
||||
.insert(
|
||||
MeasurementEntryTableCompanion(
|
||||
id: const Value('e-1'),
|
||||
categoryId: const Value('c-1'),
|
||||
date: Value(DateTime.utc(2026, 1, 1)),
|
||||
value: const Value(80.5),
|
||||
notes: const Value(''),
|
||||
extraData: const Value({'unit': 'lb', 'source_unit': 'lb'}),
|
||||
),
|
||||
);
|
||||
|
||||
final row = await db.select(db.measurementEntryTable).getSingle();
|
||||
expect(row.extraData, {'unit': 'lb', 'source_unit': 'lb'});
|
||||
});
|
||||
|
||||
test('text written by PowerSync is decoded on read', () async {
|
||||
// PowerSync syncs JSON columns as raw text, bypassing the converter
|
||||
await db.customStatement(
|
||||
'INSERT INTO measurements_measurement '
|
||||
'(id, category_id, date, value, notes, source, extra_data) '
|
||||
"VALUES ('e-2', 'c-1', '2026-01-01T00:00:00.000Z', 80.5, '', 'user', '{\"unit\": \"kg\"}')",
|
||||
);
|
||||
|
||||
final row = await db.select(db.measurementEntryTable).getSingle();
|
||||
expect(row.extraData, {'unit': 'kg'});
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user