Rename files so they match the ones they test

This commit is contained in:
Roland Geider
2026-07-17 17:38:50 +02:00
parent 432d9f1dde
commit b6c83ff37f
10 changed files with 660 additions and 464 deletions

View File

@@ -1,72 +1,69 @@
/*
* 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/material.dart';
import 'package:flutter_test/flutter_test.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/categories_card.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import '../../../../test_data/measurements.dart';
Widget _wrap(Widget child) => MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
routes: {
'/form': (ctx) => const Scaffold(body: Text('form screen')),
},
home: Scaffold(body: child),
);
MeasurementCategory _bpGroup({bool withEntries = false}) {
final sysEntries = withEntries ? [testNeasurementEntry9] : <MeasurementEntry>[];
final diaEntries = withEntries ? [testNeasurementEntry10] : <MeasurementEntry>[];
final sys = testMeasurementCategorySystolic.copyWith(entries: sysEntries);
final dia = testMeasurementCategoryDiastolic.copyWith(entries: diaEntries);
return testMeasurementCategoryBloodPressure.copyWith(children: [sys, dia]);
}
void main() {
group('CategoriesCard — group card', () {
testWidgets('shows one ListTile per child with latest reading', (tester) async {
await tester.pumpWidget(_wrap(CategoriesCard(_bpGroup(withEntries: true))));
await tester.pumpAndSettle();
expect(find.byType(ListTile), findsNWidgets(2));
expect(find.textContaining('120'), findsOneWidget);
expect(find.textContaining('80'), findsOneWidget);
});
testWidgets('shows dash when child has no entries', (tester) async {
await tester.pumpWidget(_wrap(CategoriesCard(_bpGroup(withEntries: false))));
await tester.pumpAndSettle();
// Text('—') should appear for both children
expect(find.text('—'), findsNWidgets(2));
});
testWidgets('add icon button is present on group card', (tester) async {
await tester.pumpWidget(_wrap(CategoriesCard(_bpGroup())));
await tester.pumpAndSettle();
expect(find.byIcon(Icons.add), findsOneWidget);
});
});
}
/*
* 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/material.dart';
import 'package:flutter_test/flutter_test.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/categories_card.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import '../../../../test_data/measurements.dart';
Widget _wrap(Widget child) => MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(body: child),
);
MeasurementCategory _bpGroup({bool withEntries = false}) {
final sysEntries = withEntries ? [testNeasurementEntry9] : <MeasurementEntry>[];
final diaEntries = withEntries ? [testNeasurementEntry10] : <MeasurementEntry>[];
final sys = testMeasurementCategorySystolic.copyWith(entries: sysEntries);
final dia = testMeasurementCategoryDiastolic.copyWith(entries: diaEntries);
return testMeasurementCategoryBloodPressure.copyWith(children: [sys, dia]);
}
void main() {
group('CategoriesCard group card', () {
testWidgets('shows one ListTile per child with latest reading', (tester) async {
await tester.pumpWidget(_wrap(CategoriesCard(_bpGroup(withEntries: true))));
await tester.pumpAndSettle();
expect(find.byType(ListTile), findsNWidgets(2));
expect(find.textContaining('120'), findsOneWidget);
expect(find.textContaining('80'), findsOneWidget);
});
testWidgets('shows dash when child has no entries', (tester) async {
await tester.pumpWidget(_wrap(CategoriesCard(_bpGroup(withEntries: false))));
await tester.pumpAndSettle();
// Text('—') should appear for both children
expect(find.text('—'), findsNWidgets(2));
});
testWidgets('add icon button is present on group card', (tester) async {
await tester.pumpWidget(_wrap(CategoriesCard(_bpGroup())));
await tester.pumpAndSettle();
expect(find.byIcon(Icons.add), findsOneWidget);
});
});
}

View File

@@ -1,65 +1,86 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:wger/features/measurements/providers/measurement_repository.dart';
import 'package:wger/features/measurements/widgets/categories.dart';
import 'package:wger/features/measurements/widgets/categories_card.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import '../../../../test_data/measurements.dart';
import '../providers/measurement_notifier_test.mocks.dart';
Widget _wrap(MockMeasurementRepository mockRepo) {
return ProviderScope(
overrides: [
measurementRepositoryProvider.overrideWithValue(mockRepo),
],
child: const MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(body: CategoriesList()),
),
);
}
void main() {
late MockMeasurementRepository mockRepo;
setUp(() {
mockRepo = MockMeasurementRepository();
});
group('CategoriesList', () {
testWidgets('two top-level categories render two CategoriesCard widgets', (tester) async {
when(mockRepo.watchAll()).thenAnswer((_) => Stream.value(getMeasurementCategories()));
await tester.pumpWidget(_wrap(mockRepo));
await tester.pumpAndSettle();
expect(find.byType(CategoriesCard), findsNWidgets(2));
});
testWidgets(' children of multi-value groups are not rendered as own list items', (
tester,
) async {
// Only 'bp' should produce a CategoriesCard; children stay inside it.
when(mockRepo.watchAll()).thenAnswer((_) => Stream.value(getBloodPressureGroup()));
await tester.pumpWidget(_wrap(mockRepo));
await tester.pumpAndSettle();
expect(find.byType(CategoriesCard), findsOneWidget);
expect(find.text('Systolic'), findsOneWidget);
expect(find.text('Diastolic'), findsOneWidget);
});
testWidgets('empty list renders no CategoriesCard', (tester) async {
when(mockRepo.watchAll()).thenAnswer((_) => Stream.value([]));
await tester.pumpWidget(_wrap(mockRepo));
await tester.pumpAndSettle();
expect(find.byType(CategoriesCard), findsNothing);
});
});
}
/*
* 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/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:wger/features/measurements/providers/measurement_repository.dart';
import 'package:wger/features/measurements/widgets/categories.dart';
import 'package:wger/features/measurements/widgets/categories_card.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import '../../../../test_data/measurements.dart';
import 'categories_test.mocks.dart';
Widget _wrap(MockMeasurementRepository mockRepo) {
return ProviderScope(
overrides: [
measurementRepositoryProvider.overrideWithValue(mockRepo),
],
child: const MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(body: CategoriesList()),
),
);
}
@GenerateMocks([MeasurementRepository])
void main() {
late MockMeasurementRepository mockRepo;
setUp(() {
mockRepo = MockMeasurementRepository();
});
group('CategoriesList', () {
testWidgets('two top-level categories render two CategoriesCard widgets', (tester) async {
when(mockRepo.watchAll()).thenAnswer((_) => Stream.value(getMeasurementCategories()));
await tester.pumpWidget(_wrap(mockRepo));
await tester.pumpAndSettle();
expect(find.byType(CategoriesCard), findsNWidgets(2));
});
testWidgets('children of multi-value groups are not rendered as own list items', (
tester,
) async {
// Only 'bp' should produce a CategoriesCard; children stay inside it.
when(mockRepo.watchAll()).thenAnswer((_) => Stream.value(getBloodPressureGroup()));
await tester.pumpWidget(_wrap(mockRepo));
await tester.pumpAndSettle();
expect(find.byType(CategoriesCard), findsOneWidget);
expect(find.text('Systolic'), findsOneWidget);
expect(find.text('Diastolic'), findsOneWidget);
});
testWidgets('empty list renders no CategoriesCard', (tester) async {
when(mockRepo.watchAll()).thenAnswer((_) => Stream.value([]));
await tester.pumpWidget(_wrap(mockRepo));
await tester.pumpAndSettle();
expect(find.byType(CategoriesCard), findsNothing);
});
});
}

View File

@@ -0,0 +1,139 @@
// Mocks generated by Mockito 5.4.6 from annotations
// in wger/test/features/measurements/widgets/categories_test.dart.
// Do not manually edit this file.
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i3;
import 'package:mockito/mockito.dart' as _i1;
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;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
// ignore_for_file: avoid_setters_without_getters
// ignore_for_file: comment_references
// ignore_for_file: deprecated_member_use
// ignore_for_file: deprecated_member_use_from_same_package
// ignore_for_file: implementation_imports
// ignore_for_file: invalid_use_of_visible_for_testing_member
// ignore_for_file: must_be_immutable
// ignore_for_file: prefer_const_constructors
// ignore_for_file: unnecessary_parenthesis
// ignore_for_file: camel_case_types
// ignore_for_file: subtype_of_sealed_class
// ignore_for_file: invalid_use_of_internal_member
/// A class which mocks [MeasurementRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepository {
MockMeasurementRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i3.Stream<List<_i4.MeasurementCategory>> watchAll() =>
(super.noSuchMethod(
Invocation.method(#watchAll, []),
returnValue: _i3.Stream<List<_i4.MeasurementCategory>>.empty(),
)
as _i3.Stream<List<_i4.MeasurementCategory>>);
@override
_i3.Stream<_i4.MeasurementCategory?> watchLocalDriftCategoryById(
String? id,
) =>
(super.noSuchMethod(
Invocation.method(#watchLocalDriftCategoryById, [id]),
returnValue: _i3.Stream<_i4.MeasurementCategory?>.empty(),
)
as _i3.Stream<_i4.MeasurementCategory?>);
@override
_i3.Future<List<_i4.MeasurementCategory>> getAllOnce() =>
(super.noSuchMethod(
Invocation.method(#getAllOnce, []),
returnValue: _i3.Future<List<_i4.MeasurementCategory>>.value(
<_i4.MeasurementCategory>[],
),
)
as _i3.Future<List<_i4.MeasurementCategory>>);
@override
_i3.Future<void> deleteLocalDrift(String? id) =>
(super.noSuchMethod(
Invocation.method(#deleteLocalDrift, [id]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
@override
_i3.Future<void> updateLocalDrift(_i5.MeasurementEntry? entry) =>
(super.noSuchMethod(
Invocation.method(#updateLocalDrift, [entry]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
@override
_i3.Future<void> addLocalDrift(_i5.MeasurementEntry? entry) =>
(super.noSuchMethod(
Invocation.method(#addLocalDrift, [entry]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
@override
_i3.Future<void> addLocalDriftGroupEntries(
List<_i5.MeasurementEntry>? entries,
) =>
(super.noSuchMethod(
Invocation.method(#addLocalDriftGroupEntries, [entries]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
@override
_i3.Future<void> deleteLocalDriftCategory(String? id) =>
(super.noSuchMethod(
Invocation.method(#deleteLocalDriftCategory, [id]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
@override
_i3.Future<void> updateLocalDriftCategory(
_i4.MeasurementCategory? category,
) =>
(super.noSuchMethod(
Invocation.method(#updateLocalDriftCategory, [category]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
@override
_i3.Future<void> addLocalDriftCategory(_i4.MeasurementCategory? category) =>
(super.noSuchMethod(
Invocation.method(#addLocalDriftCategory, [category]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
@override
_i3.Future<void> reorderCategories(List<String>? orderedIds) =>
(super.noSuchMethod(
Invocation.method(#reorderCategories, [orderedIds]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
}

View File

@@ -43,7 +43,6 @@ void main() {
expect(tester.takeException(), isNull);
});
// T-24
testWidgets('BarChart is present for non-empty entries', (tester) async {
final entries = [
entry(1000, DateTime(2026, 1, 1)),
@@ -55,12 +54,14 @@ void main() {
expect(find.byType(BarChart), findsOneWidget);
});
});
test('aggregatePerDay returns an empty list for no entries', () {
group('aggregatePerDay', () {
test('returns an empty list for no entries', () {
expect(aggregatePerDay([]), isEmpty);
});
test('aggregatePerDay sums entries sharing a calendar day into one point', () {
test('sums entries sharing a calendar day into one point', () {
final result = aggregatePerDay([
entry(1000, DateTime(2026, 1, 1, 8)),
entry(2500, DateTime(2026, 1, 1, 20)),

View File

@@ -19,41 +19,46 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:wger/core/widgets/decimal_input.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';
import 'package:wger/features/measurements/widgets/forms.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import '../../../../test_data/measurements.dart';
import '../providers/measurement_notifier_test.mocks.dart';
Widget _wrap(Widget child, MockMeasurementRepository mockRepo) {
return ProviderScope(
overrides: [
measurementRepositoryProvider.overrideWithValue(mockRepo),
],
child: MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: SingleChildScrollView(child: child),
),
),
);
}
import 'forms_test.mocks.dart';
@GenerateMocks([MeasurementRepository])
void main() {
late MockMeasurementRepository mockRepo;
setUp(() {
mockRepo = MockMeasurementRepository();
when(mockRepo.watchAll()).thenAnswer((_) => Stream.value([]));
when(mockRepo.addLocalDriftGroupEntries(any)).thenAnswer((_) async {});
});
Widget wrap(Widget child) {
return ProviderScope(
overrides: [
measurementRepositoryProvider.overrideWithValue(mockRepo),
],
child: MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: SingleChildScrollView(child: child),
),
),
);
}
group('MeasurementCategoryForm validation', () {
testWidgets('empty name fails validation', (tester) async {
await tester.pumpWidget(_wrap(const MeasurementCategoryForm(), mockRepo));
await tester.pumpWidget(wrap(const MeasurementCategoryForm()));
await tester.pumpAndSettle();
// Tap save without entering any text
@@ -71,7 +76,7 @@ void main() {
});
testWidgets('empty unit field fails validation', (tester) async {
await tester.pumpWidget(_wrap(const MeasurementCategoryForm(), mockRepo));
await tester.pumpWidget(wrap(const MeasurementCategoryForm()));
await tester.pumpAndSettle();
// Fill name but leave unit empty
@@ -84,17 +89,15 @@ void main() {
});
testWidgets('metricType dropdown renders all MetricType values', (tester) async {
await tester.pumpWidget(_wrap(const MeasurementCategoryForm(), mockRepo));
await tester.pumpWidget(wrap(const MeasurementCategoryForm()));
await tester.pumpAndSettle();
// Open the dropdown
await tester.tap(find.byType(DropdownButtonFormField<MetricType>));
await tester.pumpAndSettle();
// We expect N + 1 items here because when the dropdown is opened:
// 1. The initialValue is still displayed on the form background as a DropdownMenuItem.
// 2. The opened menu overlay displays all 6 total MetricType options.
// Total = 1 (background label) + 6 (popup menu options) = 7 widgets.
// The initialValue stays visible on the form behind the opened menu
// overlay, which shows every MetricType option once.
expect(
find.byType(DropdownMenuItem<MetricType>),
findsNWidgets(MetricType.values.length + 1),
@@ -104,11 +107,58 @@ void main() {
testWidgets('editing existing category pre-fills name and unit', (tester) async {
final existing = getMeasurementCategories()[1];
await tester.pumpWidget(_wrap(MeasurementCategoryForm(existing), mockRepo));
await tester.pumpWidget(wrap(MeasurementCategoryForm(existing)));
await tester.pumpAndSettle();
expect(find.widgetWithText(TextFormField, 'Biceps'), findsOneWidget);
expect(find.widgetWithText(TextFormField, 'cm'), findsOneWidget);
});
});
group('GroupMeasurementEntryForm', () {
testWidgets('renders one DecimalInputWidget per child component', (tester) async {
await tester.pumpWidget(
wrap(GroupMeasurementEntryForm(testMeasurementCategoryBloodPressure)),
);
await tester.pumpAndSettle();
expect(find.byType(DecimalInputWidget), findsNWidgets(2));
});
testWidgets('empty value fields fail validation', (tester) async {
await tester.pumpWidget(
wrap(GroupMeasurementEntryForm(testMeasurementCategoryBloodPressure)),
);
await tester.pumpAndSettle();
// Tap save without entering values
await tester.tap(find.byType(ElevatedButton));
await tester.pumpAndSettle();
// Form does not pop
expect(find.byType(GroupMeasurementEntryForm), findsOneWidget);
verifyNever(mockRepo.addLocalDriftGroupEntries(any));
});
testWidgets('valid submission adds one entry per component, sharing the date', (tester) async {
await tester.pumpWidget(
wrap(GroupMeasurementEntryForm(testMeasurementCategoryBloodPressure)),
);
await tester.pumpAndSettle();
final fields = find.byType(TextFormField);
// Fields: date, time, systolic value, diastolic value
await tester.enterText(fields.at(2), '120');
await tester.enterText(fields.at(3), '80');
await tester.tap(find.byType(ElevatedButton));
await tester.pumpAndSettle();
final entries =
verify(mockRepo.addLocalDriftGroupEntries(captureAny)).captured.single
as List<MeasurementEntry>;
expect(entries.map((e) => (e.categoryId, e.value)), [('sys', 120), ('dia', 80)]);
expect(entries.first.date, entries.last.date);
});
});
}

View File

@@ -0,0 +1,139 @@
// Mocks generated by Mockito 5.4.6 from annotations
// in wger/test/features/measurements/widgets/forms_test.dart.
// Do not manually edit this file.
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i3;
import 'package:mockito/mockito.dart' as _i1;
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;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
// ignore_for_file: avoid_setters_without_getters
// ignore_for_file: comment_references
// ignore_for_file: deprecated_member_use
// ignore_for_file: deprecated_member_use_from_same_package
// ignore_for_file: implementation_imports
// ignore_for_file: invalid_use_of_visible_for_testing_member
// ignore_for_file: must_be_immutable
// ignore_for_file: prefer_const_constructors
// ignore_for_file: unnecessary_parenthesis
// ignore_for_file: camel_case_types
// ignore_for_file: subtype_of_sealed_class
// ignore_for_file: invalid_use_of_internal_member
/// A class which mocks [MeasurementRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockMeasurementRepository extends _i1.Mock implements _i2.MeasurementRepository {
MockMeasurementRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i3.Stream<List<_i4.MeasurementCategory>> watchAll() =>
(super.noSuchMethod(
Invocation.method(#watchAll, []),
returnValue: _i3.Stream<List<_i4.MeasurementCategory>>.empty(),
)
as _i3.Stream<List<_i4.MeasurementCategory>>);
@override
_i3.Stream<_i4.MeasurementCategory?> watchLocalDriftCategoryById(
String? id,
) =>
(super.noSuchMethod(
Invocation.method(#watchLocalDriftCategoryById, [id]),
returnValue: _i3.Stream<_i4.MeasurementCategory?>.empty(),
)
as _i3.Stream<_i4.MeasurementCategory?>);
@override
_i3.Future<List<_i4.MeasurementCategory>> getAllOnce() =>
(super.noSuchMethod(
Invocation.method(#getAllOnce, []),
returnValue: _i3.Future<List<_i4.MeasurementCategory>>.value(
<_i4.MeasurementCategory>[],
),
)
as _i3.Future<List<_i4.MeasurementCategory>>);
@override
_i3.Future<void> deleteLocalDrift(String? id) =>
(super.noSuchMethod(
Invocation.method(#deleteLocalDrift, [id]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
@override
_i3.Future<void> updateLocalDrift(_i5.MeasurementEntry? entry) =>
(super.noSuchMethod(
Invocation.method(#updateLocalDrift, [entry]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
@override
_i3.Future<void> addLocalDrift(_i5.MeasurementEntry? entry) =>
(super.noSuchMethod(
Invocation.method(#addLocalDrift, [entry]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
@override
_i3.Future<void> addLocalDriftGroupEntries(
List<_i5.MeasurementEntry>? entries,
) =>
(super.noSuchMethod(
Invocation.method(#addLocalDriftGroupEntries, [entries]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
@override
_i3.Future<void> deleteLocalDriftCategory(String? id) =>
(super.noSuchMethod(
Invocation.method(#deleteLocalDriftCategory, [id]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
@override
_i3.Future<void> updateLocalDriftCategory(
_i4.MeasurementCategory? category,
) =>
(super.noSuchMethod(
Invocation.method(#updateLocalDriftCategory, [category]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
@override
_i3.Future<void> addLocalDriftCategory(_i4.MeasurementCategory? category) =>
(super.noSuchMethod(
Invocation.method(#addLocalDriftCategory, [category]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
@override
_i3.Future<void> reorderCategories(List<String>? orderedIds) =>
(super.noSuchMethod(
Invocation.method(#reorderCategories, [orderedIds]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
}

View File

@@ -1,135 +0,0 @@
/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* Copyright (c) 2026 - 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/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:wger/features/measurements/models/measurement_category.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';
void main() {
final rawEntries = [
MeasurementChartEntry(10, DateTime(2026, 1, 1)),
MeasurementChartEntry(20, DateTime(2026, 1, 10)),
];
final avgEntries = moving7dAverage(rawEntries);
group('getOverviewWidgets', () {
testWidgets('empty raw shows no-data placeholder', (tester) async {
late List<Widget> widgets;
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Builder(
builder: (ctx) {
widgets = getOverviewWidgets('Test', [], [], 'cm', ctx);
return Scaffold(
body: SingleChildScrollView(child: Column(children: widgets)),
);
},
),
),
);
await tester.pumpAndSettle();
expect(find.text('No data available'), findsOneWidget);
});
testWidgets('non-empty avg includes MeasurementOverallChangeWidget', (tester) async {
late List<Widget> widgets;
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Builder(
builder: (ctx) {
widgets = getOverviewWidgets('Test', rawEntries, avgEntries, 'cm', ctx);
return Scaffold(
body: SingleChildScrollView(child: Column(children: widgets)),
);
},
),
),
);
await tester.pumpAndSettle();
expect(find.byType(MeasurementOverallChangeWidget), findsOneWidget);
});
});
group('getOverviewWidgetsSeries — Indicator legend', () {
testWidgets('three Indicator widgets for non-summed metric (custom)', (tester) async {
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Builder(
builder: (ctx) {
final widgets = getOverviewWidgetsSeries(
'Weight',
rawEntries,
avgEntries,
[],
'kg',
ctx,
metricType: MetricType.custom,
);
return Scaffold(
body: SingleChildScrollView(child: Column(children: widgets)),
);
},
),
),
);
await tester.pumpAndSettle();
expect(find.byType(Indicator), findsNWidgets(3));
});
testWidgets('two Indicator widgets for summed metric (steps — no trend)', (tester) async {
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Builder(
builder: (ctx) {
final widgets = getOverviewWidgetsSeries(
'Steps',
rawEntries,
avgEntries,
[],
'steps',
ctx,
metricType: MetricType.steps,
);
return Scaffold(
body: SingleChildScrollView(child: Column(children: widgets)),
);
},
),
),
);
await tester.pumpAndSettle();
// isSummedPerDay -> trend indicator is hidden
expect(find.byType(Indicator), findsNWidgets(2));
});
});
}

View File

@@ -1,96 +0,0 @@
/*
* 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/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:wger/core/widgets/decimal_input.dart';
import 'package:wger/features/measurements/providers/measurement_repository.dart';
import 'package:wger/features/measurements/widgets/forms.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import '../../../../test_data/measurements.dart';
import '../providers/measurement_notifier_test.mocks.dart';
Widget _wrap(MockMeasurementRepository mockRepo) {
return ProviderScope(
overrides: [
measurementRepositoryProvider.overrideWithValue(mockRepo),
],
child: MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: SingleChildScrollView(
child: GroupMeasurementEntryForm(testMeasurementCategoryBloodPressure),
),
),
),
);
}
void main() {
late MockMeasurementRepository mockRepo;
setUp(() {
mockRepo = MockMeasurementRepository();
when(mockRepo.watchAll()).thenAnswer((_) => Stream.value([]));
when(mockRepo.addLocalDriftGroupEntries(any)).thenAnswer((_) async {});
});
group('GroupMeasurementEntryForm', () {
testWidgets('renders one DecimalInputWidget per child component', (tester) async {
await tester.pumpWidget(_wrap(mockRepo));
await tester.pumpAndSettle();
expect(find.byType(DecimalInputWidget), findsNWidgets(2));
});
testWidgets('empty value fields fail validation', (tester) async {
await tester.pumpWidget(_wrap(mockRepo));
await tester.pumpAndSettle();
// Tap save without entering values
await tester.tap(find.byType(ElevatedButton));
await tester.pumpAndSettle();
// Form doesnot pop
expect(find.byType(GroupMeasurementEntryForm), findsOneWidget);
});
testWidgets('valid submission calls addGroupEntries with correct count', (tester) async {
await tester.pumpWidget(_wrap(mockRepo));
await tester.pumpAndSettle();
final fields = find.byType(TextFormField);
// Fields : Date, Time, Systolic value, Diastolic value
await tester.enterText(fields.at(2), '120');
await tester.enterText(fields.at(3), '80');
await tester.tap(find.byType(ElevatedButton));
await tester.pumpAndSettle();
verify(
mockRepo.addLocalDriftGroupEntries(
argThat(hasLength(2)),
),
).called(1);
});
});
}

View File

@@ -1,67 +1,146 @@
/*
* 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/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:wger/features/measurements/models/measurement_category.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';
Widget _wrapChart(Widget chart) => MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: SizedBox(width: 400, height: 300, child: chart),
),
);
void main() {
final entries = [
MeasurementChartEntry(1000, DateTime(2026, 1, 1)),
MeasurementChartEntry(2000, DateTime(2026, 1, 2)),
];
group('buildChartForMetricType routing', () {
testWidgets('steps -> MeasurementBarChartWidgetFl', (tester) async {
final widget = buildChartForMetricType(MetricType.steps, entries, [], 'steps');
await tester.pumpWidget(_wrapChart(widget));
await tester.pumpAndSettle();
expect(find.byType(MeasurementBarChartWidgetFl), findsOneWidget);
expect(find.byType(MeasurementChartWidgetFl), findsNothing);
});
testWidgets('custom -> MeasurementChartWidgetFl', (tester) async {
final widget = buildChartForMetricType(MetricType.custom, entries, [], 'cm');
await tester.pumpWidget(_wrapChart(widget));
await tester.pumpAndSettle();
expect(find.byType(MeasurementChartWidgetFl), findsOneWidget);
expect(find.byType(MeasurementBarChartWidgetFl), findsNothing);
});
testWidgets('energy -> MeasurementBarChartWidgetFl', (tester) async {
final widget = buildChartForMetricType(MetricType.energy, entries, [], 'kcal');
await tester.pumpWidget(_wrapChart(widget));
await tester.pumpAndSettle();
expect(find.byType(MeasurementBarChartWidgetFl), findsOneWidget);
});
});
}
/*
* 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/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:wger/features/measurements/models/measurement_category.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';
Widget _wrapChart(Widget chart) => MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: SizedBox(width: 400, height: 300, child: chart),
),
);
/// Pumps a MaterialApp whose body is the widget list built by [builder].
Future<void> _pumpWidgetList(
WidgetTester tester,
List<Widget> Function(BuildContext context) builder,
) async {
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Builder(
builder: (ctx) => Scaffold(
body: SingleChildScrollView(child: Column(children: builder(ctx))),
),
),
),
);
await tester.pumpAndSettle();
}
void main() {
final rawEntries = [
MeasurementChartEntry(10, DateTime(2026, 1, 1)),
MeasurementChartEntry(20, DateTime(2026, 1, 10)),
];
final avgEntries = moving7dAverage(rawEntries);
group('buildChartForMetricType routing', () {
final entries = [
MeasurementChartEntry(1000, DateTime(2026, 1, 1)),
MeasurementChartEntry(2000, DateTime(2026, 1, 2)),
];
testWidgets('steps -> MeasurementBarChartWidgetFl', (tester) async {
final widget = buildChartForMetricType(MetricType.steps, entries, [], 'steps');
await tester.pumpWidget(_wrapChart(widget));
await tester.pumpAndSettle();
expect(find.byType(MeasurementBarChartWidgetFl), findsOneWidget);
expect(find.byType(MeasurementChartWidgetFl), findsNothing);
});
testWidgets('custom -> MeasurementChartWidgetFl', (tester) async {
final widget = buildChartForMetricType(MetricType.custom, entries, [], 'cm');
await tester.pumpWidget(_wrapChart(widget));
await tester.pumpAndSettle();
expect(find.byType(MeasurementChartWidgetFl), findsOneWidget);
expect(find.byType(MeasurementBarChartWidgetFl), findsNothing);
});
testWidgets('energy -> MeasurementBarChartWidgetFl', (tester) async {
final widget = buildChartForMetricType(MetricType.energy, entries, [], 'kcal');
await tester.pumpWidget(_wrapChart(widget));
await tester.pumpAndSettle();
expect(find.byType(MeasurementBarChartWidgetFl), findsOneWidget);
});
});
group('getOverviewWidgets', () {
testWidgets('empty raw shows no-data placeholder', (tester) async {
await _pumpWidgetList(tester, (ctx) => getOverviewWidgets('Test', [], [], 'cm', ctx));
expect(find.text('No data available'), findsOneWidget);
});
testWidgets('non-empty avg includes MeasurementOverallChangeWidget', (tester) async {
await _pumpWidgetList(
tester,
(ctx) => getOverviewWidgets('Test', rawEntries, avgEntries, 'cm', ctx),
);
expect(find.byType(MeasurementOverallChangeWidget), findsOneWidget);
});
});
group('getOverviewWidgetsSeries legend', () {
testWidgets('three Indicator widgets for non-summed metric (custom)', (tester) async {
await _pumpWidgetList(
tester,
(ctx) => getOverviewWidgetsSeries(
'Weight',
rawEntries,
avgEntries,
[],
'kg',
ctx,
metricType: MetricType.custom,
),
);
expect(find.byType(Indicator), findsNWidgets(3));
});
testWidgets('two Indicator widgets for summed metric (steps, no trend)', (tester) async {
await _pumpWidgetList(
tester,
(ctx) => getOverviewWidgetsSeries(
'Steps',
rawEntries,
avgEntries,
[],
'steps',
ctx,
metricType: MetricType.steps,
),
);
// isSummedPerDay -> trend indicator is hidden
expect(find.byType(Indicator), findsNWidgets(2));
});
});
}

View File

@@ -119,8 +119,9 @@ final testMeasurementCategoryDiastolic = MeasurementCategory(
order: 1,
);
/// The blood pressure group as a flat list (parent first), as stored in the
/// database. Not included in [getMeasurementCategories].
/// The blood pressure group as a flat list (parent first) with the children
/// attached to the parent, matching the shape the repository's watchAll()
/// returns. Not included in [getMeasurementCategories].
List<MeasurementCategory> getBloodPressureGroup() {
return [
testMeasurementCategoryBloodPressure,