feat(dependencies): add rxdart package and improve string extension methods for better handling of empty strings and gender parsing

This commit is contained in:
mso7nueh
2025-12-04 15:45:54 +03:00
parent 0cd8e662d9
commit 953230b387
100 changed files with 7202 additions and 14 deletions

View File

@@ -0,0 +1,123 @@
import 'package:eatvio_app/features/create_recipe/models/recipe_tag_model.dart';
import 'package:eatvio_app/features/diets/repositories/diet_repository.dart';
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
import 'package:eatvio_app/features/feed/models/recipes_model.dart';
import 'package:eatvio_app/features/feed/models/recipes_pagination_model.dart';
import 'package:eatvio_app/features/feed/presentation/bloc/recipes_cubit/recipes_cubit.dart';
import 'package:eatvio_app/features/feed/presentation/bloc/recipes_cubit/recipes_state.dart';
import 'package:eatvio_app/features/feed/repositories/feed_repository.dart';
import 'package:eatvio_app/features/recipe/repositories/about_recipe_repository.dart';
import 'package:eatvio_app/features/create_recipe/reporitories/recipe_repository.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:rxdart/rxdart.dart';
import 'recipes_cubit_test.mocks.dart';
@GenerateNiceMocks([MockSpec<FeedRepository>(), MockSpec<RecipeRepository>(), MockSpec<AboutRecipeRepository>()])
void main() {
group('RecipesCubit', () {
RecipesCubit? recipesCubit;
late MockFeedRepository mockFeedRepository;
late MockRecipeRepository mockRecipeRepository;
late MockAboutRecipeRepository mockAboutRecipeRepository;
setUp(() {
mockFeedRepository = MockFeedRepository();
mockRecipeRepository = MockRecipeRepository();
mockAboutRecipeRepository = MockAboutRecipeRepository();
// Мокируем streams для подписок
when(mockAboutRecipeRepository.recipeLikeState).thenAnswer((_) => BehaviorSubject<LikesState>());
when(mockAboutRecipeRepository.recipeFavoriteState).thenAnswer((_) => BehaviorSubject<FavoriteState>());
when(mockAboutRecipeRepository.recipeCommentsState).thenAnswer((_) => BehaviorSubject<CommentsState>());
});
tearDown(() async {
if (recipesCubit != null && !recipesCubit!.isClosed) {
await Future.delayed(const Duration(milliseconds: 100));
await recipesCubit!.close();
recipesCubit = null;
}
});
test('начальное состояние - initial', () {
recipesCubit = RecipesCubit(feedRepository: mockFeedRepository, recipeRepository: mockRecipeRepository, aboutRecipeRepository: mockAboutRecipeRepository);
expect(recipesCubit!.state, isA<RecipesState>());
expect(recipesCubit!.state.isLoading, isTrue);
expect(recipesCubit!.state.recipesList, isEmpty);
expect(recipesCubit!.state.selectedTags, isEmpty);
});
test('loadRecipesList - успешная загрузка рецептов', () async {
recipesCubit = RecipesCubit(feedRepository: mockFeedRepository, recipeRepository: mockRecipeRepository, aboutRecipeRepository: mockAboutRecipeRepository);
const testRecipe = Recipe(
id: 1,
image: 'https://example.com/image.jpg',
state: 'active',
cookingTime: 30,
activeCookingTime: 15,
ingredients: [],
description: 'Test description',
steps: [],
videoUrl: null,
createdAt: null,
updatedAt: null,
title: 'Test Recipe',
type: 'main',
slug: 'test-recipe',
commentsCount: 5,
wasLikedByMe: false,
isFavorite: false,
calories: 300.0,
servings: 4,
likesCount: 10,
viewsCount: 100,
tags: [],
author: Author(
authorSlug: 'author',
authorName: 'Author Name',
authorProfileIcon: 'https://example.com/icon.jpg',
authorIsMe: false,
isEntitySubscribedByMe: null,
authorPlaceInRating: null,
),
);
const recipesList = RecipesPagination(recipesList: [testRecipe]);
final testTags = [
RecipeTag(id: 1, name: 'Tag 1', recipesCount: 10, createdAt: DateTime(2024, 1, 1), updatedAt: DateTime(2024, 1, 2)),
RecipeTag(id: 2, name: 'Tag 2', recipesCount: 20, createdAt: DateTime(2024, 1, 1), updatedAt: DateTime(2024, 1, 2)),
];
when(mockFeedRepository.getRecipes(tags: anyNamed('tags'), query: anyNamed('query'))).thenAnswer((_) async => recipesList.recipesList);
when(mockRecipeRepository.getRecipesTags()).thenAnswer((_) async => testTags);
await recipesCubit!.loadRecipesList();
await Future.delayed(const Duration(milliseconds: 200));
expect(recipesCubit!.state.recipesList.length, 1);
expect(recipesCubit!.state.recipesTags.length, 2);
expect(recipesCubit!.state.errorMessage, isNull);
});
test('updateTags - добавляет и удаляет теги', () {
recipesCubit = RecipesCubit(feedRepository: mockFeedRepository, recipeRepository: mockRecipeRepository, aboutRecipeRepository: mockAboutRecipeRepository);
final tag = RecipeTag(id: 1, name: 'Breakfast', recipesCount: 10, createdAt: DateTime(2024, 1, 1), updatedAt: DateTime(2024, 1, 2));
recipesCubit!.updateTags(tag);
expect(recipesCubit!.state.selectedTags.contains(1), isTrue);
expect(recipesCubit!.state.selectedTagsCounter, 1);
recipesCubit!.updateTags(tag);
expect(recipesCubit!.state.selectedTags.contains(1), isFalse);
expect(recipesCubit!.state.selectedTagsCounter, 0);
});
});
}

View File

@@ -0,0 +1,77 @@
import 'package:eatvio_app/features/create_recipe/models/recipe_tag_model.dart';
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
import 'package:eatvio_app/features/feed/models/recipes_model.dart';
import 'package:eatvio_app/features/feed/presentation/bloc/recipes_cubit/recipes_state.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('RecipesState', () {
test('initial создает начальное состояние', () {
final state = RecipesState.initial();
expect(state.isLoading, isTrue);
expect(state.recipesList, isEmpty);
expect(state.recipesTags, isEmpty);
expect(state.selectedTags, isEmpty);
expect(state.selectedTagsCounter, 0);
expect(state.errorMessage, isNull);
});
test('создает RecipesState с данными', () {
const recipe = Recipe(
id: 1,
image: 'https://example.com/image.jpg',
state: 'active',
cookingTime: 30,
activeCookingTime: 15,
ingredients: [],
description: 'Test description',
steps: [],
videoUrl: null,
createdAt: null,
updatedAt: null,
title: 'Test Recipe',
type: 'main',
slug: 'test-recipe',
commentsCount: 5,
wasLikedByMe: false,
isFavorite: false,
calories: 300.0,
servings: 4,
likesCount: 10,
viewsCount: 100,
tags: [],
author: Author(
authorSlug: 'author',
authorName: 'Author Name',
authorProfileIcon: 'https://example.com/icon.jpg',
authorIsMe: false,
isEntitySubscribedByMe: null,
authorPlaceInRating: null,
),
);
final tag = RecipeTag(
id: 1,
name: 'Breakfast',
recipesCount: 10,
createdAt: DateTime(2024, 1, 1),
updatedAt: DateTime(2024, 1, 2),
);
final state = RecipesState(
recipesList: [recipe],
recipesTags: [tag],
selectedTags: {1},
selectedTagsCounter: 1,
isLoading: false,
errorMessage: null,
);
expect(state.recipesList.length, 1);
expect(state.recipesTags.length, 1);
expect(state.selectedTags.length, 1);
});
});
}