feat(tests): updated tests coverage to 66.5%

This commit is contained in:
misha
2026-01-14 18:47:11 +03:00
parent 497ff19cfa
commit 13ccf56df0
102 changed files with 10146 additions and 379 deletions

View File

@@ -0,0 +1,159 @@
import 'dart:io';
import 'package:eatvio_app/features/create_recipe/entities/recipe_create_entity.dart';
import 'package:eatvio_app/features/create_recipe/models/ingredient.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('TypeOfRecipe', () {
test('toString returns correct Russian names', () {
expect(TypeOfRecipe.firstMeals.toString(), 'Первые блюда');
expect(TypeOfRecipe.secondMeals.toString(), 'Вторые блюда');
expect(TypeOfRecipe.salads.toString(), 'Салаты');
expect(TypeOfRecipe.snacks.toString(), 'Закуски');
expect(TypeOfRecipe.sweets.toString(), 'Сладости');
expect(TypeOfRecipe.drinks.toString(), 'Напитки');
expect(TypeOfRecipe.other.toString(), 'Другое');
});
test('toApiType returns correct API strings', () {
expect(TypeOfRecipe.firstMeals.toApiType(), 'first_meals');
expect(TypeOfRecipe.secondMeals.toApiType(), 'second_meals');
expect(TypeOfRecipe.salads.toApiType(), 'salads');
expect(TypeOfRecipe.snacks.toApiType(), 'snacks');
expect(TypeOfRecipe.sweets.toApiType(), 'sweets');
expect(TypeOfRecipe.drinks.toApiType(), 'drinks');
expect(TypeOfRecipe.other.toApiType(), 'other');
});
test('fromApiType parses valid API strings', () {
expect(TypeOfRecipe.fromApiType('first_meals'), TypeOfRecipe.firstMeals);
expect(TypeOfRecipe.fromApiType('second_meals'), TypeOfRecipe.secondMeals);
expect(TypeOfRecipe.fromApiType('salads'), TypeOfRecipe.salads);
expect(TypeOfRecipe.fromApiType('snacks'), TypeOfRecipe.snacks);
expect(TypeOfRecipe.fromApiType('sweets'), TypeOfRecipe.sweets);
expect(TypeOfRecipe.fromApiType('drinks'), TypeOfRecipe.drinks);
expect(TypeOfRecipe.fromApiType('other'), TypeOfRecipe.other);
});
test('fromApiType returns null for invalid strings', () {
expect(TypeOfRecipe.fromApiType('invalid'), isNull);
expect(TypeOfRecipe.fromApiType(''), isNull);
expect(TypeOfRecipe.fromApiType('unknown'), isNull);
});
test('fromString parses valid Russian names', () {
expect(TypeOfRecipe.fromString('Первые блюда'), TypeOfRecipe.firstMeals);
expect(TypeOfRecipe.fromString('Вторые блюда'), TypeOfRecipe.secondMeals);
expect(TypeOfRecipe.fromString('Салаты'), TypeOfRecipe.salads);
expect(TypeOfRecipe.fromString('Закуски'), TypeOfRecipe.snacks);
expect(TypeOfRecipe.fromString('Сладости'), TypeOfRecipe.sweets);
expect(TypeOfRecipe.fromString('Напитки'), TypeOfRecipe.drinks);
expect(TypeOfRecipe.fromString('Другое'), TypeOfRecipe.other);
});
test('fromString returns null for invalid strings', () {
expect(TypeOfRecipe.fromString('invalid'), isNull);
expect(TypeOfRecipe.fromString(''), isNull);
expect(TypeOfRecipe.fromString('Unknown'), isNull);
});
});
group('StepEntity', () {
test('hasProps returns true when description is not null', () {
const step = StepEntity(description: 'Test description');
expect(step.hasProps(), isTrue);
});
test('hasProps returns false when description is null', () {
const step = StepEntity(description: null);
expect(step.hasProps(), isFalse);
});
test('hasProps returns true when description is not null even if image is null', () {
const step = StepEntity(description: 'Test', image: null);
expect(step.hasProps(), isTrue);
});
});
group('RecipeCreateEntity', () {
test('toModel converts entity to RecipeModel correctly', () {
const entity = RecipeCreateEntity(
title: 'Test Recipe',
typeOfRecipe: TypeOfRecipe.firstMeals,
countOfPortions: 4,
energyInOnePortion: 250.5,
totalCookHours: 1,
totalCookMinutes: 30,
activeCookHours: 0,
activeCookMinutes: 20,
description: 'Test description',
videoUrl: 'https://example.com/video',
ingredients: [Ingredient(name: 'Apple', unit: 'pc', portion: '100', productId: 1)],
steps: [
StepEntity(description: 'Step 1'),
StepEntity(description: 'Step 2'),
],
tags: ['vegan', 'breakfast'],
);
final model = entity.toModel();
expect(model.title, 'Test Recipe');
expect(model.type, 'first_meals');
expect(model.servings, 4);
expect(model.energyPerServing, 250);
expect(model.totalCookingTime, 90); // 1 hour * 60 + 30 minutes
expect(model.activeCookTime, 20); // 0 hours * 60 + 20 minutes
expect(model.description, 'Test description');
expect(model.videoUrl, 'https://example.com/video');
expect(model.ingredients?.length, 1);
expect(model.steps?.length, 2);
expect(model.tags?.length, 2);
});
test('toModel handles null values correctly', () {
const entity = RecipeCreateEntity(ingredients: [], steps: [], tags: []);
final model = entity.toModel();
expect(model.title, isNull);
expect(model.type, isNull);
expect(model.servings, isNull);
expect(model.energyPerServing, isNull);
expect(model.totalCookingTime, 0); // (0 * 60) + 0
expect(model.activeCookTime, 0); // (0 * 60) + 0
expect(model.description, isNull);
expect(model.videoUrl, isNull);
expect(model.ingredients, isEmpty);
expect(model.steps, isEmpty);
expect(model.tags, isEmpty);
});
test('toModel converts steps with hasProps correctly', () {
const entity = RecipeCreateEntity(
ingredients: [],
steps: [
StepEntity(description: 'Step with description'),
StepEntity(description: null), // Step without description
],
tags: [],
);
final model = entity.toModel();
expect(model.steps?.length, 2); // All steps are included
expect(model.steps?.first?.description, 'Step with description');
expect(model.steps?.last, isNull); // Step without description returns null
});
test('toModel handles image path correctly', () {
final tempFile = File('test_image.jpg');
final entity = RecipeCreateEntity(image: tempFile, ingredients: const [], steps: const [], tags: const []);
final model = entity.toModel();
expect(model.image, 'test_image.jpg');
});
});
}