forked from eatvio/eatvio_app
chore(version): update app version to 1.3.5+85 and improve test coverage reporting in CI
This commit is contained in:
@@ -1,143 +1,124 @@
|
||||
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:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
|
||||
import 'complaining_cubit_test.mocks.dart';
|
||||
class MockComplainingRepository extends Mock implements ComplainingRepository {}
|
||||
|
||||
@GenerateNiceMocks([MockSpec<ComplainingRepository>()])
|
||||
void main() {
|
||||
group('ComplainingCubit', () {
|
||||
ComplainingCubit? complainingCubit;
|
||||
late ComplainingCubit cubit;
|
||||
late MockComplainingRepository mockRepository;
|
||||
|
||||
setUpAll(() {
|
||||
registerFallbackValue(const ComplainModel());
|
||||
});
|
||||
|
||||
setUp(() {
|
||||
mockRepository = MockComplainingRepository();
|
||||
cubit = ComplainingCubit(repository: mockRepository);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
if (complainingCubit != null && !complainingCubit!.isClosed) {
|
||||
await complainingCubit!.close();
|
||||
complainingCubit = null;
|
||||
}
|
||||
tearDown(() {
|
||||
cubit.close();
|
||||
});
|
||||
|
||||
test('начальное состояние - пустое', () {
|
||||
complainingCubit = ComplainingCubit(repository: mockRepository);
|
||||
|
||||
expect(complainingCubit!.state.contentType, isNull);
|
||||
expect(complainingCubit!.state.category, isNull);
|
||||
expect(complainingCubit!.state.wasSentSuccessfully, isNull);
|
||||
test('начальное состояние - ComplainingState', () {
|
||||
expect(cubit.state, isA<ComplainingState>());
|
||||
});
|
||||
|
||||
test('setContentTypeAndIdentifier - устанавливает тип контента и идентификатор', () {
|
||||
complainingCubit = ComplainingCubit(repository: mockRepository);
|
||||
|
||||
complainingCubit!.setContentTypeAndIdentifier(
|
||||
test('setContentTypeAndIdentifier устанавливает тип и идентификатор', () {
|
||||
cubit.setContentTypeAndIdentifier(
|
||||
contentType: ComplainedContent.diet,
|
||||
id: 1,
|
||||
);
|
||||
|
||||
expect(complainingCubit!.state.contentType, ComplainedContent.diet);
|
||||
expect(complainingCubit!.state.contentId, 1);
|
||||
expect(cubit.state.contentType, ComplainedContent.diet);
|
||||
expect(cubit.state.contentId, 1);
|
||||
});
|
||||
|
||||
test('setCategory - устанавливает категорию жалобы', () {
|
||||
complainingCubit = ComplainingCubit(repository: mockRepository);
|
||||
|
||||
complainingCubit!.setCategory(ComplainType.spam);
|
||||
|
||||
expect(complainingCubit!.state.category, ComplainType.spam);
|
||||
});
|
||||
|
||||
test('setTags - устанавливает теги', () {
|
||||
complainingCubit = ComplainingCubit(repository: mockRepository);
|
||||
|
||||
complainingCubit!.setTags(['tag1', 'tag2']);
|
||||
|
||||
expect(complainingCubit!.state.complainInfo.tags, ['tag1', 'tag2']);
|
||||
});
|
||||
|
||||
test('toggleDescription - переключает описание', () {
|
||||
complainingCubit = ComplainingCubit(repository: mockRepository);
|
||||
|
||||
complainingCubit!.toggleDescription();
|
||||
expect(complainingCubit!.state.complainInfo.description, '');
|
||||
|
||||
complainingCubit!.toggleDescription();
|
||||
expect(complainingCubit!.state.complainInfo.description, isNull);
|
||||
});
|
||||
|
||||
test('setDescription - устанавливает описание', () {
|
||||
complainingCubit = ComplainingCubit(repository: mockRepository);
|
||||
|
||||
complainingCubit!.setDescription('Test description');
|
||||
|
||||
expect(complainingCubit!.state.complainInfo.description, 'Test description');
|
||||
});
|
||||
|
||||
test('complain - отправляет жалобу на диету', () async {
|
||||
complainingCubit = ComplainingCubit(repository: mockRepository);
|
||||
|
||||
complainingCubit!.setContentTypeAndIdentifier(
|
||||
contentType: ComplainedContent.diet,
|
||||
id: 1,
|
||||
);
|
||||
complainingCubit!.setCategory(ComplainType.spam);
|
||||
|
||||
when(mockRepository.sendDietComplain(
|
||||
id: 1,
|
||||
category: anyNamed('category'),
|
||||
body: anyNamed('body'),
|
||||
)).thenAnswer((_) async => {});
|
||||
|
||||
await complainingCubit!.complain();
|
||||
|
||||
expect(complainingCubit!.state.wasSentSuccessfully, isTrue);
|
||||
});
|
||||
|
||||
test('complain - отправляет жалобу на план', () async {
|
||||
complainingCubit = ComplainingCubit(repository: mockRepository);
|
||||
|
||||
complainingCubit!.setContentTypeAndIdentifier(
|
||||
test('setContentTypeAndIdentifier устанавливает slug', () {
|
||||
cubit.setContentTypeAndIdentifier(
|
||||
contentType: ComplainedContent.plan,
|
||||
slug: 'test-plan',
|
||||
slug: 'test-slug',
|
||||
);
|
||||
complainingCubit!.setCategory(ComplainType.spam);
|
||||
|
||||
when(mockRepository.sendPlanComplain(
|
||||
slug: 'test-plan',
|
||||
category: anyNamed('category'),
|
||||
body: anyNamed('body'),
|
||||
)).thenAnswer((_) async => {});
|
||||
|
||||
await complainingCubit!.complain();
|
||||
|
||||
expect(complainingCubit!.state.wasSentSuccessfully, isTrue);
|
||||
expect(cubit.state.contentType, ComplainedContent.plan);
|
||||
expect(cubit.state.contentSlug, 'test-slug');
|
||||
});
|
||||
|
||||
test('complain - обработка ошибки', () async {
|
||||
complainingCubit = ComplainingCubit(repository: mockRepository);
|
||||
test('setCategory устанавливает категорию', () {
|
||||
cubit.setCategory(ComplainType.spam);
|
||||
|
||||
complainingCubit!.setContentTypeAndIdentifier(
|
||||
contentType: ComplainedContent.diet,
|
||||
id: 1,
|
||||
);
|
||||
complainingCubit!.setCategory(ComplainType.spam);
|
||||
expect(cubit.state.category, ComplainType.spam);
|
||||
});
|
||||
|
||||
when(mockRepository.sendDietComplain(
|
||||
id: anyNamed('id'),
|
||||
category: anyNamed('category'),
|
||||
body: anyNamed('body'),
|
||||
)).thenThrow(Exception('Ошибка отправки'));
|
||||
test('setTags устанавливает теги', () {
|
||||
final tags = ['tag1', 'tag2'];
|
||||
cubit.setTags(tags);
|
||||
|
||||
await complainingCubit!.complain();
|
||||
expect(cubit.state.complainInfo.tags, tags);
|
||||
});
|
||||
|
||||
expect(complainingCubit!.state.wasSentSuccessfully, isFalse);
|
||||
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user