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,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);
});
});
}