mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-02 10:09:11 +01:00
cleanup
This commit is contained in:
@@ -16,112 +16,23 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:golden_toolkit/golden_toolkit.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wger/models/nutrition/ingredient.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 '../../test_data/nutritional_plans.dart';
|
||||
import '../fixtures/fixture_reader.dart';
|
||||
import 'helper.dart';
|
||||
import 'nutritional_plan_screen_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([WgerBaseProvider, AuthProvider, http.Client])
|
||||
void main() {
|
||||
// makeUrl('nutritionplan', {id: 1, objectMethod: null, query: null})
|
||||
// Add a stub for this method using Mockito's 'when' API, or generate the MockWgerBaseProvider mock with the @GenerateNiceMocks annotation (see https://pub.dev/documentation/mockito/latest/annotations/MockSpec-class.html).)
|
||||
|
||||
late NutritionPlansProvider nutritionProvider;
|
||||
late MockWgerBaseProvider mockWgerBaseProvider;
|
||||
|
||||
setUp(() {
|
||||
mockWgerBaseProvider = MockWgerBaseProvider();
|
||||
nutritionProvider = NutritionPlansProvider(mockWgerBaseProvider, []);
|
||||
|
||||
const String planInfoUrl = 'nutritionplaninfo';
|
||||
const String planUrl = 'nutritionplan';
|
||||
const String diaryUrl = 'nutritiondiary';
|
||||
const String ingredientUrl = 'ingredient';
|
||||
|
||||
final Map<String, dynamic> nutritionalPlanInfoResponse = jsonDecode(
|
||||
fixture('nutrition/nutritional_plan_info_detail_response.json'),
|
||||
);
|
||||
final Map<String, dynamic> nutritionalPlanDetailResponse = jsonDecode(
|
||||
fixture('nutrition/nutritional_plan_detail_response.json'),
|
||||
);
|
||||
final List<dynamic> nutritionDiaryResponse = jsonDecode(
|
||||
fixture('nutrition/nutrition_diary_response.json'),
|
||||
)['results'];
|
||||
final Map<String, dynamic> ingredient59887Response = jsonDecode(
|
||||
fixture('nutrition/ingredient_59887_response.json'),
|
||||
);
|
||||
final Map<String, dynamic> ingredient10065Response = jsonDecode(
|
||||
fixture('nutrition/ingredient_10065_response.json'),
|
||||
);
|
||||
final Map<String, dynamic> ingredient58300Response = jsonDecode(
|
||||
fixture('nutrition/ingredient_58300_response.json'),
|
||||
);
|
||||
|
||||
final ingredientList = [
|
||||
Ingredient.fromJson(ingredient59887Response),
|
||||
Ingredient.fromJson(ingredient10065Response),
|
||||
Ingredient.fromJson(ingredient58300Response),
|
||||
];
|
||||
|
||||
nutritionProvider.ingredients = ingredientList;
|
||||
|
||||
final Uri planInfoUri = Uri(
|
||||
scheme: 'http',
|
||||
host: 'localhost',
|
||||
path: 'api/v2/$planInfoUrl/1',
|
||||
);
|
||||
final Uri planUri = Uri(
|
||||
scheme: 'http',
|
||||
host: 'localhost',
|
||||
path: 'api/v2/$planUrl',
|
||||
);
|
||||
final Uri diaryUri = Uri(
|
||||
scheme: 'http',
|
||||
host: 'localhost',
|
||||
path: 'api/v2/$diaryUrl',
|
||||
);
|
||||
when(mockWgerBaseProvider.makeUrl(planInfoUrl, id: anyNamed('id'))).thenReturn(planInfoUri);
|
||||
when(mockWgerBaseProvider.makeUrl(planUrl, id: anyNamed('id'))).thenReturn(planUri);
|
||||
when(mockWgerBaseProvider.makeUrl(diaryUrl, query: anyNamed('query'))).thenReturn(diaryUri);
|
||||
when(mockWgerBaseProvider.fetch(planInfoUri)).thenAnswer(
|
||||
(realInvocation) => Future.value(nutritionalPlanInfoResponse),
|
||||
);
|
||||
when(mockWgerBaseProvider.fetch(planUri)).thenAnswer(
|
||||
(realInvocation) => Future.value(nutritionalPlanDetailResponse),
|
||||
);
|
||||
when(mockWgerBaseProvider.fetchPaginated(diaryUri)).thenAnswer(
|
||||
(realInvocation) => Future.value(nutritionDiaryResponse),
|
||||
);
|
||||
});
|
||||
|
||||
/*
|
||||
late MockWgerBaseProvider mockBaseProvider;
|
||||
// late ExercisesProvider provider;
|
||||
|
||||
const String npPlanUrl = 'nutritionplan';
|
||||
|
||||
final Uri tNpPlanEntriesUri = Uri(
|
||||
scheme: 'http',
|
||||
host: 'localhost',
|
||||
path: 'api/v2/$npPlanUrl/',
|
||||
);
|
||||
*/
|
||||
Widget createNutritionalPlan({locale = 'en'}) {
|
||||
final key = GlobalKey<NavigatorState>();
|
||||
final mockBaseProvider = MockWgerBaseProvider();
|
||||
@@ -159,7 +70,6 @@ void main() {
|
||||
'Test the widgets on the nutritional plan screen',
|
||||
(tester) async {
|
||||
await loadAppFonts();
|
||||
await tester.takeScreenshot(name: 'die1');
|
||||
final globalKey = GlobalKey();
|
||||
await tester.pumpWidgetBuilder(
|
||||
Material(
|
||||
@@ -189,7 +99,6 @@ void main() {
|
||||
var infoOutlineButtons = find.byIcon(Icons.info_outline);
|
||||
await tester.tap(infoOutlineButtons.first); // 2nd button shows up also, but is off-screen
|
||||
await tester.pumpAndSettle();
|
||||
await tester.takeScreenshot(name: 'die2');
|
||||
await screenMatchesGolden(tester, 'nutritional_plan_2_one_meal_with_ingredients');
|
||||
|
||||
// Ingredients show up now
|
||||
|
||||
Reference in New Issue
Block a user