forked from eatvio/eatvio_app
feat(dependencies): add rxdart package and improve string extension methods for better handling of empty strings and gender parsing
This commit is contained in:
35
test/features/create_recipe/models/ingredient_test.dart
Normal file
35
test/features/create_recipe/models/ingredient_test.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'package:eatvio_app/features/create_recipe/models/ingredient.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('Ingredient', () {
|
||||
test('создает Ingredient с правильными значениями', () {
|
||||
const ingredient = Ingredient(
|
||||
name: 'Apple',
|
||||
unit: 'gr',
|
||||
portion: '100',
|
||||
productId: 1,
|
||||
);
|
||||
|
||||
expect(ingredient.name, 'Apple');
|
||||
expect(ingredient.unit, 'gr');
|
||||
expect(ingredient.portion, '100');
|
||||
expect(ingredient.productId, 1);
|
||||
});
|
||||
|
||||
test('fromJson создает Ingredient из JSON', () {
|
||||
final json = {
|
||||
'name': 'Apple',
|
||||
'unit': 'gr',
|
||||
'portion': '100',
|
||||
'product_nutritional_id': 1,
|
||||
};
|
||||
|
||||
final ingredient = Ingredient.fromJson(json);
|
||||
|
||||
expect(ingredient.name, 'Apple');
|
||||
expect(ingredient.productId, 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
29
test/features/create_recipe/models/product_test.dart
Normal file
29
test/features/create_recipe/models/product_test.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'package:eatvio_app/features/create_recipe/models/product.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('Product', () {
|
||||
test('создает Product с правильными значениями', () {
|
||||
const product = Product(
|
||||
id: 1,
|
||||
name: 'Apple',
|
||||
);
|
||||
|
||||
expect(product.id, 1);
|
||||
expect(product.name, 'Apple');
|
||||
});
|
||||
|
||||
test('fromJson создает Product из JSON', () {
|
||||
final json = {
|
||||
'id': 1,
|
||||
'name': 'Apple',
|
||||
};
|
||||
|
||||
final product = Product.fromJson(json);
|
||||
|
||||
expect(product.id, 1);
|
||||
expect(product.name, 'Apple');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
44
test/features/create_recipe/models/recipe_model_test.dart
Normal file
44
test/features/create_recipe/models/recipe_model_test.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
import 'package:eatvio_app/features/create_recipe/models/ingredient.dart';
|
||||
import 'package:eatvio_app/features/create_recipe/models/recipe_model.dart';
|
||||
import 'package:eatvio_app/features/create_recipe/models/step.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('RecipeModel', () {
|
||||
test('создает RecipeModel с правильными значениями', () {
|
||||
const ingredient = Ingredient(
|
||||
name: 'Apple',
|
||||
unit: 'gr',
|
||||
portion: '100',
|
||||
productId: 1,
|
||||
);
|
||||
|
||||
const step = Step(
|
||||
image: 'https://example.com/image.jpg',
|
||||
description: 'Step description',
|
||||
);
|
||||
|
||||
const model = RecipeModel(
|
||||
ingredients: [ingredient],
|
||||
steps: [step],
|
||||
tags: ['breakfast'],
|
||||
type: 'main',
|
||||
state: 'draft',
|
||||
title: 'Test Recipe',
|
||||
description: 'Test description',
|
||||
videoUrl: 'https://example.com/video.mp4',
|
||||
image: 'https://example.com/image.jpg',
|
||||
totalCookingTime: 30,
|
||||
activeCookTime: 15,
|
||||
servings: 4,
|
||||
energyPerServing: 300,
|
||||
);
|
||||
|
||||
expect(model.title, 'Test Recipe');
|
||||
expect(model.ingredients?.length, 1);
|
||||
expect(model.steps?.length, 1);
|
||||
expect(model.tags?.length, 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import 'package:eatvio_app/core/models/pagination_model.dart';
|
||||
import 'package:eatvio_app/features/create_recipe/models/recipe_tag_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('RecipeTag', () {
|
||||
test('создает RecipeTag с правильными значениями', () {
|
||||
final tag = RecipeTag(
|
||||
id: 1,
|
||||
name: 'Breakfast',
|
||||
recipesCount: 10,
|
||||
createdAt: DateTime(2024, 1, 1),
|
||||
updatedAt: DateTime(2024, 1, 2),
|
||||
);
|
||||
|
||||
expect(tag.id, 1);
|
||||
expect(tag.name, 'Breakfast');
|
||||
expect(tag.recipesCount, 10);
|
||||
});
|
||||
});
|
||||
|
||||
group('RecipeTagModel', () {
|
||||
test('создает RecipeTagModel с правильными значениями', () {
|
||||
final tag = RecipeTag(
|
||||
id: 1,
|
||||
name: 'Breakfast',
|
||||
recipesCount: 10,
|
||||
createdAt: DateTime(2024, 1, 1),
|
||||
updatedAt: DateTime(2024, 1, 2),
|
||||
);
|
||||
|
||||
final model = RecipeTagModel(
|
||||
data: [tag],
|
||||
links: const Links(
|
||||
first: 'https://example.com?page=1',
|
||||
last: 'https://example.com?page=1',
|
||||
prev: null,
|
||||
next: null,
|
||||
),
|
||||
meta: const Meta(
|
||||
currentPage: 1,
|
||||
from: 1,
|
||||
lastPage: 1,
|
||||
links: [],
|
||||
perPage: 10,
|
||||
to: 1,
|
||||
total: 1,
|
||||
),
|
||||
);
|
||||
|
||||
expect(model.data.length, 1);
|
||||
expect(model.data.first.name, 'Breakfast');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
27
test/features/create_recipe/models/step_test.dart
Normal file
27
test/features/create_recipe/models/step_test.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'package:eatvio_app/features/create_recipe/models/step.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('Step', () {
|
||||
test('создает Step с правильными значениями', () {
|
||||
const step = Step(
|
||||
image: 'https://example.com/image.jpg',
|
||||
description: 'Step description',
|
||||
);
|
||||
|
||||
expect(step.image, 'https://example.com/image.jpg');
|
||||
expect(step.description, 'Step description');
|
||||
});
|
||||
|
||||
test('создает Step с null значениями', () {
|
||||
const step = Step(
|
||||
image: null,
|
||||
description: null,
|
||||
);
|
||||
|
||||
expect(step.image, isNull);
|
||||
expect(step.description, isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user