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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user