forked from eatvio/eatvio_app
chore(dependencies): add webview_flutter_platform_interface package to pubspec.yaml and clean up test files by removing unnecessary whitespace
This commit is contained in:
238
test/features/feed/models/recipes_model_test.dart
Normal file
238
test/features/feed/models/recipes_model_test.dart
Normal file
@@ -0,0 +1,238 @@
|
||||
import 'package:eatvio_app/features/feed/models/recipes_model.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('Recipe', () {
|
||||
test('creates Recipe with all parameters', () {
|
||||
const author = Author(
|
||||
authorSlug: 'chef',
|
||||
authorName: 'Chef Name',
|
||||
authorProfileIcon: 'icon.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
authorPlaceInRating: null,
|
||||
);
|
||||
|
||||
const recipe = Recipe(
|
||||
id: 1,
|
||||
image: 'recipe.jpg',
|
||||
state: 'published',
|
||||
cookingTime: 30,
|
||||
activeCookingTime: 15,
|
||||
ingredients: null,
|
||||
description: 'Test recipe description',
|
||||
steps: null,
|
||||
videoUrl: null,
|
||||
createdAt: null,
|
||||
updatedAt: null,
|
||||
title: 'Test Recipe',
|
||||
type: 'main',
|
||||
slug: 'test-recipe',
|
||||
commentsCount: 5,
|
||||
wasLikedByMe: false,
|
||||
isFavorite: false,
|
||||
calories: 250.0,
|
||||
servings: 4,
|
||||
likesCount: 10,
|
||||
viewsCount: 100,
|
||||
tags: [],
|
||||
author: author,
|
||||
);
|
||||
|
||||
expect(recipe.id, 1);
|
||||
expect(recipe.title, 'Test Recipe');
|
||||
expect(recipe.slug, 'test-recipe');
|
||||
expect(recipe.cookingTime, 30);
|
||||
expect(recipe.calories, 250.0);
|
||||
expect(recipe.author.authorName, 'Chef Name');
|
||||
});
|
||||
|
||||
test('creates Recipe with ingredients and steps', () {
|
||||
const author = Author(
|
||||
authorSlug: 'chef',
|
||||
authorName: 'Chef',
|
||||
authorProfileIcon: 'icon.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
authorPlaceInRating: null,
|
||||
);
|
||||
|
||||
final ingredients = [
|
||||
const Ingredient(name: 'Flour', unit: 'cup', portion: '1', productId: 1),
|
||||
const Ingredient(name: 'Sugar', unit: 'tbsp', portion: '2', productId: 2),
|
||||
];
|
||||
|
||||
final steps = [
|
||||
const Step(image: 'step1.jpg', description: 'Step 1 description'),
|
||||
const Step(image: 'step2.jpg', description: 'Step 2 description'),
|
||||
];
|
||||
|
||||
final recipe = Recipe(
|
||||
id: 1,
|
||||
image: 'recipe.jpg',
|
||||
state: 'published',
|
||||
cookingTime: 30,
|
||||
activeCookingTime: 15,
|
||||
ingredients: ingredients,
|
||||
description: 'Recipe with steps',
|
||||
steps: steps,
|
||||
videoUrl: 'video.mp4',
|
||||
createdAt: DateTime(2023, 1, 1),
|
||||
updatedAt: DateTime(2023, 1, 2),
|
||||
title: 'Complete Recipe',
|
||||
type: 'dessert',
|
||||
slug: 'complete-recipe',
|
||||
commentsCount: 10,
|
||||
wasLikedByMe: true,
|
||||
isFavorite: true,
|
||||
calories: 300.0,
|
||||
servings: 6,
|
||||
likesCount: 20,
|
||||
viewsCount: 200,
|
||||
tags: [const Tag(name: 'sweet'), const Tag(name: 'dessert')],
|
||||
author: author,
|
||||
);
|
||||
|
||||
expect(recipe.ingredients, isNotNull);
|
||||
expect(recipe.ingredients!.length, 2);
|
||||
expect(recipe.steps, isNotNull);
|
||||
expect(recipe.steps!.length, 2);
|
||||
expect(recipe.videoUrl, 'video.mp4');
|
||||
expect(recipe.tags.length, 2);
|
||||
});
|
||||
|
||||
test('creates Recipe from JSON', () {
|
||||
final json = {
|
||||
'id': 1,
|
||||
'image': 'recipe.jpg',
|
||||
'state': 'published',
|
||||
'cooking_time': 30,
|
||||
'active_time': 15,
|
||||
'ingredients': null,
|
||||
'description_md': 'Test description',
|
||||
'steps': null,
|
||||
'video_url': null,
|
||||
'created_at': null,
|
||||
'updated_at': null,
|
||||
'title': 'Test Recipe',
|
||||
'type': 'main',
|
||||
'slug': 'test-recipe',
|
||||
'total_comments': 5,
|
||||
'was_liked_by_me': false,
|
||||
'is_favorite': false,
|
||||
'energy_per_serving': 250.0,
|
||||
'servings': 4,
|
||||
'total_likes': 10,
|
||||
'total_views': 100,
|
||||
'tags': [],
|
||||
'author': {
|
||||
'author_slug': 'chef',
|
||||
'author_name': 'Chef',
|
||||
'author_profile_icon': 'icon.jpg',
|
||||
'author_is_me': false,
|
||||
},
|
||||
};
|
||||
|
||||
final recipe = Recipe.fromJson(json);
|
||||
|
||||
expect(recipe.id, 1);
|
||||
expect(recipe.title, 'Test Recipe');
|
||||
expect(recipe.cookingTime, 30);
|
||||
});
|
||||
});
|
||||
|
||||
group('Tag', () {
|
||||
test('creates Tag with name', () {
|
||||
const tag = Tag(name: 'dessert');
|
||||
|
||||
expect(tag.name, 'dessert');
|
||||
});
|
||||
|
||||
test('creates Tag from JSON', () {
|
||||
final json = {'name': 'sweet'};
|
||||
|
||||
final tag = Tag.fromJson(json);
|
||||
|
||||
expect(tag.name, 'sweet');
|
||||
});
|
||||
});
|
||||
|
||||
group('Ingredient', () {
|
||||
test('creates Ingredient with all parameters', () {
|
||||
const ingredient = Ingredient(
|
||||
name: 'Flour',
|
||||
unit: 'cup',
|
||||
portion: '1',
|
||||
productId: 1,
|
||||
);
|
||||
|
||||
expect(ingredient.name, 'Flour');
|
||||
expect(ingredient.unit, 'cup');
|
||||
expect(ingredient.portion, '1');
|
||||
expect(ingredient.productId, 1);
|
||||
});
|
||||
|
||||
test('creates Ingredient with null unit', () {
|
||||
const ingredient = Ingredient(
|
||||
name: 'Salt',
|
||||
unit: null,
|
||||
portion: 'pinch',
|
||||
productId: 2,
|
||||
);
|
||||
|
||||
expect(ingredient.unit, null);
|
||||
});
|
||||
|
||||
test('creates Ingredient from JSON with string productId', () {
|
||||
final json = {
|
||||
'name': 'Flour',
|
||||
'unit': 'cup',
|
||||
'portion': '1',
|
||||
'product_nutritional_id': '123',
|
||||
};
|
||||
|
||||
final ingredient = Ingredient.fromJson(json);
|
||||
|
||||
expect(ingredient.productId, 123);
|
||||
});
|
||||
|
||||
test('creates Ingredient from JSON with int productId', () {
|
||||
final json = {
|
||||
'name': 'Sugar',
|
||||
'unit': 'tbsp',
|
||||
'portion': '2',
|
||||
'product_nutritional_id': 456,
|
||||
};
|
||||
|
||||
final ingredient = Ingredient.fromJson(json);
|
||||
|
||||
expect(ingredient.productId, 456);
|
||||
});
|
||||
});
|
||||
|
||||
group('Step', () {
|
||||
test('creates Step with image and description', () {
|
||||
const step = Step(
|
||||
image: 'step1.jpg',
|
||||
description: 'Step 1 description',
|
||||
);
|
||||
|
||||
expect(step.image, 'step1.jpg');
|
||||
expect(step.description, 'Step 1 description');
|
||||
});
|
||||
|
||||
test('creates Step from JSON', () {
|
||||
final json = {
|
||||
'image': 'step1.jpg',
|
||||
'description_md': 'Step description',
|
||||
};
|
||||
|
||||
final step = Step.fromJson(json);
|
||||
|
||||
expect(step.image, 'step1.jpg');
|
||||
expect(step.description, 'Step description');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user