forked from eatvio/eatvio_app
feat(tests): updated tests coverage to 66.5%
This commit is contained in:
@@ -141,5 +141,88 @@ void main() {
|
||||
expect(recipe.steps!.length, 2);
|
||||
expect(recipe.videoUrl, 'video.mp4');
|
||||
});
|
||||
|
||||
test('creates MyRecipeModel from JSON', () {
|
||||
final json = {
|
||||
'id': 1,
|
||||
'image': 'image.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 recipe = MyRecipeModel.fromJson(json);
|
||||
|
||||
expect(recipe.id, 1);
|
||||
expect(recipe.title, 'Recipe 1');
|
||||
expect(recipe.cookingTime, 30);
|
||||
expect(recipe.calories, 250.0);
|
||||
});
|
||||
|
||||
test('toJson serializes MyRecipeModel correctly', () {
|
||||
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,
|
||||
);
|
||||
|
||||
final json = recipe.toJson();
|
||||
|
||||
expect(json['id'], 1);
|
||||
expect(json['title'], 'Recipe 1');
|
||||
expect(json['slug'], 'recipe-1');
|
||||
expect(json['cooking_time'], 30);
|
||||
expect(json['active_time'], 15);
|
||||
expect(json['energy_per_serving'], 250.0);
|
||||
expect(json['total_likes'], 10);
|
||||
expect(json['total_views'], 100);
|
||||
});
|
||||
});
|
||||
|
||||
group('MyRecipePaginationModel', () {
|
||||
test('toJson serializes MyRecipePaginationModel correctly', () {
|
||||
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,
|
||||
),
|
||||
];
|
||||
|
||||
final model = MyRecipePaginationModel(data: recipes);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json.containsKey('data'), isTrue);
|
||||
expect((json['data'] as List).length, 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,10 +9,7 @@ import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'my_recipes_cubit_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([
|
||||
MockSpec<MyRecipesRepository>(),
|
||||
MockSpec<AboutRecipeRepository>(),
|
||||
])
|
||||
@GenerateNiceMocks([MockSpec<MyRecipesRepository>(), MockSpec<AboutRecipeRepository>()])
|
||||
void main() {
|
||||
group('MyRecipesCubit', () {
|
||||
MyRecipesCubit? cubit;
|
||||
@@ -32,19 +29,13 @@ void main() {
|
||||
});
|
||||
|
||||
test('начальное состояние - loading', () {
|
||||
cubit = MyRecipesCubit(
|
||||
myRecipesRepository: mockMyRecipesRepository,
|
||||
aboutRecipeRepository: mockAboutRecipeRepository,
|
||||
);
|
||||
cubit = MyRecipesCubit(myRecipesRepository: mockMyRecipesRepository, aboutRecipeRepository: mockAboutRecipeRepository);
|
||||
|
||||
expect(cubit!.state, isA<MyRecipesStateLoading>());
|
||||
});
|
||||
|
||||
test('getMyRecipes - успешная загрузка активных рецептов', () async {
|
||||
cubit = MyRecipesCubit(
|
||||
myRecipesRepository: mockMyRecipesRepository,
|
||||
aboutRecipeRepository: mockAboutRecipeRepository,
|
||||
);
|
||||
cubit = MyRecipesCubit(myRecipesRepository: mockMyRecipesRepository, aboutRecipeRepository: mockAboutRecipeRepository);
|
||||
|
||||
final testRecipes = [
|
||||
const MyRecipeModel(
|
||||
@@ -64,8 +55,7 @@ void main() {
|
||||
),
|
||||
];
|
||||
|
||||
when(mockMyRecipesRepository.getMyRecipes())
|
||||
.thenAnswer((_) async => testRecipes);
|
||||
when(mockMyRecipesRepository.getMyRecipes()).thenAnswer((_) async => testRecipes);
|
||||
|
||||
await cubit!.getMyRecipes();
|
||||
|
||||
@@ -76,10 +66,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('setActiveState - фильтрует активные рецепты', () async {
|
||||
cubit = MyRecipesCubit(
|
||||
myRecipesRepository: mockMyRecipesRepository,
|
||||
aboutRecipeRepository: mockAboutRecipeRepository,
|
||||
);
|
||||
cubit = MyRecipesCubit(myRecipesRepository: mockMyRecipesRepository, aboutRecipeRepository: mockAboutRecipeRepository);
|
||||
|
||||
final testRecipes = [
|
||||
const MyRecipeModel(
|
||||
@@ -114,8 +101,7 @@ void main() {
|
||||
),
|
||||
];
|
||||
|
||||
when(mockMyRecipesRepository.getMyRecipes())
|
||||
.thenAnswer((_) async => testRecipes);
|
||||
when(mockMyRecipesRepository.getMyRecipes()).thenAnswer((_) async => testRecipes);
|
||||
|
||||
await cubit!.setActiveState();
|
||||
|
||||
@@ -126,10 +112,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('setArchivedState - фильтрует архивированные рецепты', () async {
|
||||
cubit = MyRecipesCubit(
|
||||
myRecipesRepository: mockMyRecipesRepository,
|
||||
aboutRecipeRepository: mockAboutRecipeRepository,
|
||||
);
|
||||
cubit = MyRecipesCubit(myRecipesRepository: mockMyRecipesRepository, aboutRecipeRepository: mockAboutRecipeRepository);
|
||||
|
||||
final testRecipes = [
|
||||
const MyRecipeModel(
|
||||
@@ -164,8 +147,7 @@ void main() {
|
||||
),
|
||||
];
|
||||
|
||||
when(mockMyRecipesRepository.getMyRecipes())
|
||||
.thenAnswer((_) async => testRecipes);
|
||||
when(mockMyRecipesRepository.getMyRecipes()).thenAnswer((_) async => testRecipes);
|
||||
|
||||
await cubit!.setArchivedState();
|
||||
|
||||
@@ -176,4 +158,3 @@ void main() {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user