import 'package:cookit/src/planning/day.dart'; import 'package:cookit/src/planning/plan_share_service.dart'; import 'package:cookit/src/planning/views/shared_week_view.dart'; import 'package:cookit/src/recipes/views/widgets/recipe_card.dart'; import 'package:cookit/src/sharing/recipe_code.dart'; import 'package:cookit/src/sharing/views/shared_recipe_view.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:qr_flutter/qr_flutter.dart'; import '../support/fixtures.dart'; import '../support/test_app.dart'; void main() { testWidgets('"Rezept teilen" shows the Recipe Code and can leave the notes out', (tester) async { final app = await TestApp.create(tester); await tester.runAsync(() => app.recipes.saveRecipe(recipe())); await tester.pumpWidget(app.build()); await app.settle(tester); expect(find.byTooltip('Rezept scannen'), findsOneWidget); await tester.tap(find.descendant(of: find.byType(RecipeCard), matching: find.text('Focaccia'))); await app.settle(tester); await tester.tap(find.byTooltip('Rezept teilen')); await app.settle(tester); expect(find.byType(QrImageView), findsOneWidget); expect(find.text('Als Datei teilen'), findsOneWidget); await tester.tap(find.text('Notizen mitschicken')); await app.settle(tester); expect(tester.widget(find.byType(SwitchListTile)).value, isFalse); expect(find.byType(QrImageView), findsOneWidget); await app.dispose(tester); }); testWidgets('a received Recipe is previewed, flagged as a double and saved as a copy', (tester) async { final app = await TestApp.create(tester); await tester.runAsync(() => app.recipes.saveRecipe(recipe())); final shared = RecipeCode.decode(RecipeCode.encode(recipe(), courseName: 'Brot'), now: DateTime(2026)); await tester.pumpWidget(app.build()); await app.settle(tester); tester.state(find.byType(Navigator)).pushNamed(SharedRecipeView.routeName, arguments: shared); await app.settle(tester); expect(find.text('Rezept empfangen'), findsOneWidget); expect(find.text('Brot · 4 Portionen · 50 Min.'), findsOneWidget); expect(find.text('Mehl'), findsOneWidget); expect(find.text('1. Kneten.'), findsOneWidget); expect(find.textContaining('Du hast schon ein Rezept „Focaccia“'), findsOneWidget); await tester.tap(find.text('Speichern')); await app.settle(tester); expect(find.text('„Focaccia“ gespeichert'), findsOneWidget); expect(find.text('Kochmodus starten'), findsOneWidget); final all = (await tester.runAsync(app.recipes.allRecipes))!; expect(all, hasLength(2)); final courses = (await tester.runAsync(app.courses.allCourses))!; expect(courses.map((c) => c.name), contains('Brot')); await app.dispose(tester); }); testWidgets('a received week is previewed and adopted next to what is planned', (tester) async { final app = await TestApp.create(tester); final monday = DateTime.utc(2026, 10, 19); final week = (await tester.runAsync(() async { await app.recipes.saveRecipe(recipe()); final meals = await app.plan.allMeals(); final abend = meals.firstWhere((m) => m.name == 'Abend'); await app.plan.addEntry(monday, abend.id, recipeId: 'r1'); await app.plan.addEntry(addDays(monday, 2), abend.id, note: 'Essen gehen'); final shares = PlanShareService(app.recipes, app.courses, app.units, app.photos, app.plan, app.bundles); return SharedWeek(await app.bundles.read(await shares.weekFile(monday))); }))!; await tester.pumpWidget(app.build()); await app.settle(tester); tester.state(find.byType(Navigator)).pushNamed(SharedWeekView.routeName, arguments: week); await app.settle(tester); expect(find.text('Wochenplan empfangen'), findsOneWidget); expect(find.text('2 Einträge · keine neuen Rezepte'), findsOneWidget); expect(find.textContaining('schon 2 Einträge'), findsOneWidget); expect(find.text('Focaccia'), findsOneWidget); expect(find.text('Essen gehen'), findsOneWidget); await tester.tap(find.text('Übernehmen')); await app.settle(tester); expect(find.text('Wochenplan 19.–25. Okt. übernommen'), findsOneWidget); expect(await tester.runAsync(app.plan.allEntries), hasLength(4)); expect(await tester.runAsync(app.recipes.allRecipes), hasLength(1)); await app.dispose(tester); }); }