Files
flutter/test/routine/routine_edit_test.dart
Roland Geider 9c531a7799 Merge branch 'master' into feature/offline-mode
# Conflicts:
#	integration_test/1_dashboard.dart
#	integration_test/3_gym_mode.dart
#	ios/Podfile.lock
#	lib/database/exercises/exercise_database.dart
#	lib/database/exercises/type_converters.dart
#	lib/models/exercises/exercise.dart
#	lib/models/exercises/exercise.g.dart
#	lib/models/exercises/exercise_api.dart
#	lib/models/exercises/exercise_api.freezed.dart
#	lib/models/exercises/exercise_api.g.dart
#	lib/models/exercises/translation.dart
#	lib/models/exercises/translation.g.dart
#	lib/models/exercises/variation.dart
#	lib/providers/exercises.dart
#	lib/widgets/add_exercise/steps/step_1_basics.dart
#	lib/widgets/add_exercise/steps/step_2_variations.dart
#	lib/widgets/exercises/exercises.dart
#	lib/widgets/measurements/forms.dart
#	lib/widgets/routines/forms/slot.dart
#	pubspec.lock
#	pubspec.yaml
#	test/core/settings_test.mocks.dart
#	test/exercises/contribute_exercise_image_test.mocks.dart
#	test/exercises/contribute_exercise_test.mocks.dart
#	test/exercises/exercise_provider_load_test.dart
#	test/exercises/exercise_provider_test.dart
#	test/exercises/exercises_detail_widget_test.dart
#	test/exercises/exercises_detail_widget_test.mocks.dart
#	test/exercises/model_exercise_test.dart
#	test/measurements/measurement_entries_screen_test.dart
#	test/routine/gym_mode/gym_mode_test.dart
#	test/routine/gym_mode/gym_mode_test.mocks.dart
#	test/routine/routines_provider_test.mocks.dart
#	test/weight/weight_screen_test.mocks.dart
#	test/widgets/routines/gym_mode/log_page_test.mocks.dart
#	test_data/measurements.dart
2026-04-17 12:23:56 +02:00

110 lines
3.8 KiB
Dart

/*
* 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/l10n/generated/app_localizations.dart';
import 'package:wger/providers/routines.dart';
import 'package:wger/widgets/routines/forms/day.dart';
import 'package:wger/widgets/routines/routine_edit.dart';
import '../../test_data/routines.dart';
import 'routine_edit_test.mocks.dart';
@GenerateMocks([RoutinesRepository])
void main() {
late MockRoutinesRepository mockRoutinesRepository;
setUp(() {
mockRoutinesRepository = MockRoutinesRepository();
when(
mockRoutinesRepository.fetchAndSetRoutineFullServer(any),
).thenAnswer((_) => Future.value(getTestRoutine()));
});
testWidgets('RoutineEditScreen smoke test', (WidgetTester tester) async {
// Build the RoutineEditScreen widget with the correct arguments
await tester.pumpWidget(
ProviderScope(
overrides: [
routinesRepositoryProvider.overrideWithValue(mockRoutinesRepository),
],
child: MaterialApp(
locale: const Locale('en'),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: RoutineEdit(getTestRoutine()),
),
),
),
);
await tester.pumpAndSettle();
// Always two widgets, one in the edit list, one in the generated routine
expect(find.text('3 day workout'), findsOne, reason: 'title');
expect(
find.textContaining('This is a sample routine'),
findsNWidgets(2),
reason: 'description',
);
expect(find.text('first day'), findsNWidgets(2));
expect(find.text('chest, shoulders'), findsNWidgets(2), reason: 'description');
expect(find.text('second day'), findsNWidgets(2));
expect(find.text('legs'), findsNWidgets(2), reason: 'description');
// Edit the first day
expect(find.byElementType(DayFormWidget), findsNothing);
expect(find.byIcon(Icons.edit), findsNWidgets(2));
expect(find.byIcon(Icons.edit_off), findsNothing);
expect(find.byKey(const ValueKey('edit-day-1')), findsOne);
expect(find.byKey(const ValueKey('edit-day-2')), findsOne);
expect(find.text('is rest day'), findsNothing);
await tester.tap(find.byKey(const ValueKey('edit-day-1')));
await tester.pumpAndSettle();
expect(
find.byIcon(Icons.edit),
findsNWidgets(3),
reason: 'also for the days',
);
expect(find.byIcon(Icons.edit_off), findsOne);
expect(find.text('Is rest day'), findsOne);
expect(find.text('Exercise 1'), findsOne);
expect(
find.text('Bench press'),
findsNWidgets(2),
reason: 'resulting routine plus edit',
);
expect(find.text('Exercise 2'), findsOne);
expect(
find.text('Side raises'),
findsNWidgets(2),
reason: 'resulting routine plus edit',
);
});
}