import 'package:eatvio_app/core/enums/complained_content.dart'; import 'package:eatvio_app/features/complaining/models/complain_model.dart'; import 'package:eatvio_app/features/complaining/presentation/complaining_bottom_sheet.dart'; import 'package:eatvio_app/features/complaining/presentation/cubit/complaining_cubit.dart'; import 'package:eatvio_app/features/complaining/presentation/cubit/complaining_state.dart'; import 'package:eatvio_app/features/complaining/repositories/complaining_repository.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mocktail/mocktail.dart'; class MockComplainingRepository extends Mock implements ComplainingRepository {} void main() { group('ComplainingCubit', () { late ComplainingCubit cubit; late MockComplainingRepository mockRepository; setUpAll(() { registerFallbackValue(const ComplainModel()); }); setUp(() { mockRepository = MockComplainingRepository(); cubit = ComplainingCubit(repository: mockRepository); }); tearDown(() { cubit.close(); }); test('начальное состояние - ComplainingState', () { expect(cubit.state, isA()); }); test('setContentTypeAndIdentifier устанавливает тип и идентификатор', () { cubit.setContentTypeAndIdentifier( contentType: ComplainedContent.diet, id: 1, ); expect(cubit.state.contentType, ComplainedContent.diet); expect(cubit.state.contentId, 1); }); test('setContentTypeAndIdentifier устанавливает slug', () { cubit.setContentTypeAndIdentifier( contentType: ComplainedContent.plan, slug: 'test-slug', ); expect(cubit.state.contentType, ComplainedContent.plan); expect(cubit.state.contentSlug, 'test-slug'); }); test('setCategory устанавливает категорию', () { cubit.setCategory(ComplainType.spam); expect(cubit.state.category, ComplainType.spam); }); test('setTags устанавливает теги', () { final tags = ['tag1', 'tag2']; cubit.setTags(tags); expect(cubit.state.complainInfo.tags, tags); }); test('toggleDescription переключает описание', () { // Включает описание cubit.toggleDescription(); expect(cubit.state.complainInfo.description, ''); // Выключает описание cubit.toggleDescription(); expect(cubit.state.complainInfo.description, null); }); test('setDescription устанавливает описание', () { const description = 'Test description'; cubit.setDescription(description); expect(cubit.state.complainInfo.description, description); }); test('complain - отправляет жалобу на diet', () async { const id = 1; when(() => mockRepository.sendDietComplain( id: id, category: any(named: 'category'), body: any(named: 'body'), )).thenAnswer((_) async => {}); cubit.setContentTypeAndIdentifier(contentType: ComplainedContent.diet, id: id); cubit.setCategory(ComplainType.spam); cubit.setTags(['tag1']); await cubit.complain(); expect(cubit.state.wasSentSuccessfully, true); verify(() => mockRepository.sendDietComplain( id: id, category: any(named: 'category'), body: any(named: 'body'), )).called(1); }); test('complain - возвращает false при ошибке', () async { const id = 1; when(() => mockRepository.sendDietComplain( id: id, category: any(named: 'category'), body: any(named: 'body'), )).thenThrow(Exception('Error')); cubit.setContentTypeAndIdentifier(contentType: ComplainedContent.diet, id: id); cubit.setCategory(ComplainType.spam); await cubit.complain(); expect(cubit.state.wasSentSuccessfully, false); }); }); }