Files
eatvio_app/test/features/create_recipe/models/recipe_model_test.dart
2026-01-14 18:47:11 +03:00

104 lines
3.1 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
});
});
}