forked from eatvio/eatvio_app
104 lines
3.1 KiB
Dart
104 lines
3.1 KiB
Dart
import 'package:eatvio_app/features/create_recipe/models/recipe_model.dart';
|
||
import 'package:flutter_test/flutter_test.dart';
|
||
|
||
void main() {
|
||
group('RecipeModel', () {
|
||
test('создает RecipeModel с правильными значениями', () {
|
||
const model = RecipeModel(
|
||
ingredients: [],
|
||
steps: [],
|
||
tags: ['tag1', 'tag2'],
|
||
type: 'breakfast',
|
||
state: 'active',
|
||
title: 'Test Recipe',
|
||
description: 'Test Description',
|
||
videoUrl: 'https://example.com/video.mp4',
|
||
image: 'https://example.com/image.jpg',
|
||
totalCookingTime: 30,
|
||
activeCookTime: 20,
|
||
servings: 4,
|
||
energyPerServing: 250,
|
||
);
|
||
|
||
expect(model.title, 'Test Recipe');
|
||
expect(model.description, 'Test Description');
|
||
expect(model.totalCookingTime, 30);
|
||
expect(model.servings, 4);
|
||
});
|
||
|
||
test('создает RecipeModel с null значениями', () {
|
||
const model = RecipeModel();
|
||
|
||
expect(model.ingredients, isNull);
|
||
expect(model.steps, isNull);
|
||
expect(model.tags, isNull);
|
||
expect(model.type, isNull);
|
||
expect(model.state, isNull);
|
||
expect(model.title, isNull);
|
||
});
|
||
|
||
test('fromJson создает RecipeModel из JSON', () {
|
||
final json = {
|
||
'ingredients': [],
|
||
'steps': [],
|
||
'tags': ['tag1', 'tag2'],
|
||
'type': 'breakfast',
|
||
'state': 'active',
|
||
'title': 'Test Recipe',
|
||
'description': 'Test Description',
|
||
'video_url': 'https://example.com/video.mp4',
|
||
'image': 'https://example.com/image.jpg',
|
||
'total_cooking_time': 30,
|
||
'active_cook_time': 20,
|
||
'servings': 4,
|
||
'energy_per_serving': 250,
|
||
};
|
||
|
||
final model = RecipeModel.fromJson(json);
|
||
|
||
expect(model.title, 'Test Recipe');
|
||
expect(model.description, 'Test Description');
|
||
expect(model.videoUrl, 'https://example.com/video.mp4');
|
||
expect(model.tags, ['tag1', 'tag2']);
|
||
});
|
||
|
||
test('fromJson создает RecipeModel из JSON с null значениями', () {
|
||
final json = <String, dynamic>{};
|
||
|
||
final model = RecipeModel.fromJson(json);
|
||
|
||
expect(model.ingredients, isNull);
|
||
expect(model.steps, isNull);
|
||
expect(model.tags, isNull);
|
||
expect(model.title, isNull);
|
||
});
|
||
|
||
test('toJson serializes RecipeModel correctly', () {
|
||
const model = RecipeModel(
|
||
ingredients: [],
|
||
steps: [],
|
||
tags: ['tag1', 'tag2'],
|
||
type: 'breakfast',
|
||
state: 'active',
|
||
title: 'Test Recipe',
|
||
description: 'Test Description',
|
||
videoUrl: 'https://example.com/video.mp4',
|
||
image: 'https://example.com/image.jpg',
|
||
totalCookingTime: 30,
|
||
activeCookTime: 20,
|
||
servings: 4,
|
||
energyPerServing: 250,
|
||
);
|
||
|
||
final json = model.toJson();
|
||
|
||
expect(json['title'], 'Test Recipe');
|
||
expect(json['description'], 'Test Description');
|
||
expect(json['video_url'], 'https://example.com/video.mp4');
|
||
expect(json['tags'], ['tag1', 'tag2']);
|
||
expect(json['totalCookingTime'], 30);
|
||
expect(json['servings'], 4);
|
||
});
|
||
});
|
||
}
|