|
| 1 | +/* |
| 2 | + * This file is part of wger Workout Manager <https://github.com/wger-project>. |
| 3 | + * Copyright (C) wger Team |
| 4 | + * |
| 5 | + * wger Workout Manager is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU Affero General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * wger Workout Manager is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU Affero General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Affero General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | + |
| 19 | +import 'package:clock/clock.dart'; |
| 20 | +import 'package:flutter/material.dart'; |
| 21 | +import 'package:flutter_test/flutter_test.dart'; |
| 22 | +import 'package:mockito/annotations.dart'; |
| 23 | +import 'package:mockito/mockito.dart'; |
| 24 | +import 'package:provider/provider.dart'; |
| 25 | +import 'package:wger/l10n/generated/app_localizations.dart'; |
| 26 | +import 'package:wger/providers/routines.dart'; |
| 27 | +import 'package:wger/widgets/routines/gym_mode/session_page.dart'; |
| 28 | + |
| 29 | +import '../../test_data/routines.dart'; |
| 30 | +import 'gym_mode_session_screen_test.mocks.dart'; |
| 31 | + |
| 32 | +@GenerateMocks([RoutinesProvider]) |
| 33 | +void main() { |
| 34 | + final mockRoutinesProvider = MockRoutinesProvider(); |
| 35 | + |
| 36 | + final testRoutine = getTestRoutine(); |
| 37 | + |
| 38 | + Widget renderSessionPage({locale = 'en'}) { |
| 39 | + return ChangeNotifierProvider<RoutinesProvider>( |
| 40 | + create: (context) => mockRoutinesProvider, |
| 41 | + child: MaterialApp( |
| 42 | + locale: Locale(locale), |
| 43 | + localizationsDelegates: AppLocalizations.localizationsDelegates, |
| 44 | + supportedLocales: AppLocalizations.supportedLocales, |
| 45 | + home: Scaffold( |
| 46 | + body: SessionPage( |
| 47 | + testRoutine, |
| 48 | + PageController(), |
| 49 | + const TimeOfDay(hour: 12, minute: 34), |
| 50 | + const {}, |
| 51 | + ), |
| 52 | + ), |
| 53 | + ), |
| 54 | + ); |
| 55 | + } |
| 56 | + |
| 57 | + testWidgets('Test that data from session is loaded', (WidgetTester tester) async { |
| 58 | + withClock(Clock.fixed(DateTime(2021, 5, 1)), () async { |
| 59 | + await tester.pumpWidget(renderSessionPage()); |
| 60 | + expect(find.text('10:00'), findsOneWidget); |
| 61 | + expect(find.text('12:34'), findsOneWidget); |
| 62 | + expect(find.text('This is a note'), findsOneWidget); |
| 63 | + final toggleButtons = tester.widget<ToggleButtons>(find.byType(ToggleButtons)); |
| 64 | + expect(toggleButtons.isSelected[2], isTrue); |
| 65 | + }); |
| 66 | + }); |
| 67 | + |
| 68 | + testWidgets('Test that correct data is send to server', (WidgetTester tester) async { |
| 69 | + withClock(Clock.fixed(DateTime(2021, 5, 1)), () async { |
| 70 | + await tester.pumpWidget(renderSessionPage()); |
| 71 | + await tester.tap(find.byKey(const ValueKey('save-button'))); |
| 72 | + final captured = verify(mockRoutinesProvider.editSession(captureAny)).captured.single; |
| 73 | + |
| 74 | + expect(captured.id, 1); |
| 75 | + expect(captured.impression, 3); |
| 76 | + expect(captured.notes, equals('This is a note')); |
| 77 | + expect(captured.timeStart, equals(const TimeOfDay(hour: 10, minute: 0))); |
| 78 | + expect(captured.timeEnd, equals(const TimeOfDay(hour: 12, minute: 34))); |
| 79 | + }); |
| 80 | + }); |
| 81 | +} |
0 commit comments