forked from eatvio/eatvio_app
129 lines
5.0 KiB
Dart
129 lines
5.0 KiB
Dart
import 'package:eatvio_app/core/app_initializer.dart';
|
|
import 'package:eatvio_app/features/create_recipe/entities/recipe_create_entity.dart';
|
|
import 'package:eatvio_app/features/create_recipe/presentation/pages/recipe_create_screen.dart';
|
|
import 'package:eatvio_app/main.dart' as app;
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:integration_test/integration_test.dart';
|
|
|
|
import '../common_cases/skip_welcome_screen.dart';
|
|
import '../common_cases/skip_sign_in.dart';
|
|
import 'create_recipe_helpers.dart';
|
|
|
|
void main() {
|
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
setUpAll(() async {
|
|
await AppInitializer.initialize(buildType: AppBuildType.tests);
|
|
});
|
|
|
|
group('Create Recipe Integration Tests', () {
|
|
testWidgets('should create and publish a new recipe successfully', (tester) async {
|
|
// 1. Запустить приложение
|
|
await tester.pumpWidget(const app.MyApp());
|
|
await tester.pumpAndSettle(const Duration(seconds: 20));
|
|
|
|
// 2. Пропустить онбординг и войти в систему
|
|
await skipWelcomeScreen(tester);
|
|
await skipSignIn(tester);
|
|
await tester.pumpAndSettle(const Duration(seconds: 3));
|
|
|
|
// 3. Перейти на экран создания рецепта
|
|
await navigateToCreateRecipeScreen(tester);
|
|
|
|
// Проверяем, что мы на экране создания рецепта
|
|
expect(find.byType(RecipeCreateScreen), findsOneWidget);
|
|
|
|
// 4. Заполнить все поля формы
|
|
final testData = createTestRecipeData();
|
|
await fillRecipeBasicInfo(
|
|
tester,
|
|
title: testData['title'] as String,
|
|
type: testData['type'] as TypeOfRecipe,
|
|
portions: testData['portions'] as int,
|
|
calories: testData['calories'] as double,
|
|
totalHours: testData['totalHours'] as int,
|
|
totalMinutes: testData['totalMinutes'] as int,
|
|
activeHours: testData['activeHours'] as int,
|
|
activeMinutes: testData['activeMinutes'] as int,
|
|
description: testData['description'] as String,
|
|
);
|
|
|
|
// 5. Добавить теги
|
|
await addTags(tester, testData['tags'] as List<String>);
|
|
|
|
// 6. Добавить ингредиенты
|
|
await addIngredients(tester, testData['ingredients'] as List<Map<String, String>>);
|
|
|
|
// 7. Добавить шаги приготовления
|
|
await addCookingSteps(tester, testData['steps'] as List<Map<String, String>>);
|
|
|
|
// 8. Симулировать добавление изображения
|
|
await mockImageSelection(tester);
|
|
|
|
// 9. Нажать "Опубликовать"
|
|
await publishRecipe(tester);
|
|
|
|
// 10. Проверить результат
|
|
verifyRecipePublished(tester);
|
|
});
|
|
|
|
testWidgets('should validate required fields before publishing', (tester) async {
|
|
// 1. Запустить приложение и войти в систему
|
|
await tester.pumpWidget(const app.MyApp());
|
|
await tester.pumpAndSettle(const Duration(seconds: 3));
|
|
await skipWelcomeScreen(tester);
|
|
await skipSignIn(tester);
|
|
await tester.pumpAndSettle(const Duration(seconds: 3));
|
|
|
|
// 2. Перейти на экран создания рецепта
|
|
await navigateToCreateRecipeScreen(tester);
|
|
|
|
// 3. Попытаться опубликовать без заполнения полей
|
|
await publishRecipe(tester);
|
|
|
|
// 4. Проверить, что валидация сработала
|
|
verifyValidationErrors(tester);
|
|
});
|
|
|
|
testWidgets('should create recipe with minimal required fields', (tester) async {
|
|
// 1. Запустить приложение и войти в систему
|
|
await tester.pumpWidget(const app.MyApp());
|
|
await tester.pumpAndSettle(const Duration(seconds: 3));
|
|
await skipWelcomeScreen(tester);
|
|
await skipSignIn(tester);
|
|
await tester.pumpAndSettle(const Duration(seconds: 3));
|
|
|
|
// 2. Перейти на экран создания рецепта
|
|
await navigateToCreateRecipeScreen(tester);
|
|
|
|
// 3. Заполнить только обязательные поля
|
|
await fillRecipeBasicInfo(
|
|
tester,
|
|
title: 'Минимальный тестовый рецепт',
|
|
type: TypeOfRecipe.firstMeals,
|
|
portions: 2,
|
|
calories: 300.0,
|
|
totalHours: 0,
|
|
totalMinutes: 30,
|
|
activeHours: 0,
|
|
activeMinutes: 15,
|
|
description: 'Простой рецепт для тестирования.',
|
|
);
|
|
|
|
// 4. Добавить минимум ингредиентов
|
|
await addIngredients(tester, [
|
|
{'name': 'Тестовый ингредиент', 'quantity': '100'},
|
|
]);
|
|
|
|
// 5. Симулировать добавление изображения
|
|
await mockImageSelection(tester);
|
|
|
|
// 6. Опубликовать рецепт
|
|
await publishRecipe(tester);
|
|
|
|
// 7. Проверить результат
|
|
verifyRecipePublished(tester);
|
|
});
|
|
});
|
|
}
|