forked from eatvio/eatvio_app
146 lines
4.0 KiB
Dart
146 lines
4.0 KiB
Dart
import 'package:eatvio_app/features/recipe/models/my_recipe_model.dart';
|
|
import 'package:eatvio_app/features/feed/models/recipes_model.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
group('MyRecipePaginationModel', () {
|
|
test('creates MyRecipePaginationModel with empty list', () {
|
|
const model = MyRecipePaginationModel(data: []);
|
|
|
|
expect(model.data, isEmpty);
|
|
});
|
|
|
|
test('creates MyRecipePaginationModel with recipes', () {
|
|
final recipes = [
|
|
const MyRecipeModel(
|
|
id: 1,
|
|
image: 'image1.jpg',
|
|
state: 'published',
|
|
cookingTime: 30,
|
|
activeCookingTime: 15,
|
|
description: 'Test recipe 1',
|
|
steps: null,
|
|
videoUrl: null,
|
|
title: 'Recipe 1',
|
|
slug: 'recipe-1',
|
|
calories: 250.0,
|
|
likesCount: 10,
|
|
viewsCount: 100,
|
|
),
|
|
const MyRecipeModel(
|
|
id: 2,
|
|
image: 'image2.jpg',
|
|
state: 'draft',
|
|
cookingTime: 45,
|
|
activeCookingTime: 20,
|
|
description: 'Test recipe 2',
|
|
steps: null,
|
|
videoUrl: 'video.mp4',
|
|
title: 'Recipe 2',
|
|
slug: 'recipe-2',
|
|
calories: 300.0,
|
|
likesCount: 5,
|
|
viewsCount: 50,
|
|
),
|
|
];
|
|
|
|
final model = MyRecipePaginationModel(data: recipes);
|
|
|
|
expect(model.data.length, 2);
|
|
expect(model.data[0].id, 1);
|
|
expect(model.data[0].title, 'Recipe 1');
|
|
expect(model.data[1].id, 2);
|
|
expect(model.data[1].title, 'Recipe 2');
|
|
});
|
|
|
|
test('creates MyRecipePaginationModel from JSON', () {
|
|
final json = {
|
|
'data': [
|
|
{
|
|
'id': 1,
|
|
'image': 'image1.jpg',
|
|
'state': 'published',
|
|
'cooking_time': 30,
|
|
'active_time': 15,
|
|
'description_md': 'Test recipe',
|
|
'steps': null,
|
|
'video_url': null,
|
|
'title': 'Recipe 1',
|
|
'slug': 'recipe-1',
|
|
'energy_per_serving': 250.0,
|
|
'total_likes': 10,
|
|
'total_views': 100,
|
|
},
|
|
],
|
|
};
|
|
|
|
final model = MyRecipePaginationModel.fromJson(json);
|
|
|
|
expect(model.data.length, 1);
|
|
expect(model.data[0].id, 1);
|
|
expect(model.data[0].title, 'Recipe 1');
|
|
});
|
|
});
|
|
|
|
group('MyRecipeModel', () {
|
|
test('creates MyRecipeModel with all parameters', () {
|
|
const recipe = MyRecipeModel(
|
|
id: 1,
|
|
image: 'image.jpg',
|
|
state: 'published',
|
|
cookingTime: 30,
|
|
activeCookingTime: 15,
|
|
description: 'Test recipe',
|
|
steps: null,
|
|
videoUrl: null,
|
|
title: 'Recipe 1',
|
|
slug: 'recipe-1',
|
|
calories: 250.0,
|
|
likesCount: 10,
|
|
viewsCount: 100,
|
|
);
|
|
|
|
expect(recipe.id, 1);
|
|
expect(recipe.image, 'image.jpg');
|
|
expect(recipe.state, 'published');
|
|
expect(recipe.cookingTime, 30);
|
|
expect(recipe.activeCookingTime, 15);
|
|
expect(recipe.description, 'Test recipe');
|
|
expect(recipe.steps, null);
|
|
expect(recipe.videoUrl, null);
|
|
expect(recipe.title, 'Recipe 1');
|
|
expect(recipe.slug, 'recipe-1');
|
|
expect(recipe.calories, 250.0);
|
|
expect(recipe.likesCount, 10);
|
|
expect(recipe.viewsCount, 100);
|
|
});
|
|
|
|
test('creates MyRecipeModel with steps and videoUrl', () {
|
|
final steps = [
|
|
const Step(image: 'step1.jpg', description: 'Step 1'),
|
|
const Step(image: 'step2.jpg', description: 'Step 2'),
|
|
];
|
|
|
|
final recipe = MyRecipeModel(
|
|
id: 1,
|
|
image: 'image.jpg',
|
|
state: 'published',
|
|
cookingTime: 30,
|
|
activeCookingTime: 15,
|
|
description: 'Test recipe',
|
|
steps: steps,
|
|
videoUrl: 'video.mp4',
|
|
title: 'Recipe 1',
|
|
slug: 'recipe-1',
|
|
calories: 250.0,
|
|
likesCount: 10,
|
|
viewsCount: 100,
|
|
);
|
|
|
|
expect(recipe.steps, isNotNull);
|
|
expect(recipe.steps!.length, 2);
|
|
expect(recipe.videoUrl, 'video.mp4');
|
|
});
|
|
});
|
|
}
|