mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
105 lines
3.8 KiB
Dart
105 lines
3.8 KiB
Dart
/*
|
|
* This file is part of wger Workout Manager <https://github.com/wger-project>.
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:mockito/annotations.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:wger/providers/auth.dart';
|
|
import 'package:wger/providers/base_provider.dart';
|
|
import 'package:wger/providers/body_weight.dart';
|
|
import 'package:wger/providers/nutrition.dart';
|
|
import 'package:wger/screens/nutritional_plan_screen.dart';
|
|
import 'package:wger/widgets/nutrition/charts.dart';
|
|
|
|
import '../../test_data/nutritional_plans.dart';
|
|
import 'nutritional_plan_screen_test.mocks.dart';
|
|
|
|
@GenerateMocks([WgerBaseProvider, AuthProvider, http.Client])
|
|
void main() {
|
|
Widget createNutritionalPlan({locale = 'en'}) {
|
|
final key = GlobalKey<NavigatorState>();
|
|
final client = MockClient();
|
|
final mockBaseProvider = MockWgerBaseProvider();
|
|
final mockAuthProvider = MockAuthProvider();
|
|
|
|
final plan = getNutritionalPlan();
|
|
|
|
return MultiProvider(
|
|
providers: [
|
|
ChangeNotifierProvider<NutritionPlansProvider>(
|
|
create: (context) => NutritionPlansProvider(mockAuthProvider, [], client),
|
|
),
|
|
ChangeNotifierProvider<BodyWeightProvider>(
|
|
create: (context) => BodyWeightProvider(mockBaseProvider),
|
|
),
|
|
],
|
|
child: MaterialApp(
|
|
locale: Locale(locale),
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
navigatorKey: key,
|
|
home: TextButton(
|
|
onPressed: () => key.currentState!.push(
|
|
MaterialPageRoute<void>(
|
|
settings: RouteSettings(arguments: plan),
|
|
builder: (_) => NutritionalPlanScreen(),
|
|
),
|
|
),
|
|
child: const SizedBox(),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
testWidgets('Test the widgets on the nutritional plan screen', (WidgetTester tester) async {
|
|
await tester.pumpWidget(createNutritionalPlan());
|
|
await tester.tap(find.byType(TextButton));
|
|
await tester.pumpAndSettle();
|
|
|
|
// PLan description
|
|
expect(find.text('Less fat, more protein'), findsOneWidget);
|
|
|
|
// Ingredients
|
|
expect(find.text('100g Water'), findsOneWidget);
|
|
expect(find.text('75g Burger soup'), findsOneWidget);
|
|
expect(find.text('300g Broccoli cake'), findsOneWidget);
|
|
|
|
expect(find.byType(Dismissible), findsNWidgets(2));
|
|
expect(find.byType(NutritionalDiaryChartWidget), findsNothing);
|
|
});
|
|
|
|
testWidgets('Tests the localization of times - EN', (WidgetTester tester) async {
|
|
await tester.pumpWidget(createNutritionalPlan());
|
|
await tester.tap(find.byType(TextButton));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('5:00 PM'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('Tests the localization of times - DE', (WidgetTester tester) async {
|
|
await tester.pumpWidget(createNutritionalPlan(locale: 'de'));
|
|
await tester.tap(find.byType(TextButton));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('17:00'), findsOneWidget);
|
|
});
|
|
}
|