forked from eatvio/eatvio_app
feat(dependencies): add rxdart package and improve string extension methods for better handling of empty strings and gender parsing
This commit is contained in:
36
test/features/complaining/models/complain_model_test.dart
Normal file
36
test/features/complaining/models/complain_model_test.dart
Normal file
@@ -0,0 +1,36 @@
|
||||
import 'package:eatvio_app/features/complaining/models/complain_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('ComplainModel', () {
|
||||
test('создает ComplainModel с дефолтными значениями', () {
|
||||
const model = ComplainModel();
|
||||
|
||||
expect(model.description, isNull);
|
||||
expect(model.tags, isEmpty);
|
||||
});
|
||||
|
||||
test('создает ComplainModel с описанием и тегами', () {
|
||||
const model = ComplainModel(
|
||||
description: 'Test complaint',
|
||||
tags: ['tag1', 'tag2'],
|
||||
);
|
||||
|
||||
expect(model.description, 'Test complaint');
|
||||
expect(model.tags, ['tag1', 'tag2']);
|
||||
});
|
||||
|
||||
test('fromJson создает ComplainModel из JSON', () {
|
||||
final json = {
|
||||
'description': 'Test complaint',
|
||||
'tags': ['tag1', 'tag2'],
|
||||
};
|
||||
|
||||
final model = ComplainModel.fromJson(json);
|
||||
|
||||
expect(model.description, 'Test complaint');
|
||||
expect(model.tags, ['tag1', 'tag2']);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
import 'package:eatvio_app/core/enums/complained_content.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/repositories/complaining_repository.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'complaining_cubit_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<ComplainingRepository>()])
|
||||
void main() {
|
||||
group('ComplainingCubit', () {
|
||||
ComplainingCubit? complainingCubit;
|
||||
late MockComplainingRepository mockRepository;
|
||||
|
||||
setUp(() {
|
||||
mockRepository = MockComplainingRepository();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
if (complainingCubit != null && !complainingCubit!.isClosed) {
|
||||
await complainingCubit!.close();
|
||||
complainingCubit = null;
|
||||
}
|
||||
});
|
||||
|
||||
test('начальное состояние - пустое', () {
|
||||
complainingCubit = ComplainingCubit(repository: mockRepository);
|
||||
|
||||
expect(complainingCubit!.state.contentType, isNull);
|
||||
expect(complainingCubit!.state.category, isNull);
|
||||
expect(complainingCubit!.state.wasSentSuccessfully, isNull);
|
||||
});
|
||||
|
||||
test('setContentTypeAndIdentifier - устанавливает тип контента и идентификатор', () {
|
||||
complainingCubit = ComplainingCubit(repository: mockRepository);
|
||||
|
||||
complainingCubit!.setContentTypeAndIdentifier(
|
||||
contentType: ComplainedContent.diet,
|
||||
id: 1,
|
||||
);
|
||||
|
||||
expect(complainingCubit!.state.contentType, ComplainedContent.diet);
|
||||
expect(complainingCubit!.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(
|
||||
contentType: ComplainedContent.plan,
|
||||
slug: 'test-plan',
|
||||
);
|
||||
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);
|
||||
});
|
||||
|
||||
test('complain - обработка ошибки', () async {
|
||||
complainingCubit = ComplainingCubit(repository: mockRepository);
|
||||
|
||||
complainingCubit!.setContentTypeAndIdentifier(
|
||||
contentType: ComplainedContent.diet,
|
||||
id: 1,
|
||||
);
|
||||
complainingCubit!.setCategory(ComplainType.spam);
|
||||
|
||||
when(mockRepository.sendDietComplain(
|
||||
id: anyNamed('id'),
|
||||
category: anyNamed('category'),
|
||||
body: anyNamed('body'),
|
||||
)).thenThrow(Exception('Ошибка отправки'));
|
||||
|
||||
await complainingCubit!.complain();
|
||||
|
||||
expect(complainingCubit!.state.wasSentSuccessfully, isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
import 'package:eatvio_app/features/complaining/models/complain_model.dart';
|
||||
import 'package:eatvio_app/features/complaining/repositories/complaining_repository.dart';
|
||||
import 'package:eatvio_app/features/complaining/services/complaining_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'complaining_repository_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<ComplainingService>()])
|
||||
void main() {
|
||||
group('ComplainingRepository', () {
|
||||
late ComplainingRepository repository;
|
||||
late MockComplainingService mockService;
|
||||
|
||||
setUp(() {
|
||||
mockService = MockComplainingService();
|
||||
repository = ComplainingRepository(service: mockService);
|
||||
});
|
||||
|
||||
test('sendPlanComplain - успешная отправка жалобы на план', () async {
|
||||
const slug = 'test-plan';
|
||||
const category = 'spam';
|
||||
const body = ComplainModel(
|
||||
description: 'Test complaint',
|
||||
tags: ['tag1', 'tag2'],
|
||||
);
|
||||
|
||||
when(mockService.sendPlanComplain(slug: slug, category: category, body: body))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await repository.sendPlanComplain(slug: slug, category: category, body: body);
|
||||
|
||||
verify(mockService.sendPlanComplain(slug: slug, category: category, body: body)).called(1);
|
||||
});
|
||||
|
||||
test('sendRecipeComplain - успешная отправка жалобы на рецепт', () async {
|
||||
const slug = 'test-recipe';
|
||||
const category = 'spam';
|
||||
const body = ComplainModel(
|
||||
description: 'Test complaint',
|
||||
tags: ['tag1'],
|
||||
);
|
||||
|
||||
when(mockService.sendRecipeComplain(slug: slug, category: category, body: body))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await repository.sendRecipeComplain(slug: slug, category: category, body: body);
|
||||
|
||||
verify(mockService.sendRecipeComplain(slug: slug, category: category, body: body)).called(1);
|
||||
});
|
||||
|
||||
test('sendBlogPostsComplain - успешная отправка жалобы на пост', () async {
|
||||
const id = 1;
|
||||
const category = 'spam';
|
||||
const body = ComplainModel(
|
||||
description: 'Test complaint',
|
||||
tags: [],
|
||||
);
|
||||
|
||||
when(mockService.sendBlogPostsComplain(id: id, category: category, body: body))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await repository.sendBlogPostsComplain(id: id, category: category, body: body);
|
||||
|
||||
verify(mockService.sendBlogPostsComplain(id: id, category: category, body: body)).called(1);
|
||||
});
|
||||
|
||||
test('sendProfileComplain - успешная отправка жалобы на профиль', () async {
|
||||
const slug = 'test-profile';
|
||||
const category = 'spam';
|
||||
const body = ComplainModel(
|
||||
description: 'Test complaint',
|
||||
tags: ['tag1'],
|
||||
);
|
||||
|
||||
when(mockService.sendProfileComplain(slug: slug, category: category, body: body))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await repository.sendProfileComplain(slug: slug, category: category, body: body);
|
||||
|
||||
verify(mockService.sendProfileComplain(slug: slug, category: category, body: body)).called(1);
|
||||
});
|
||||
|
||||
test('sendDietComplain - успешная отправка жалобы на диету', () async {
|
||||
const id = 1;
|
||||
const category = 'spam';
|
||||
const body = ComplainModel(
|
||||
description: 'Test complaint',
|
||||
tags: ['tag1'],
|
||||
);
|
||||
|
||||
when(mockService.sendDietComplain(id: id, category: category, body: body))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await repository.sendDietComplain(id: id, category: category, body: body);
|
||||
|
||||
verify(mockService.sendDietComplain(id: id, category: category, body: body)).called(1);
|
||||
});
|
||||
|
||||
test('sendCommentComplain - успешная отправка жалобы на комментарий', () async {
|
||||
const id = 1;
|
||||
const category = 'spam';
|
||||
const body = ComplainModel(
|
||||
description: 'Test complaint',
|
||||
tags: ['tag1'],
|
||||
);
|
||||
|
||||
when(mockService.sendCommentComplain(id: id, category: category, body: body))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await repository.sendCommentComplain(id: id, category: category, body: body);
|
||||
|
||||
verify(mockService.sendCommentComplain(id: id, category: category, body: body)).called(1);
|
||||
});
|
||||
|
||||
test('sendPlanComplain - пробрасывает исключение', () async {
|
||||
const slug = 'test-plan';
|
||||
const category = 'spam';
|
||||
const body = ComplainModel();
|
||||
|
||||
when(mockService.sendPlanComplain(slug: slug, category: category, body: body))
|
||||
.thenThrow(Exception('Ошибка отправки жалобы'));
|
||||
|
||||
expect(
|
||||
() => repository.sendPlanComplain(slug: slug, category: category, body: body),
|
||||
throwsException,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user