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:
@@ -0,0 +1,84 @@
|
||||
import 'package:eatvio_app/features/cancel_plan_bottom_sheet/cubit/cancel_plan_cubit.dart';
|
||||
import 'package:eatvio_app/features/cancel_plan_bottom_sheet/cubit/cancel_plan_state.dart';
|
||||
import 'package:eatvio_app/features/cancel_plan_bottom_sheet/repository/cancel_plan_repository.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'cancel_plan_cubit_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<CancelPlanRepository>()])
|
||||
void main() {
|
||||
group('CancelPlanCubit', () {
|
||||
CancelPlanCubit? cubit;
|
||||
late MockCancelPlanRepository mockRepository;
|
||||
|
||||
setUp(() {
|
||||
mockRepository = MockCancelPlanRepository();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
if (cubit != null && !cubit!.isClosed) {
|
||||
await cubit!.close();
|
||||
cubit = null;
|
||||
}
|
||||
});
|
||||
|
||||
test('начальное состояние - пустое', () {
|
||||
cubit = CancelPlanCubit(cancelPlanRepository: mockRepository);
|
||||
|
||||
expect(cubit!.state, isA<CancelPlanState>());
|
||||
});
|
||||
|
||||
test('cancelChosenPlan - успешная отмена плана без причины', () async {
|
||||
cubit = CancelPlanCubit(cancelPlanRepository: mockRepository);
|
||||
|
||||
when(mockRepository.cancelChosenPlan(
|
||||
id: 1,
|
||||
body: anyNamed('body'),
|
||||
)).thenAnswer((_) async => {});
|
||||
|
||||
final result = await cubit!.cancelChosenPlan(id: 1);
|
||||
|
||||
expect(result, isTrue);
|
||||
verify(mockRepository.cancelChosenPlan(id: 1, body: null)).called(1);
|
||||
});
|
||||
|
||||
test('cancelChosenPlan - успешная отмена плана с причиной', () async {
|
||||
cubit = CancelPlanCubit(cancelPlanRepository: mockRepository);
|
||||
|
||||
when(mockRepository.cancelChosenPlan(
|
||||
id: anyNamed('id'),
|
||||
body: anyNamed('body'),
|
||||
)).thenAnswer((_) async => {});
|
||||
|
||||
final result = await cubit!.cancelChosenPlan(
|
||||
id: 1,
|
||||
reason: 'Test reason',
|
||||
price: 1000,
|
||||
);
|
||||
|
||||
expect(result, isTrue);
|
||||
verify(mockRepository.cancelChosenPlan(
|
||||
id: 1,
|
||||
body: anyNamed('body'),
|
||||
)).called(1);
|
||||
});
|
||||
|
||||
test('cancelChosenPlan - обработка ошибки', () async {
|
||||
cubit = CancelPlanCubit(cancelPlanRepository: mockRepository);
|
||||
|
||||
when(mockRepository.cancelChosenPlan(
|
||||
id: anyNamed('id'),
|
||||
body: anyNamed('body'),
|
||||
)).thenAnswer((_) async {
|
||||
throw Exception('Ошибка отмены');
|
||||
});
|
||||
|
||||
final result = await cubit!.cancelChosenPlan(id: 1);
|
||||
|
||||
expect(result, isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import 'package:eatvio_app/features/cancel_plan_bottom_sheet/models/cancelation_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('CancelationModel', () {
|
||||
test('создает CancelationModel с правильными значениями', () {
|
||||
final model = CancelationModel(
|
||||
description: 'Test reason',
|
||||
price: 1000,
|
||||
);
|
||||
|
||||
expect(model.description, 'Test reason');
|
||||
expect(model.price, 1000);
|
||||
});
|
||||
|
||||
test('fromJson создает CancelationModel из JSON', () {
|
||||
final json = {
|
||||
'description': 'Test reason',
|
||||
'price': 1000,
|
||||
};
|
||||
|
||||
final model = CancelationModel.fromJson(json);
|
||||
|
||||
expect(model.description, 'Test reason');
|
||||
expect(model.price, 1000);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import 'package:eatvio_app/features/cancel_plan_bottom_sheet/models/cancelation_model.dart';
|
||||
import 'package:eatvio_app/features/cancel_plan_bottom_sheet/repository/cancel_plan_repository.dart';
|
||||
import 'package:eatvio_app/features/cancel_plan_bottom_sheet/service/cancel_plan_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'cancel_plan_repository_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<CancelPlanService>()])
|
||||
void main() {
|
||||
group('CancelPlanRepository', () {
|
||||
late CancelPlanRepository repository;
|
||||
late MockCancelPlanService mockService;
|
||||
|
||||
setUp(() {
|
||||
mockService = MockCancelPlanService();
|
||||
repository = CancelPlanRepository(cancelService: mockService);
|
||||
});
|
||||
|
||||
test('cancelChosenPlan - успешная отмена плана без body', () async {
|
||||
const id = 1;
|
||||
|
||||
when(mockService.cancelChosenPlan(id: id, body: null))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await repository.cancelChosenPlan(id: id, body: null);
|
||||
|
||||
verify(mockService.cancelChosenPlan(id: id, body: null)).called(1);
|
||||
});
|
||||
|
||||
test('cancelChosenPlan - успешная отмена плана с body', () async {
|
||||
const id = 1;
|
||||
final body = CancelationModel(
|
||||
description: 'Test reason',
|
||||
price: 1000,
|
||||
);
|
||||
|
||||
when(mockService.cancelChosenPlan(id: id, body: body))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await repository.cancelChosenPlan(id: id, body: body);
|
||||
|
||||
verify(mockService.cancelChosenPlan(id: id, body: body)).called(1);
|
||||
});
|
||||
|
||||
test('cancelChosenPlan - пробрасывает исключение', () async {
|
||||
const id = 1;
|
||||
|
||||
when(mockService.cancelChosenPlan(id: id, body: null))
|
||||
.thenThrow(Exception('Ошибка отмены плана'));
|
||||
|
||||
expect(
|
||||
() => repository.cancelChosenPlan(id: id, body: null),
|
||||
throwsException,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user