feat(feed): fixed comments state updating in feed, feat(consultantRegistration): fixed registration flow for users with unverified phone, feat(tests): fixed tests coverage

This commit is contained in:
misha
2026-04-01 10:37:59 +03:00
parent ee2dd75a94
commit a13b623ca2
20 changed files with 949 additions and 343 deletions

View File

@@ -71,7 +71,7 @@ void main() {
when(mockPlanRepository.getPlan('test-plan')).thenAnswer((_) async => testPlan);
await aboutPlanCubit!.getPlan('test-plan');
await aboutPlanCubit!.getPlan(slug: 'test-plan');
expect(aboutPlanCubit!.state.planModel, isNotNull);
expect(aboutPlanCubit!.state.planModel!.id, 1);
@@ -157,7 +157,7 @@ void main() {
when(mockPlanRepository.getPlan('test-plan')).thenAnswer((_) async => testPlan);
when(mockPlanRepository.likePlan('test-plan')).thenAnswer((_) async => {});
await aboutPlanCubit!.getPlan('test-plan');
await aboutPlanCubit!.getPlan(slug: 'test-plan');
await aboutPlanCubit!.likePlan(index: null, slug: 'test-plan');
await Future.delayed(const Duration(milliseconds: 1200));
@@ -170,7 +170,7 @@ void main() {
when(mockPlanRepository.getPlan('test-plan')).thenThrow(Exception('Ошибка загрузки'));
await aboutPlanCubit!.getPlan('test-plan');
await aboutPlanCubit!.getPlan(slug: 'test-plan');
expect(aboutPlanCubit!.state.error, isNotNull);
expect(aboutPlanCubit!.state.isLoading, isFalse);
@@ -220,7 +220,7 @@ void main() {
when(mockPlanRepository.getPlan('test-plan')).thenAnswer((_) async => testPlan);
when(mockPlanRepository.likePlan('test-plan')).thenAnswer((_) async => {});
await aboutPlanCubit!.getPlan('test-plan');
await aboutPlanCubit!.getPlan(slug: 'test-plan');
await aboutPlanCubit!.likePlan(index: null, slug: 'test-plan');
expect(aboutPlanCubit!.state.planModel!.wasLikedByMe, isFalse);
@@ -263,7 +263,7 @@ void main() {
when(mockPlanRepository.getPlan('test-plan')).thenAnswer((_) async => testPlan);
when(mockPlanRepository.addToFavorite('test-plan')).thenAnswer((_) async => Future<void>.value());
await aboutPlanCubit!.getPlan('test-plan');
await aboutPlanCubit!.getPlan(slug: 'test-plan');
await aboutPlanCubit!.addToFavorite(slug: 'test-plan', index: null);
expect(aboutPlanCubit!.state.planModel!.isFavorite, true);
@@ -305,7 +305,7 @@ void main() {
when(mockPlanRepository.getPlan('test-plan')).thenAnswer((_) async => testPlan);
when(mockPlanRepository.removeFromFavorite('test-plan')).thenAnswer((_) async => Future<void>.value());
await aboutPlanCubit!.getPlan('test-plan');
await aboutPlanCubit!.getPlan(slug: 'test-plan');
await aboutPlanCubit!.removeFromFavorite(slug: 'test-plan', index: null);
expect(aboutPlanCubit!.state.planModel!.isFavorite, false);
@@ -357,7 +357,7 @@ void main() {
when(mockPlanRepository.getPlan('test-plan')).thenAnswer((_) async => testPlan);
when(mockPlanRepository.chosePlan('test-plan', any)).thenAnswer((_) async => chosenPlan);
await aboutPlanCubit!.getPlan('test-plan');
await aboutPlanCubit!.getPlan(slug: 'test-plan');
aboutPlanCubit!.choseOption(0);
final result = await aboutPlanCubit!.chosePlan();
@@ -405,7 +405,7 @@ void main() {
),
);
await aboutPlanCubit!.getPlan('test-plan');
await aboutPlanCubit!.getPlan(slug: 'test-plan');
aboutPlanCubit!.choseOption(0);
final result = await aboutPlanCubit!.chosePlan();
@@ -447,7 +447,7 @@ void main() {
when(mockPlanRepository.getPlan('test-plan')).thenAnswer((_) async => testPlan);
when(mockPlanRepository.likePlan('test-plan')).thenAnswer((_) async => {});
await aboutPlanCubit!.getPlan('test-plan');
await aboutPlanCubit!.getPlan(slug: 'test-plan');
await aboutPlanCubit!.likePlan(index: 5, slug: 'test-plan');
expect(aboutPlanCubit!.state.planModel!.wasLikedByMe, isTrue);
@@ -490,7 +490,7 @@ void main() {
when(mockPlanRepository.getPlan('test-plan')).thenAnswer((_) async => testPlan);
when(mockPlanRepository.likePlan('test-plan')).thenAnswer((_) async => {});
await aboutPlanCubit!.getPlan('test-plan');
await aboutPlanCubit!.getPlan(slug: 'test-plan');
await aboutPlanCubit!.likePlan(index: 5, slug: 'test-plan');
expect(aboutPlanCubit!.state.planModel!.wasLikedByMe, isFalse);
@@ -533,7 +533,7 @@ void main() {
when(mockPlanRepository.getPlan('test-plan')).thenAnswer((_) async => testPlan);
when(mockPlanRepository.likePlan('test-plan')).thenThrow(Exception('Ошибка'));
await aboutPlanCubit!.getPlan('test-plan');
await aboutPlanCubit!.getPlan(slug: 'test-plan');
await aboutPlanCubit!.likePlan(index: 5, slug: 'test-plan');
// Проверяем, что состояние изменилось сразу после вызова
@@ -583,7 +583,7 @@ void main() {
when(mockPlanRepository.getPlan('test-plan')).thenAnswer((_) async => testPlan);
when(mockPlanRepository.addToFavorite('test-plan')).thenAnswer((_) async => Future<void>.value());
await aboutPlanCubit!.getPlan('test-plan');
await aboutPlanCubit!.getPlan(slug: 'test-plan');
await aboutPlanCubit!.addToFavorite(slug: 'test-plan', index: 5);
expect(aboutPlanCubit!.state.planModel!.isFavorite, true);
@@ -624,7 +624,7 @@ void main() {
when(mockPlanRepository.getPlan('test-plan')).thenAnswer((_) async => testPlan);
when(mockPlanRepository.addToFavorite('test-plan')).thenThrow(Exception('Ошибка'));
await aboutPlanCubit!.getPlan('test-plan');
await aboutPlanCubit!.getPlan(slug: 'test-plan');
await aboutPlanCubit!.addToFavorite(slug: 'test-plan', index: 5);
// Проверяем, что состояние изменилось сразу после вызова
@@ -673,7 +673,7 @@ void main() {
when(mockPlanRepository.getPlan('test-plan')).thenAnswer((_) async => testPlan);
when(mockPlanRepository.removeFromFavorite('test-plan')).thenAnswer((_) async => Future<void>.value());
await aboutPlanCubit!.getPlan('test-plan');
await aboutPlanCubit!.getPlan(slug: 'test-plan');
await aboutPlanCubit!.removeFromFavorite(slug: 'test-plan', index: 5);
expect(aboutPlanCubit!.state.planModel!.isFavorite, false);
@@ -714,7 +714,7 @@ void main() {
when(mockPlanRepository.getPlan('test-plan')).thenAnswer((_) async => testPlan);
when(mockPlanRepository.removeFromFavorite('test-plan')).thenThrow(Exception('Ошибка'));
await aboutPlanCubit!.getPlan('test-plan');
await aboutPlanCubit!.getPlan(slug: 'test-plan');
await aboutPlanCubit!.removeFromFavorite(slug: 'test-plan', index: 5);
// Проверяем, что состояние изменилось сразу после вызова
@@ -773,7 +773,7 @@ void main() {
when(mockPlanRepository.getPlan('test-plan')).thenAnswer((_) async => testPlan);
when(mockPlanRepository.chosePlan('test-plan', any)).thenAnswer((_) async => chosenPlan);
await aboutPlanCubit!.getPlan('test-plan');
await aboutPlanCubit!.getPlan(slug: 'test-plan');
aboutPlanCubit!.choseOption(1);
final result = await aboutPlanCubit!.chosePlan();
@@ -826,7 +826,7 @@ void main() {
when(mockPlanRepository.getPlan('test-plan')).thenAnswer((_) async => testPlan);
when(mockPlanRepository.chosePlan('test-plan', any)).thenAnswer((_) async => chosenPlan);
await aboutPlanCubit!.getPlan('test-plan');
await aboutPlanCubit!.getPlan(slug: 'test-plan');
aboutPlanCubit!.choseOption(2);
final result = await aboutPlanCubit!.chosePlan();
@@ -884,7 +884,7 @@ void main() {
),
);
await aboutPlanCubit!.getPlan('test-plan');
await aboutPlanCubit!.getPlan(slug: 'test-plan');
aboutPlanCubit!.choseOption(0);
final result = await aboutPlanCubit!.chosePlan();
@@ -926,7 +926,7 @@ void main() {
when(mockPlanRepository.getPlan('test-plan')).thenAnswer((_) async => testPlan);
when(mockPlanRepository.chosePlan('test-plan', any)).thenThrow(Exception('Общая ошибка'));
await aboutPlanCubit!.getPlan('test-plan');
await aboutPlanCubit!.getPlan(slug: 'test-plan');
aboutPlanCubit!.choseOption(0);
final result = await aboutPlanCubit!.chosePlan();

View File

@@ -4,6 +4,7 @@ import 'package:eatvio_app/core/comments/comments_cubit/comments_cubit.dart';
import 'package:eatvio_app/core/comments/comments_cubit/comments_state.dart';
import 'package:eatvio_app/core/locator_service.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/core/widgets/bookmark_button.dart';
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
import 'package:eatvio_app/features/feed/presentation/bloc/feed_cubit/feed_cubit.dart';
@@ -167,7 +168,7 @@ void main() {
when(planCubit.state).thenReturn(state);
when(planCubit.stream).thenAnswer((_) => const Stream<AboutPlanState>.empty());
when(planCubit.close()).thenAnswer((_) async => Future<void>.value());
when(planCubit.getPlan(any)).thenAnswer((_) async => Future<void>.value());
when(planCubit.getPlan(slug: anyNamed('slug'), index: anyNamed('index'))).thenAnswer((_) async => Future<void>.value());
when(feedCubit.viewPlan(any)).thenAnswer((_) async => Future<void>.value());
when(feedCubit.stream).thenAnswer((_) => const Stream.empty());
when(feedCubit.close()).thenAnswer((_) async => Future<void>.value());
@@ -183,6 +184,95 @@ void main() {
expect(find.byType(AboutPlanScreen), findsOneWidget);
});
testWidgets('error state try again calls getPlan', (tester) async {
final planCubit = MockAboutPlanCubit();
final feedCubit = MockFeedCubit();
final commentsCubit = MockCommentsCubit();
const state = AboutPlanState(isLoading: false, error: 'Error loading plan', planModel: testPlan, chosenOptionIndex: 0);
when(planCubit.state).thenReturn(state);
when(planCubit.stream).thenAnswer((_) => const Stream<AboutPlanState>.empty());
when(planCubit.close()).thenAnswer((_) async => Future<void>.value());
when(planCubit.getPlan(slug: anyNamed('slug'), index: anyNamed('index'))).thenAnswer((_) async => Future<void>.value());
when(feedCubit.viewPlan(any)).thenAnswer((_) async => Future<void>.value());
when(feedCubit.stream).thenAnswer((_) => const Stream.empty());
when(feedCubit.close()).thenAnswer((_) async => Future<void>.value());
when(commentsCubit.state).thenReturn(const CommentsState());
when(commentsCubit.stream).thenAnswer((_) => const Stream<CommentsState>.empty());
when(commentsCubit.close()).thenAnswer((_) async => Future<void>.value());
when(commentsCubit.getComments(any, any, any)).thenAnswer((_) async => Future<void>.value());
registerMocks(planCubit, commentsCubit);
await tester.pumpWidget(wrap(planCubit, feedCubit, commentsCubit, const AboutPlanScreen(slug: 'test', navigateToComments: false, index: null, highlightedCommentId: null)));
await tester.pump();
await tester.tap(find.text('Попробовать снова'));
await tester.pump();
verify(planCubit.getPlan(slug: 'test', index: null)).called(1);
});
testWidgets('loading state back button does not throw', (tester) async {
final planCubit = MockAboutPlanCubit();
final feedCubit = MockFeedCubit();
final commentsCubit = MockCommentsCubit();
const state = AboutPlanState(isLoading: true, error: null, planModel: null, chosenOptionIndex: 0);
when(planCubit.state).thenReturn(state);
when(planCubit.stream).thenAnswer((_) => const Stream<AboutPlanState>.empty());
when(planCubit.close()).thenAnswer((_) async => Future<void>.value());
when(feedCubit.viewPlan(any)).thenAnswer((_) async => Future<void>.value());
when(feedCubit.stream).thenAnswer((_) => const Stream.empty());
when(feedCubit.close()).thenAnswer((_) async => Future<void>.value());
when(commentsCubit.state).thenReturn(const CommentsState());
when(commentsCubit.stream).thenAnswer((_) => const Stream<CommentsState>.empty());
when(commentsCubit.close()).thenAnswer((_) async => Future<void>.value());
when(commentsCubit.getComments(any, any, any)).thenAnswer((_) async => Future<void>.value());
registerMocks(planCubit, commentsCubit);
await tester.pumpWidget(wrap(planCubit, feedCubit, commentsCubit, const AboutPlanScreen(slug: 'test', navigateToComments: false, index: null, highlightedCommentId: null)));
await tester.pump();
await tester.tap(find.byType(BackButton));
await tester.pump();
expect(find.byType(AboutPlanScreen), findsOneWidget);
});
testWidgets('loaded state bookmark tap calls addToFavorite when not favorite', (tester) async {
final planCubit = MockAboutPlanCubit();
final feedCubit = MockFeedCubit();
final commentsCubit = MockCommentsCubit();
const state = AboutPlanState(isLoading: false, planModel: testPlan, chosenOptionIndex: 0, error: null);
when(planCubit.state).thenReturn(state);
when(planCubit.stream).thenAnswer((_) => const Stream<AboutPlanState>.empty());
when(planCubit.close()).thenAnswer((_) async => Future<void>.value());
when(planCubit.addToFavorite(slug: anyNamed('slug'), index: anyNamed('index'))).thenAnswer((_) async => Future<void>.value());
when(feedCubit.viewPlan(any)).thenAnswer((_) async => Future<void>.value());
when(feedCubit.stream).thenAnswer((_) => const Stream.empty());
when(feedCubit.close()).thenAnswer((_) async => Future<void>.value());
when(commentsCubit.state).thenReturn(const CommentsState());
when(commentsCubit.stream).thenAnswer((_) => const Stream<CommentsState>.empty());
when(commentsCubit.close()).thenAnswer((_) async => Future<void>.value());
when(commentsCubit.getComments(any, any, any)).thenAnswer((_) async => Future<void>.value());
registerMocks(planCubit, commentsCubit);
await mockNetworkImagesFor(() async {
await tester.pumpWidget(wrap(planCubit, feedCubit, commentsCubit, const AboutPlanScreen(slug: 'test-plan', navigateToComments: false, index: 7, highlightedCommentId: null)));
await tester.pump();
await tester.pump();
});
await tester.tap(find.byType(BookmarkButton));
await tester.pump();
verify(planCubit.addToFavorite(slug: 'test-plan', index: 7)).called(1);
});
testWidgets('renders with navigateToComments true', (tester) async {
final planCubit = MockAboutPlanCubit();
final feedCubit = MockFeedCubit();