mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Previously due to rebuilds the form would e.g. not stay open after selecting a new unit (which would also not change)
105 lines
3.5 KiB
Dart
105 lines
3.5 KiB
Dart
/*
|
|
* This file is part of wger Workout Manager <https://github.com/wger-project>.
|
|
* Copyright (c) 2020 - 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:mockito/annotations.dart';
|
|
import 'package:mockito/mockito.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:wger/l10n/generated/app_localizations.dart';
|
|
import 'package:wger/models/workouts/repetition_unit.dart';
|
|
import 'package:wger/models/workouts/slot_entry.dart';
|
|
import 'package:wger/providers/routines.dart';
|
|
import 'package:wger/screens/routine_screen.dart';
|
|
import 'package:wger/widgets/routines/forms/reps_unit.dart';
|
|
|
|
import 'repetition_unit_form_widget_test.mocks.dart';
|
|
|
|
@GenerateMocks([RoutinesProvider])
|
|
void main() {
|
|
var mockWorkoutPlans = MockRoutinesProvider();
|
|
const unit1 = RepetitionUnit(id: 1, name: 'some rep unit');
|
|
const unit2 = RepetitionUnit(id: 2, name: 'another name');
|
|
const unit3 = RepetitionUnit(id: 3, name: 'this is repetition number 3');
|
|
|
|
RepetitionUnit? result;
|
|
|
|
final slotEntry = SlotEntry(
|
|
slotId: 1,
|
|
exerciseId: 1,
|
|
repetitionUnitId: 1,
|
|
repetitionRounding: 0.25,
|
|
weightUnitId: 1,
|
|
weightRounding: 0.25,
|
|
comment: 'comment',
|
|
);
|
|
slotEntry.repetitionUnitObj = unit1;
|
|
|
|
setUp(() {
|
|
mockWorkoutPlans = MockRoutinesProvider();
|
|
result = null;
|
|
when(mockWorkoutPlans.repetitionUnits).thenAnswer((_) => [unit1, unit2, unit3]);
|
|
});
|
|
|
|
Widget renderWidget() {
|
|
final key = GlobalKey<NavigatorState>();
|
|
|
|
return ChangeNotifierProvider<RoutinesProvider>(
|
|
create: (context) => mockWorkoutPlans,
|
|
child: MaterialApp(
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
navigatorKey: key,
|
|
home: Scaffold(
|
|
body: RepetitionUnitInputWidget(
|
|
unit1,
|
|
onChanged: (value) => result = value,
|
|
),
|
|
),
|
|
routes: {RoutineScreen.routeName: (ctx) => const RoutineScreen()},
|
|
),
|
|
);
|
|
}
|
|
|
|
testWidgets('Test that the entries are shown', (WidgetTester tester) async {
|
|
// arrange
|
|
await tester.pumpWidget(renderWidget());
|
|
await tester.tap(find.byKey(const Key('1')));
|
|
await tester.pump();
|
|
|
|
// assert
|
|
expect(find.text('some rep unit'), findsWidgets);
|
|
expect(find.text('another name'), findsWidgets);
|
|
expect(find.text('this is repetition number 3'), findsWidgets);
|
|
});
|
|
|
|
testWidgets('Test that the correct units are set after selection', (WidgetTester tester) async {
|
|
// arrange
|
|
await tester.pumpWidget(renderWidget());
|
|
await tester.pump();
|
|
|
|
// act
|
|
await tester.tap(find.byKey(const Key('1')));
|
|
await tester.pump();
|
|
await tester.tap(find.text('another name').last);
|
|
|
|
// assert
|
|
expect(result, equals(unit2));
|
|
});
|
|
}
|