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,190 @@
import 'package:eatvio_app/features/diets/models/diet_likes_model.dart';
import 'package:eatvio_app/features/diets/presentation/cubit/about_diet_cubit.dart';
import 'package:eatvio_app/features/diets/presentation/cubit/about_diet_state.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/profile/repositories/profile_repository.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'about_diet_cubit_test.mocks.dart';
@GenerateNiceMocks([
MockSpec<DietRepository>(),
MockSpec<ProfileRepository>(),
])
void main() {
group('AboutDietCubit', () {
AboutDietCubit? aboutDietCubit;
late MockDietRepository mockDietRepository;
late MockProfileRepository mockProfileRepository;
setUp(() {
mockDietRepository = MockDietRepository();
mockProfileRepository = MockProfileRepository();
});
tearDown(() async {
if (aboutDietCubit != null && !aboutDietCubit!.isClosed) {
await aboutDietCubit!.close();
aboutDietCubit = null;
}
});
test('начальное состояние - initial', () {
aboutDietCubit = AboutDietCubit(
dietsRepository: mockDietRepository,
profileRepository: mockProfileRepository,
);
expect(aboutDietCubit!.state, isA<AboutDietState>());
});
test('getDiet - успешная загрузка диеты по slug', () async {
aboutDietCubit = AboutDietCubit(
dietsRepository: mockDietRepository,
profileRepository: mockProfileRepository,
);
const testDiet = Diet(
id: 1,
slug: 'test-diet',
name: 'Test Diet',
image: 'https://example.com/image.jpg',
duration: 7,
state: DietState.active,
type: DietType(veg: true, light: false, carb: false, meat: false),
details: 'Test details',
dailySchedule: {},
author: Author(
authorSlug: 'author',
authorName: 'Author Name',
authorProfileIcon: 'https://example.com/icon.jpg',
authorIsMe: false,
isEntitySubscribedByMe: null,
authorPlaceInRating: null,
),
totalLikes: 10,
totalViews: 100,
totalComments: 5,
wasLikedByMe: false,
isFavorite: false,
dailyNutrition: [],
);
when(mockDietRepository.getDietBySlug('test-diet'))
.thenAnswer((_) async => testDiet);
await aboutDietCubit!.getDiet(slug: 'test-diet');
expect(aboutDietCubit!.state, isA<DietStateLoaded>());
final loadedState = aboutDietCubit!.state as DietStateLoaded;
expect(loadedState.diet.id, 1);
});
test('getDiet - успешная загрузка диеты по id', () async {
aboutDietCubit = AboutDietCubit(
dietsRepository: mockDietRepository,
profileRepository: mockProfileRepository,
);
const testDiet = Diet(
id: 1,
slug: 'test-diet',
name: 'Test Diet',
image: 'https://example.com/image.jpg',
duration: 7,
state: DietState.active,
type: DietType(veg: true, light: false, carb: false, meat: false),
details: 'Test details',
dailySchedule: {},
author: Author(
authorSlug: 'author',
authorName: 'Author Name',
authorProfileIcon: 'https://example.com/icon.jpg',
authorIsMe: false,
isEntitySubscribedByMe: null,
authorPlaceInRating: null,
),
totalLikes: 10,
totalViews: 100,
totalComments: 5,
wasLikedByMe: false,
isFavorite: false,
dailyNutrition: [],
);
when(mockDietRepository.getDiet(1))
.thenAnswer((_) async => testDiet);
await aboutDietCubit!.getDiet(id: 1);
expect(aboutDietCubit!.state, isA<DietStateLoaded>());
});
test('getDiet - обработка ошибки', () async {
aboutDietCubit = AboutDietCubit(
dietsRepository: mockDietRepository,
profileRepository: mockProfileRepository,
);
when(mockDietRepository.getDietBySlug(any))
.thenThrow(Exception('Ошибка загрузки'));
await aboutDietCubit!.getDiet(slug: 'test-diet');
expect(aboutDietCubit!.state, isA<DietStateError>());
});
test('likeDiet - лайк диеты', () async {
aboutDietCubit = AboutDietCubit(
dietsRepository: mockDietRepository,
profileRepository: mockProfileRepository,
);
const testDiet = Diet(
id: 1,
slug: 'test-diet',
name: 'Test Diet',
image: 'https://example.com/image.jpg',
duration: 7,
state: DietState.active,
type: DietType(veg: true, light: false, carb: false, meat: false),
details: 'Test details',
dailySchedule: {},
author: Author(
authorSlug: 'author',
authorName: 'Author Name',
authorProfileIcon: 'https://example.com/icon.jpg',
authorIsMe: false,
isEntitySubscribedByMe: null,
authorPlaceInRating: null,
),
totalLikes: 10,
totalViews: 100,
totalComments: 5,
wasLikedByMe: false,
isFavorite: false,
dailyNutrition: [],
);
when(mockDietRepository.getDietBySlug('test-diet'))
.thenAnswer((_) async => testDiet);
when(mockDietRepository.likeDiet(1))
.thenAnswer((_) async => const DietLikesModel(
totalLikes: 11,
isLiked: true,
));
await aboutDietCubit!.getDiet(slug: 'test-diet');
await aboutDietCubit!.likeDiet(1, null);
await Future.delayed(const Duration(milliseconds: 1200));
expect(aboutDietCubit!.state, isA<DietStateLoaded>());
final loadedState = aboutDietCubit!.state as DietStateLoaded;
expect(loadedState.diet.wasLikedByMe, isTrue);
});
});
}