From 9b791eba8cac8be1d98352483cefa1d1d69f93eb Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Tue, 13 Apr 2021 17:50:42 +0200 Subject: [PATCH] Add simple widget test for workout plan screen --- test/workout_plan_screen_test.dart | 106 +++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 test/workout_plan_screen_test.dart diff --git a/test/workout_plan_screen_test.dart b/test/workout_plan_screen_test.dart new file mode 100644 index 00000000..f57d24a2 --- /dev/null +++ b/test/workout_plan_screen_test.dart @@ -0,0 +1,106 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (C) 2020, 2021 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. + * + * wger Workout Manager 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 . + */ + +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:provider/provider.dart'; +import 'package:wger/models/workouts/day.dart'; +import 'package:wger/models/workouts/workout_plan.dart'; +import 'package:wger/providers/workout_plans.dart'; +import 'package:wger/screens/workout_plan_screen.dart'; + +import 'base_provider_test.mocks.dart'; +import 'utils.dart'; + +void main() { + Widget createHomeScreen({locale = 'en'}) { + final key = GlobalKey(); + final client = MockClient(); + + var day = Day() + ..id = 1 + ..workoutId = 1 + ..description = 'test day 1' + ..daysOfWeek = [1, 2]; + + var day2 = Day() + ..id = 2 + ..workoutId = 1 + ..description = 'test day 2' + ..daysOfWeek = [4]; + + WorkoutPlan workout = WorkoutPlan( + id: 1, + creationDate: DateTime(2021, 01, 01), + description: 'test workout 1', + days: [day, day2], + ); + + return ChangeNotifierProvider( + create: (context) => WorkoutPlans(testAuthProvider, testExercisesProvider, [], client), + child: MaterialApp( + locale: Locale(locale), + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + navigatorKey: key, + home: TextButton( + onPressed: () => key.currentState!.push( + MaterialPageRoute( + settings: RouteSettings(arguments: workout), + builder: (_) => WorkoutPlanScreen(), + ), + ), + child: const SizedBox(), + ), + routes: { + WorkoutPlanScreen.routeName: (ctx) => WorkoutPlanScreen(), + }, + ), + ); + } + + testWidgets('Test the widgets on the nutritional plan screen', (WidgetTester tester) async { + await tester.pumpWidget(createHomeScreen()); + await tester.tap(find.byType(TextButton)); + await tester.pumpAndSettle(); + + expect(find.text('test workout 1'), findsOneWidget); + expect(find.text('test day 1'), findsOneWidget); + expect(find.text('test day 2'), findsOneWidget); + expect(find.byType(Dismissible), findsNWidgets(2)); + }); + + testWidgets('Tests the localization of times - EN', (WidgetTester tester) async { + await tester.pumpWidget(createHomeScreen()); + await tester.tap(find.byType(TextButton)); + await tester.pumpAndSettle(); + + expect(find.text('Monday, Tuesday'), findsOneWidget); + expect(find.text('Thursday'), findsOneWidget); + }); + + testWidgets('Tests the localization of times - DE', (WidgetTester tester) async { + await tester.pumpWidget(createHomeScreen(locale: 'de')); + await tester.tap(find.byType(TextButton)); + await tester.pumpAndSettle(); + + expect(find.text('Monday, Tuesday'), findsOneWidget); + expect(find.text('Thursday'), findsOneWidget); + }); +}