merge upstream

This commit is contained in:
2026-11-23 11:19:45 +00:00
38 changed files with 2437 additions and 503 deletions

View File

@@ -12,6 +12,12 @@ import 'package:eatvio_app/features/chat/presentation/bloc/chat_room_cubit/chat_
import 'package:eatvio_app/features/chat/presentation/bloc/chats_cubit/chats_cubit.dart';
import 'package:eatvio_app/features/chat/presentation/bloc/chats_cubit/chats_state.dart';
import 'package:eatvio_app/features/chat/presentation/pages/chat_screen.dart';
import 'package:eatvio_app/features/chat/presentation/widgets/video_call_chat_message_widget.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/plans/enums/chosen_plan_state_enum.dart';
import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
@@ -55,13 +61,57 @@ void main() {
final fakeBundle = _FakeAssetBundle({
'assets/icons/error_icon.svg': fakeSvg,
'assets/icons/video_call/vc_control_enter.svg': fakeSvg,
});
const plan = PlanModel(
id: 1,
slug: 'test-plan',
name: 'Test Plan',
image: 'https://example.com/image.jpg',
duration: 30,
state: 'active',
type: PlanType(fit: true, slim: false, behavior: false, wellness: false),
details: 'Test details',
packetsCount: 3,
author: Author(
authorSlug: 'author',
authorName: 'Author Name',
authorProfileIcon: 'https://example.com/icon.jpg',
authorIsMe: false,
),
totalLikes: 10,
totalViews: 100,
totalComments: 5,
isFavorite: false,
minPriceOfOptions: 1000,
maxPriceOfOptions: 2000,
wasLikedByMe: false,
);
ChosenPlanModel chosenPlan(ChosenPlanStateEnum state) {
return ChosenPlanModel(
id: 7,
optionType: 'options1',
startDate: DateTime(2025, 1, 1),
chosenPlanState: state,
chatId: '1',
consultantId: 2,
plan: plan,
);
}
Widget wrap(Widget child, ChatsCubit chatsCubit) {
return DefaultAssetBundle(
bundle: fakeBundle,
child: MaterialApp(
theme: ThemeHelper().themeData(),
locale: const Locale('ru'),
localizationsDelegates: const [
S.delegate,
...GlobalMaterialLocalizations.delegates,
],
supportedLocales: S.delegate.supportedLocales,
home: BlocProvider<ChatsCubit>.value(value: chatsCubit, child: child),
),
);
@@ -214,9 +264,133 @@ void main() {
expect(find.text('sending...'), findsOneWidget);
expect(find.text('tap to retry'), findsOneWidget);
expect(find.text('file.pdf'), findsOneWidget);
expect(find.byIcon(Icons.videocam_rounded), findsNothing);
VisibilityDetectorController.instance.notifyNow();
await tester.pump();
});
Future<void> pumpLoadedChat(
WidgetTester tester, {
ChosenPlanModel? plan,
List<ChatMessageModel> messages = const [],
}) async {
final chatRoomCubit = MockChatRoomCubit();
final chatsCubit = MockChatsCubit();
const chatRoom = ChatRoomModel(
id: '1',
chatRoomSettings: ChatRoomSettingsModel(name: 'room', state: 'active'),
users: Users(
sender: ChatUserModel(
id: 1,
name: 'Me',
slug: 'me',
profilePhotoUrl: null,
),
receiver: ChatUserModel(
id: 2,
name: 'User Two',
slug: 'user-two',
profilePhotoUrl: null,
),
),
chosenPlanId: 7,
chosenPlan: null,
);
final state = ChatRoomState.loaded(
chatRoom: chatRoom.copyWith(chosenPlan: plan),
chatMessages: messages,
hasCard: false,
isTyping: false,
isLoading: false,
);
when(chatRoomCubit.state).thenReturn(state);
when(
chatRoomCubit.stream,
).thenAnswer((_) => const Stream<ChatRoomState>.empty());
when(chatRoomCubit.close()).thenAnswer((_) async => Future<void>.value());
when(
chatRoomCubit.initChat(
any,
sendInitialMessage: anyNamed('sendInitialMessage'),
orderId: anyNamed('orderId'),
),
).thenAnswer((_) async => 'uuid');
when(chatRoomCubit.setTimer()).thenReturn(null);
when(chatRoomCubit.refreshChat()).thenAnswer((_) async {});
if (sl.isRegistered<ChatRoomCubit>()) {
sl.unregister<ChatRoomCubit>();
}
sl.registerFactory<ChatRoomCubit>(() => chatRoomCubit);
when(chatsCubit.state).thenReturn(ChatsState());
when(chatsCubit.stream).thenAnswer((_) => const Stream.empty());
when(chatsCubit.close()).thenAnswer((_) async => Future<void>.value());
await tester.pumpWidget(
wrap(
const ChatScreen(uuid: 'uuid', sendInitialMessage: false),
chatsCubit,
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 200));
}
ChatMessageModel incomingCallMessage() {
return ChatMessageModel(
id: 9,
data: 'Видеозвонок',
mediaData: const [],
authorId: 2,
updatedAt: DateTime(2025, 1, 2, 11),
isRead: true,
isCurrentUserAuthor: false,
roomId: '1',
type: ChatMessageType.videoCallStarted,
messageState: MessageState.sent,
uuid: 'call',
);
}
testWidgets('shows the call button for an active consultation', (
tester,
) async {
await pumpLoadedChat(
tester,
plan: chosenPlan(ChosenPlanStateEnum.stateInProgress),
messages: [incomingCallMessage()],
);
expect(find.byIcon(Icons.videocam_rounded), findsOneWidget);
expect(find.byType(VideoCallChatMessageWidget), findsOneWidget);
});
testWidgets('hides the call button for a finished consultation', (
tester,
) async {
await pumpLoadedChat(
tester,
plan: chosenPlan(ChosenPlanStateEnum.stateDone),
messages: [incomingCallMessage()],
);
expect(find.byIcon(Icons.videocam_rounded), findsNothing);
expect(find.byType(VideoCallChatMessageWidget), findsNothing);
expect(find.text('Видеозвонок'), findsOneWidget);
});
testWidgets('hides the call button for a canceled consultation', (
tester,
) async {
await pumpLoadedChat(
tester,
plan: chosenPlan(ChosenPlanStateEnum.stateCanceledByTheInitiator),
);
expect(find.byIcon(Icons.videocam_rounded), findsNothing);
});
});
}

View File

@@ -18,6 +18,11 @@ Widget _wrap(Widget child) {
);
}
Future<void> _pump(WidgetTester tester, Widget child) async {
await tester.pumpWidget(_wrap(child));
await tester.pump();
}
void main() {
group('ChatConsultationHeader', () {
testWidgets('вызывает onInfoTap по тапу на info', (tester) async {
@@ -27,13 +32,12 @@ void main() {
hasPersonalDiet: false,
);
await tester.pumpWidget(
_wrap(
ChatConsultationHeader(
progress: progress,
showInfoButton: true,
onInfoTap: () => tapped++,
),
await _pump(
tester,
ChatConsultationHeader(
progress: progress,
showInfoButton: true,
onInfoTap: () => tapped++,
),
);
@@ -54,13 +58,12 @@ void main() {
expect(progress.showProgressPlank, isTrue);
expect(progress.dietStatus, PersonalDietStatus.proposed);
await tester.pumpWidget(
_wrap(
ChatConsultationHeader(
progress: progress,
showInfoButton: false,
onInfoTap: () {},
),
await _pump(
tester,
ChatConsultationHeader(
progress: progress,
showInfoButton: false,
onInfoTap: () {},
),
);

View File

@@ -15,6 +15,11 @@ Widget _wrap(Widget child) {
);
}
Future<void> _pump(WidgetTester tester, Widget child) async {
await tester.pumpWidget(_wrap(child));
await tester.pump();
}
void main() {
group('ConsultationProgressPlank', () {
testWidgets('не строит шаги при showProgressPlank=false', (tester) async {
@@ -24,9 +29,7 @@ void main() {
);
expect(progress.showProgressPlank, isFalse);
await tester.pumpWidget(
_wrap(ConsultationProgressPlank(progress: progress)),
);
await _pump(tester, ConsultationProgressPlank(progress: progress));
expect(
find.descendant(
@@ -48,9 +51,7 @@ void main() {
);
expect(progress.showProgressPlank, isTrue);
await tester.pumpWidget(
_wrap(ConsultationProgressPlank(progress: progress)),
);
await _pump(tester, ConsultationProgressPlank(progress: progress));
final s = S.of(tester.element(find.byType(ConsultationProgressPlank)));
@@ -70,12 +71,11 @@ void main() {
hasPersonalDiet: false,
);
await tester.pumpWidget(
_wrap(
SizedBox(
width: 360,
child: ConsultationProgressPlank(progress: progress),
),
await _pump(
tester,
SizedBox(
width: 360,
child: ConsultationProgressPlank(progress: progress),
),
);

View File

@@ -15,6 +15,11 @@ Widget _wrap(Widget child) {
);
}
Future<void> _pump(WidgetTester tester, Widget child) async {
await tester.pumpWidget(_wrap(child));
await tester.pump();
}
Widget _chip(
ChosenPlanStateEnum state, {
bool hasPersonalDiet = true,
@@ -32,9 +37,7 @@ Widget _chip(
void main() {
group('PersonalDietStatusChip', () {
testWidgets('notRequired + active ничего не показывает', (tester) async {
await tester.pumpWidget(
_wrap(_chip(ChosenPlanStateEnum.stateInited, hasPersonalDiet: false)),
);
await _pump(tester, _chip(ChosenPlanStateEnum.stateInited, hasPersonalDiet: false));
expect(
find.descendant(
@@ -47,7 +50,7 @@ void main() {
});
testWidgets('proposed показывает personal_diet_proposed', (tester) async {
await tester.pumpWidget(_wrap(_chip(ChosenPlanStateEnum.stateStarted)));
await _pump(tester, _chip(ChosenPlanStateEnum.stateStarted));
final s = S.of(tester.element(find.byType(PersonalDietStatusChip)));
@@ -55,12 +58,11 @@ void main() {
});
testWidgets('proposed с названием показывает имя диеты', (tester) async {
await tester.pumpWidget(
_wrap(
_chip(
ChosenPlanStateEnum.stateStarted,
personalDietName: 'Индивидуальный план питания',
),
await _pump(
tester,
_chip(
ChosenPlanStateEnum.stateStarted,
personalDietName: 'Индивидуальный план питания',
),
);
@@ -75,7 +77,7 @@ void main() {
testWidgets('notProposed показывает personal_diet_not_proposed', (
tester,
) async {
await tester.pumpWidget(_wrap(_chip(ChosenPlanStateEnum.statePaid)));
await _pump(tester, _chip(ChosenPlanStateEnum.statePaid));
final s = S.of(tester.element(find.byType(PersonalDietStatusChip)));
@@ -83,9 +85,7 @@ void main() {
});
testWidgets('canceled показывает orderCanceled', (tester) async {
await tester.pumpWidget(
_wrap(_chip(ChosenPlanStateEnum.stateCanceledByTheInitiator)),
);
await _pump(tester, _chip(ChosenPlanStateEnum.stateCanceledByTheInitiator));
final s = S.of(tester.element(find.byType(PersonalDietStatusChip)));
@@ -93,9 +93,7 @@ void main() {
});
testWidgets('paymentFailed показывает payment_failed', (tester) async {
await tester.pumpWidget(
_wrap(_chip(ChosenPlanStateEnum.statePaymentFailed)),
);
await _pump(tester, _chip(ChosenPlanStateEnum.statePaymentFailed));
final s = S.of(tester.element(find.byType(PersonalDietStatusChip)));

File diff suppressed because it is too large Load Diff

View File

@@ -34,6 +34,7 @@ void main() {
testWidgets('показывает заголовок Есть промокод? и кнопки Применить/Пропустить', (tester) async {
await tester.pumpWidget(createTestWidget());
await tester.pump();
await tester.tap(find.text('Open'));
await tester.pumpAndSettle();
@@ -44,6 +45,7 @@ void main() {
testWidgets('Применить с пустым полем показывает ошибку и не закрывает', (tester) async {
await tester.pumpWidget(createTestWidget());
await tester.pump();
await tester.tap(find.text('Open'));
await tester.pumpAndSettle();
@@ -64,6 +66,7 @@ void main() {
},
),
);
await tester.pump();
await tester.tap(find.text('Open'));
await tester.pumpAndSettle();
@@ -78,6 +81,7 @@ void main() {
testWidgets('Пропустить закрывает шторку', (tester) async {
await tester.pumpWidget(createTestWidget());
await tester.pump();
await tester.tap(find.text('Open'));
await tester.pumpAndSettle();
@@ -101,6 +105,7 @@ void main() {
onRemove: () async => true,
),
);
await tester.pump();
await tester.tap(find.text('Open'));
await tester.pumpAndSettle();
@@ -128,6 +133,7 @@ void main() {
},
),
);
await tester.pump();
await tester.tap(find.text('Open'));
await tester.pumpAndSettle();
@@ -156,6 +162,7 @@ void main() {
},
),
);
await tester.pump();
await tester.tap(find.text('Open'));
await tester.pumpAndSettle();

View File

@@ -98,6 +98,7 @@ void main() {
await tester.pumpWidget(createTestWidget(planId: planId));
await tester.pump();
await tester.pump();
expect(find.byType(Loader), findsOneWidget);
expect(find.text('Сбербанк'), findsNothing);

View File

@@ -106,6 +106,7 @@ void main() {
Future<void> openSheet(WidgetTester tester, {double? amount}) async {
await pumpApp(tester, amount: amount);
await tester.pump();
await tester.tap(find.text('open'));
await tester.pump();
await tester.pump();

View File

@@ -5,22 +5,70 @@ void main() {
group('ChosenPlanStateEnum', () {
test('has all expected values', () {
expect(ChosenPlanStateEnum.values.length, 16);
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateInited));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateStartDateHasBeenSet));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateInCoordination));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateStarted));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateInProgress));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.statePendingPayment));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateConfirmedByConsultant));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.statePaid));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateCanceledByTheInitiator));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateLastDayStarted));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateLastDayFinished));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateComplained));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateDone));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.personalDietSet));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateChargeWasCollected));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.statePaymentFailed));
expect(
ChosenPlanStateEnum.values,
contains(ChosenPlanStateEnum.stateInited),
);
expect(
ChosenPlanStateEnum.values,
contains(ChosenPlanStateEnum.stateStartDateHasBeenSet),
);
expect(
ChosenPlanStateEnum.values,
contains(ChosenPlanStateEnum.stateInCoordination),
);
expect(
ChosenPlanStateEnum.values,
contains(ChosenPlanStateEnum.stateStarted),
);
expect(
ChosenPlanStateEnum.values,
contains(ChosenPlanStateEnum.stateInProgress),
);
expect(
ChosenPlanStateEnum.values,
contains(ChosenPlanStateEnum.statePendingPayment),
);
expect(
ChosenPlanStateEnum.values,
contains(ChosenPlanStateEnum.stateConfirmedByConsultant),
);
expect(
ChosenPlanStateEnum.values,
contains(ChosenPlanStateEnum.statePaid),
);
expect(
ChosenPlanStateEnum.values,
contains(ChosenPlanStateEnum.stateCanceledByTheInitiator),
);
expect(
ChosenPlanStateEnum.values,
contains(ChosenPlanStateEnum.stateLastDayStarted),
);
expect(
ChosenPlanStateEnum.values,
contains(ChosenPlanStateEnum.stateLastDayFinished),
);
expect(
ChosenPlanStateEnum.values,
contains(ChosenPlanStateEnum.stateComplained),
);
expect(
ChosenPlanStateEnum.values,
contains(ChosenPlanStateEnum.stateDone),
);
expect(
ChosenPlanStateEnum.values,
contains(ChosenPlanStateEnum.personalDietSet),
);
expect(
ChosenPlanStateEnum.values,
contains(ChosenPlanStateEnum.stateChargeWasCollected),
);
expect(
ChosenPlanStateEnum.values,
contains(ChosenPlanStateEnum.statePaymentFailed),
);
});
test('getShowableChatBadgeStates returns correct states', () {
@@ -40,32 +88,77 @@ void main() {
});
test('isStateAfterPaidState returns false for states before paid', () {
expect(ChosenPlanStateEnum.stateCanceledByTheInitiator.isStateAfterPaidState(), isFalse);
expect(
ChosenPlanStateEnum.stateCanceledByTheInitiator.isStateAfterPaidState(),
isFalse,
);
expect(ChosenPlanStateEnum.stateInited.isStateAfterPaidState(), isFalse);
expect(ChosenPlanStateEnum.stateInCoordination.isStateAfterPaidState(), isFalse);
expect(ChosenPlanStateEnum.stateStartDateHasBeenSet.isStateAfterPaidState(), isFalse);
expect(ChosenPlanStateEnum.statePendingPayment.isStateAfterPaidState(), isFalse);
expect(ChosenPlanStateEnum.statePaymentFailed.isStateAfterPaidState(), isFalse);
expect(
ChosenPlanStateEnum.stateInCoordination.isStateAfterPaidState(),
isFalse,
);
expect(
ChosenPlanStateEnum.stateStartDateHasBeenSet.isStateAfterPaidState(),
isFalse,
);
expect(
ChosenPlanStateEnum.statePendingPayment.isStateAfterPaidState(),
isFalse,
);
expect(
ChosenPlanStateEnum.statePaymentFailed.isStateAfterPaidState(),
isFalse,
);
});
test('isStateAfterPaidState returns true for states after paid', () {
expect(ChosenPlanStateEnum.statePaid.isStateAfterPaidState(), isTrue);
expect(ChosenPlanStateEnum.stateStarted.isStateAfterPaidState(), isTrue);
expect(ChosenPlanStateEnum.stateInProgress.isStateAfterPaidState(), isTrue);
expect(ChosenPlanStateEnum.stateLastDayStarted.isStateAfterPaidState(), isTrue);
expect(ChosenPlanStateEnum.stateLastDayFinished.isStateAfterPaidState(), isTrue);
expect(ChosenPlanStateEnum.stateComplained.isStateAfterPaidState(), isTrue);
expect(
ChosenPlanStateEnum.stateInProgress.isStateAfterPaidState(),
isTrue,
);
expect(
ChosenPlanStateEnum.stateLastDayStarted.isStateAfterPaidState(),
isTrue,
);
expect(
ChosenPlanStateEnum.stateLastDayFinished.isStateAfterPaidState(),
isTrue,
);
expect(
ChosenPlanStateEnum.stateComplained.isStateAfterPaidState(),
isTrue,
);
expect(ChosenPlanStateEnum.stateDone.isStateAfterPaidState(), isTrue);
expect(ChosenPlanStateEnum.personalDietSet.isStateAfterPaidState(), isTrue);
expect(ChosenPlanStateEnum.stateChargeWasCollected.isStateAfterPaidState(), isTrue);
expect(ChosenPlanStateEnum.stateConfirmedByConsultant.isStateAfterPaidState(), isTrue);
expect(
ChosenPlanStateEnum.personalDietSet.isStateAfterPaidState(),
isTrue,
);
expect(
ChosenPlanStateEnum.stateChargeWasCollected.isStateAfterPaidState(),
isTrue,
);
expect(
ChosenPlanStateEnum.stateConfirmedByConsultant.isStateAfterPaidState(),
isTrue,
);
});
test('canShowCancelAction returns true for cancellable states', () {
expect(ChosenPlanStateEnum.stateInited.canShowCancelAction, isTrue);
expect(ChosenPlanStateEnum.stateInCoordination.canShowCancelAction, isTrue);
expect(ChosenPlanStateEnum.stateStartDateHasBeenSet.canShowCancelAction, isTrue);
expect(ChosenPlanStateEnum.statePendingPayment.canShowCancelAction, isTrue);
expect(
ChosenPlanStateEnum.stateInCoordination.canShowCancelAction,
isTrue,
);
expect(
ChosenPlanStateEnum.stateStartDateHasBeenSet.canShowCancelAction,
isTrue,
);
expect(
ChosenPlanStateEnum.statePendingPayment.canShowCancelAction,
isTrue,
);
expect(ChosenPlanStateEnum.statePaid.canShowCancelAction, isTrue);
expect(ChosenPlanStateEnum.stateStarted.canShowCancelAction, isTrue);
expect(ChosenPlanStateEnum.stateInProgress.canShowCancelAction, isTrue);
@@ -73,33 +166,129 @@ void main() {
test('canShowCancelAction returns false for non-cancellable states', () {
expect(ChosenPlanStateEnum.personalDietSet.canShowCancelAction, isFalse);
expect(ChosenPlanStateEnum.stateLastDayStarted.canShowCancelAction, isFalse);
expect(ChosenPlanStateEnum.stateLastDayFinished.canShowCancelAction, isFalse);
expect(
ChosenPlanStateEnum.stateLastDayStarted.canShowCancelAction,
isFalse,
);
expect(
ChosenPlanStateEnum.stateLastDayFinished.canShowCancelAction,
isFalse,
);
expect(ChosenPlanStateEnum.stateComplained.canShowCancelAction, isFalse);
expect(ChosenPlanStateEnum.stateDone.canShowCancelAction, isFalse);
expect(ChosenPlanStateEnum.stateChargeWasCollected.canShowCancelAction, isFalse);
expect(ChosenPlanStateEnum.stateCanceledByTheInitiator.canShowCancelAction, isFalse);
expect(ChosenPlanStateEnum.statePaymentFailed.canShowCancelAction, isFalse);
expect(ChosenPlanStateEnum.stateConfirmedByConsultant.canShowCancelAction, isFalse);
expect(
ChosenPlanStateEnum.stateChargeWasCollected.canShowCancelAction,
isFalse,
);
expect(
ChosenPlanStateEnum.stateCanceledByTheInitiator.canShowCancelAction,
isFalse,
);
expect(
ChosenPlanStateEnum.statePaymentFailed.canShowCancelAction,
isFalse,
);
expect(
ChosenPlanStateEnum.stateConfirmedByConsultant.canShowCancelAction,
isFalse,
);
});
test('isCancelAfterPaidState returns true only for post-paid cancellable states', () {
expect(ChosenPlanStateEnum.statePaid.isCancelAfterPaidState, isTrue);
expect(ChosenPlanStateEnum.stateStarted.isCancelAfterPaidState, isTrue);
expect(ChosenPlanStateEnum.stateInProgress.isCancelAfterPaidState, isTrue);
expect(ChosenPlanStateEnum.stateInited.isCancelAfterPaidState, isFalse);
expect(ChosenPlanStateEnum.stateInCoordination.isCancelAfterPaidState, isFalse);
expect(ChosenPlanStateEnum.stateStartDateHasBeenSet.isCancelAfterPaidState, isFalse);
expect(ChosenPlanStateEnum.statePendingPayment.isCancelAfterPaidState, isFalse);
expect(ChosenPlanStateEnum.statePaymentFailed.isCancelAfterPaidState, isFalse);
expect(ChosenPlanStateEnum.stateConfirmedByConsultant.isCancelAfterPaidState, isFalse);
expect(ChosenPlanStateEnum.personalDietSet.isCancelAfterPaidState, isFalse);
expect(ChosenPlanStateEnum.stateLastDayStarted.isCancelAfterPaidState, isFalse);
expect(ChosenPlanStateEnum.stateLastDayFinished.isCancelAfterPaidState, isFalse);
expect(ChosenPlanStateEnum.stateComplained.isCancelAfterPaidState, isFalse);
expect(ChosenPlanStateEnum.stateDone.isCancelAfterPaidState, isFalse);
expect(ChosenPlanStateEnum.stateChargeWasCollected.isCancelAfterPaidState, isFalse);
expect(ChosenPlanStateEnum.stateCanceledByTheInitiator.isCancelAfterPaidState, isFalse);
test(
'isCancelAfterPaidState returns true only for post-paid cancellable states',
() {
expect(ChosenPlanStateEnum.statePaid.isCancelAfterPaidState, isTrue);
expect(ChosenPlanStateEnum.stateStarted.isCancelAfterPaidState, isTrue);
expect(
ChosenPlanStateEnum.stateInProgress.isCancelAfterPaidState,
isTrue,
);
expect(ChosenPlanStateEnum.stateInited.isCancelAfterPaidState, isFalse);
expect(
ChosenPlanStateEnum.stateInCoordination.isCancelAfterPaidState,
isFalse,
);
expect(
ChosenPlanStateEnum.stateStartDateHasBeenSet.isCancelAfterPaidState,
isFalse,
);
expect(
ChosenPlanStateEnum.statePendingPayment.isCancelAfterPaidState,
isFalse,
);
expect(
ChosenPlanStateEnum.statePaymentFailed.isCancelAfterPaidState,
isFalse,
);
expect(
ChosenPlanStateEnum.stateConfirmedByConsultant.isCancelAfterPaidState,
isFalse,
);
expect(
ChosenPlanStateEnum.personalDietSet.isCancelAfterPaidState,
isFalse,
);
expect(
ChosenPlanStateEnum.stateLastDayStarted.isCancelAfterPaidState,
isFalse,
);
expect(
ChosenPlanStateEnum.stateLastDayFinished.isCancelAfterPaidState,
isFalse,
);
expect(
ChosenPlanStateEnum.stateComplained.isCancelAfterPaidState,
isFalse,
);
expect(ChosenPlanStateEnum.stateDone.isCancelAfterPaidState, isFalse);
expect(
ChosenPlanStateEnum.stateChargeWasCollected.isCancelAfterPaidState,
isFalse,
);
expect(
ChosenPlanStateEnum
.stateCanceledByTheInitiator
.isCancelAfterPaidState,
isFalse,
);
},
);
test(
'allowsVideoCall is false for finished and canceled consultations',
() {
expect(
ChosenPlanStateEnum.stateCanceledByTheInitiator.allowsVideoCall,
isFalse,
);
expect(ChosenPlanStateEnum.statePaymentFailed.allowsVideoCall, isFalse);
expect(ChosenPlanStateEnum.stateDone.allowsVideoCall, isFalse);
expect(
ChosenPlanStateEnum.stateChargeWasCollected.allowsVideoCall,
isFalse,
);
},
);
test('allowsVideoCall is true while the consultation is not finished', () {
expect(ChosenPlanStateEnum.stateInited.allowsVideoCall, isTrue);
expect(ChosenPlanStateEnum.stateInCoordination.allowsVideoCall, isTrue);
expect(
ChosenPlanStateEnum.stateStartDateHasBeenSet.allowsVideoCall,
isTrue,
);
expect(ChosenPlanStateEnum.statePendingPayment.allowsVideoCall, isTrue);
expect(
ChosenPlanStateEnum.stateConfirmedByConsultant.allowsVideoCall,
isTrue,
);
expect(ChosenPlanStateEnum.statePaid.allowsVideoCall, isTrue);
expect(ChosenPlanStateEnum.personalDietSet.allowsVideoCall, isTrue);
expect(ChosenPlanStateEnum.stateStarted.allowsVideoCall, isTrue);
expect(ChosenPlanStateEnum.stateInProgress.allowsVideoCall, isTrue);
expect(ChosenPlanStateEnum.stateLastDayStarted.allowsVideoCall, isTrue);
expect(ChosenPlanStateEnum.stateLastDayFinished.allowsVideoCall, isTrue);
expect(ChosenPlanStateEnum.stateComplained.allowsVideoCall, isTrue);
});
test('getActiveStates returns correct states', () {
@@ -114,8 +303,10 @@ void main() {
expect(activeStates, contains(ChosenPlanStateEnum.stateComplained));
expect(activeStates, contains(ChosenPlanStateEnum.stateDone));
expect(activeStates, contains(ChosenPlanStateEnum.personalDietSet));
expect(activeStates, isNot(contains(ChosenPlanStateEnum.statePaymentFailed)));
expect(
activeStates,
isNot(contains(ChosenPlanStateEnum.statePaymentFailed)),
);
});
});
}

View File

@@ -141,12 +141,46 @@ void main() {
await settingsCubit!.init();
await Future.delayed(const Duration(milliseconds: 100));
await settingsCubit!.updateProfileDetails(profileDetailsModel: SettingsFixtures.profileDetailsModel());
final result = await settingsCubit!.updateProfileDetails(profileDetailsModel: SettingsFixtures.profileDetailsModel());
await Future.delayed(const Duration(milliseconds: 100));
expect(result, true);
verify(mockSettingsRepository.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).called(1);
});
test('updateProfileDetails - возвращает false при ошибке и перезагружает состояние', () async {
settingsCubit = SettingsCubit(
profileRepository: mockProfileRepository,
settingsRepository: mockSettingsRepository,
consultantRepository: mockConsultantRepository,
consultationsRepository: mockConsultationsRepository,
sessionLifecycleService: fakeSession,
);
when(mockProfileRepository.getMyProfile())
.thenAnswer((_) async => SettingsFixtures.profileModel());
when(mockConsultantRepository.getMyRequestStatus(any))
.thenThrow(Exception('Not found'));
when(mockConsultationsRepository.getUserPurchases(any, any))
.thenAnswer((_) async => []);
when(mockSettingsRepository.getOAuthAccounts())
.thenAnswer((_) async => SettingsFixtures.oauthAccountsResponseModel());
when(mockSettingsRepository.getProfileSettings())
.thenAnswer((_) async => SettingsFixtures.profileSettingsModel());
when(mockProfileRepository.getMyProfileDetails())
.thenAnswer((_) async => SettingsFixtures.profileDetailsModel());
when(mockSettingsRepository.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel')))
.thenThrow(Exception('Ошибка сохранения'));
await settingsCubit!.init();
await Future.delayed(const Duration(milliseconds: 100));
final result = await settingsCubit!.updateProfileDetails(profileDetailsModel: SettingsFixtures.profileDetailsModel());
await Future.delayed(const Duration(milliseconds: 100));
expect(result, false);
expect(settingsCubit!.state, isA<SettingsStateLoaded>());
});
test('updateProfileSettings - обновляет настройки профиля', () async {
settingsCubit = SettingsCubit(
profileRepository: mockProfileRepository,
@@ -173,12 +207,46 @@ void main() {
await settingsCubit!.init();
await Future.delayed(const Duration(milliseconds: 100));
await settingsCubit!.updateProfileSettings(profileSettingsModel: SettingsFixtures.profileSettingsModel());
final result = await settingsCubit!.updateProfileSettings(profileSettingsModel: SettingsFixtures.profileSettingsModel());
await Future.delayed(const Duration(milliseconds: 100));
expect(result, true);
verify(mockSettingsRepository.updateProfileSettings(profileSettingsModel: anyNamed('profileSettingsModel'))).called(1);
});
test('updateProfileSettings - возвращает false при ошибке и перезагружает состояние', () async {
settingsCubit = SettingsCubit(
profileRepository: mockProfileRepository,
settingsRepository: mockSettingsRepository,
consultantRepository: mockConsultantRepository,
consultationsRepository: mockConsultationsRepository,
sessionLifecycleService: fakeSession,
);
when(mockProfileRepository.getMyProfile())
.thenAnswer((_) async => SettingsFixtures.profileModel());
when(mockConsultantRepository.getMyRequestStatus(any))
.thenThrow(Exception('Not found'));
when(mockConsultationsRepository.getUserPurchases(any, any))
.thenAnswer((_) async => []);
when(mockSettingsRepository.getOAuthAccounts())
.thenAnswer((_) async => SettingsFixtures.oauthAccountsResponseModel());
when(mockSettingsRepository.getProfileSettings())
.thenAnswer((_) async => SettingsFixtures.profileSettingsModel());
when(mockProfileRepository.getMyProfileDetails())
.thenAnswer((_) async => SettingsFixtures.profileDetailsModel());
when(mockSettingsRepository.updateProfileSettings(profileSettingsModel: anyNamed('profileSettingsModel')))
.thenThrow(Exception('Ошибка сохранения'));
await settingsCubit!.init();
await Future.delayed(const Duration(milliseconds: 100));
final result = await settingsCubit!.updateProfileSettings(profileSettingsModel: SettingsFixtures.profileSettingsModel());
await Future.delayed(const Duration(milliseconds: 100));
expect(result, false);
expect(settingsCubit!.state, isA<SettingsStateLoaded>());
});
test('deleteAccount - удаляет аккаунт', () async {
settingsCubit = SettingsCubit(
profileRepository: mockProfileRepository,

View File

@@ -13,6 +13,7 @@ import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/se
import 'package:eatvio_app/features/settings/presentation/pages/general_info_screen.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -25,6 +26,8 @@ import 'general_info_screen_test.mocks.dart';
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
void main() {
group('GeneralInfoScreen smoke', () {
final toastCalls = <MethodCall>[];
setUpAll(() async {
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
});
@@ -32,6 +35,21 @@ void main() {
setUp(() async {
await sl.reset();
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
toastCalls.clear();
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
(MethodCall methodCall) async {
toastCalls.add(methodCall);
return null;
},
);
});
tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
null,
);
});
const mockProfile = ProfileModel(
@@ -95,7 +113,20 @@ void main() {
supportedLocales: const [Locale('ru')],
routerConfig: GoRouter(
initialLocation: '/',
routes: [GoRoute(path: '/', builder: (context, state) => child)],
routes: [
GoRoute(
path: '/',
builder: (context, state) => Scaffold(
body: Center(
child: TextButton(
onPressed: () => context.push('/screen'),
child: const Text('open screen'),
),
),
),
),
GoRoute(path: '/screen', builder: (context, state) => child),
],
),
);
}
@@ -112,7 +143,7 @@ void main() {
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
@@ -122,8 +153,8 @@ void main() {
child: wrap(GeneralInfoScreen(settingsEntity: settingsEntity)),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 200));
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
expect(find.byType(GeneralInfoScreen), findsOneWidget);
});
@@ -136,13 +167,13 @@ void main() {
profile: mockProfile,
hasActiveConsultation: false,
);
final saveCompleter = Completer<void>();
final saveCompleter = Completer<bool>();
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) => saveCompleter.future);
when(cubit.updateProfileSettings(profileSettingsModel: anyNamed('profileSettingsModel'))).thenAnswer((_) async {});
when(cubit.updateProfileSettings(profileSettingsModel: anyNamed('profileSettingsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
@@ -152,7 +183,8 @@ void main() {
child: wrap(GeneralInfoScreen(settingsEntity: settingsEntity)),
),
);
await tester.pump();
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
expect(find.text('Сохранить'), findsOneWidget);
expect(find.byType(Loader), findsNothing);
@@ -167,12 +199,88 @@ void main() {
final loaderSize = tester.getSize(find.byType(Loader));
expect(loaderSize.height, lessThan(60));
saveCompleter.complete();
saveCompleter.complete(true);
await tester.pump();
await tester.pumpAndSettle();
expect(find.byType(GeneralInfoScreen), findsNothing);
expect(find.text('open screen'), findsOneWidget);
await tester.pump(const Duration(seconds: 2));
});
testWidgets('показывает уведомление после успешного сохранения', (tester) async {
final cubit = MockSettingsCubit();
const state = SettingsState.loaded(
profileSettings: mockProfileSettings,
profileDetails: mockProfileDetails,
profile: mockProfile,
hasActiveConsultation: false,
);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
when(cubit.updateProfileSettings(profileSettingsModel: anyNamed('profileSettingsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
await tester.pumpWidget(
BlocProvider<SettingsCubit>.value(
value: cubit,
child: wrap(GeneralInfoScreen(settingsEntity: settingsEntity)),
),
);
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
await tester.tap(find.text('Сохранить'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
expect(find.text('Сохранить'), findsOneWidget);
expect(find.byType(Loader), findsNothing);
final toastMessages = toastCalls.where((call) => call.method == 'showToast').map((call) => call.arguments['msg']);
expect(toastMessages, contains('Данные успешно сохранены'));
await tester.pumpAndSettle();
expect(find.byType(GeneralInfoScreen), findsNothing);
expect(find.text('open screen'), findsOneWidget);
await tester.pump(const Duration(seconds: 2));
});
testWidgets('не показывает уведомление, если сохранение не удалось', (tester) async {
final cubit = MockSettingsCubit();
const state = SettingsState.loaded(
profileSettings: mockProfileSettings,
profileDetails: mockProfileDetails,
profile: mockProfile,
hasActiveConsultation: false,
);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => false);
when(cubit.updateProfileSettings(profileSettingsModel: anyNamed('profileSettingsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
await tester.pumpWidget(
BlocProvider<SettingsCubit>.value(
value: cubit,
child: wrap(GeneralInfoScreen(settingsEntity: settingsEntity)),
),
);
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
await tester.tap(find.text('Сохранить'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
expect(toastCalls.where((call) => call.method == 'showToast'), isEmpty);
expect(find.byType(GeneralInfoScreen), findsOneWidget);
});
});
}

View File

@@ -10,6 +10,7 @@ import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/se
import 'package:eatvio_app/features/settings/presentation/pages/other_info_screen.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -22,6 +23,8 @@ import 'other_info_screen_test.mocks.dart';
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
void main() {
group('OtherInfoScreen smoke', () {
final toastCalls = <MethodCall>[];
setUpAll(() async {
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
});
@@ -29,6 +32,21 @@ void main() {
setUp(() async {
await sl.reset();
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
toastCalls.clear();
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
(MethodCall methodCall) async {
toastCalls.add(methodCall);
return null;
},
);
});
tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
null,
);
});
const mockProfile = ProfileModel(
@@ -92,7 +110,20 @@ void main() {
supportedLocales: const [Locale('ru')],
routerConfig: GoRouter(
initialLocation: '/',
routes: [GoRoute(path: '/', builder: (context, state) => child)],
routes: [
GoRoute(
path: '/',
builder: (context, state) => Scaffold(
body: Center(
child: TextButton(
onPressed: () => context.push('/screen'),
child: const Text('open screen'),
),
),
),
),
GoRoute(path: '/screen', builder: (context, state) => child),
],
),
);
}
@@ -109,9 +140,7 @@ void main() {
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async {
return Future<void>.value();
});
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
@@ -121,10 +150,82 @@ void main() {
child: wrap(OtherInfoScreen(settingsEntity: settingsEntity)),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
expect(find.byType(OtherInfoScreen), findsOneWidget);
});
testWidgets('показывает уведомление и возвращается к настройкам после успешного сохранения', (tester) async {
final cubit = MockSettingsCubit();
const state = SettingsState.loaded(
profileSettings: mockProfileSettings,
profileDetails: mockProfileDetails,
profile: mockProfile,
hasActiveConsultation: false,
);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
await tester.pumpWidget(
BlocProvider<SettingsCubit>.value(
value: cubit,
child: wrap(OtherInfoScreen(settingsEntity: settingsEntity)),
),
);
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
await tester.tap(find.text('Сохранить'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
final toastMessages = toastCalls.where((call) => call.method == 'showToast').map((call) => call.arguments['msg']);
expect(toastMessages, contains('Данные успешно сохранены'));
await tester.pumpAndSettle();
expect(find.byType(OtherInfoScreen), findsNothing);
expect(find.text('open screen'), findsOneWidget);
await tester.pump(const Duration(seconds: 2));
});
testWidgets('не показывает уведомление и остаётся на экране при ошибке сохранения', (tester) async {
final cubit = MockSettingsCubit();
const state = SettingsState.loaded(
profileSettings: mockProfileSettings,
profileDetails: mockProfileDetails,
profile: mockProfile,
hasActiveConsultation: false,
);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => false);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
await tester.pumpWidget(
BlocProvider<SettingsCubit>.value(
value: cubit,
child: wrap(OtherInfoScreen(settingsEntity: settingsEntity)),
),
);
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
await tester.tap(find.text('Сохранить'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
expect(toastCalls.where((call) => call.method == 'showToast'), isEmpty);
expect(find.byType(OtherInfoScreen), findsOneWidget);
});
});
}

View File

@@ -8,7 +8,9 @@ import 'package:eatvio_app/features/settings/models/profile_settings_model.dart'
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_cubit.dart';
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart';
import 'package:eatvio_app/features/settings/presentation/pages/physical_activity_screen.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -21,6 +23,8 @@ import 'physical_activity_screen_test.mocks.dart';
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
void main() {
group('PhysicalActivityScreen smoke', () {
final toastCalls = <MethodCall>[];
setUpAll(() async {
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
});
@@ -28,6 +32,21 @@ void main() {
setUp(() async {
await sl.reset();
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
toastCalls.clear();
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
(MethodCall methodCall) async {
toastCalls.add(methodCall);
return null;
},
);
});
tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
null,
);
});
const mockProfile = ProfileModel(
@@ -87,9 +106,24 @@ void main() {
Widget wrap(Widget child) {
return MaterialApp.router(
theme: ThemeHelper().themeData(),
localizationsDelegates: const [S.delegate, ...GlobalMaterialLocalizations.delegates],
supportedLocales: const [Locale('ru')],
routerConfig: GoRouter(
initialLocation: '/',
routes: [GoRoute(path: '/', builder: (context, state) => child)],
routes: [
GoRoute(
path: '/',
builder: (context, state) => Scaffold(
body: Center(
child: TextButton(
onPressed: () => context.push('/screen'),
child: const Text('open screen'),
),
),
),
),
GoRoute(path: '/screen', builder: (context, state) => child),
],
),
);
}
@@ -106,7 +140,7 @@ void main() {
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
@@ -116,10 +150,82 @@ void main() {
child: wrap(PhysicalActivityScreen(settingsEntity: settingsEntity)),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 200));
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
expect(find.byType(PhysicalActivityScreen), findsOneWidget);
});
testWidgets('показывает уведомление и возвращается к настройкам после успешного сохранения', (tester) async {
final cubit = MockSettingsCubit();
const state = SettingsState.loaded(
profileSettings: mockProfileSettings,
profileDetails: mockProfileDetails,
profile: mockProfile,
hasActiveConsultation: false,
);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
await tester.pumpWidget(
BlocProvider<SettingsCubit>.value(
value: cubit,
child: wrap(PhysicalActivityScreen(settingsEntity: settingsEntity)),
),
);
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
await tester.tap(find.text('Сохранить'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
final toastMessages = toastCalls.where((call) => call.method == 'showToast').map((call) => call.arguments['msg']);
expect(toastMessages, contains('Данные успешно сохранены'));
await tester.pumpAndSettle();
expect(find.byType(PhysicalActivityScreen), findsNothing);
expect(find.text('open screen'), findsOneWidget);
await tester.pump(const Duration(seconds: 2));
});
testWidgets('не показывает уведомление и остаётся на экране при ошибке сохранения', (tester) async {
final cubit = MockSettingsCubit();
const state = SettingsState.loaded(
profileSettings: mockProfileSettings,
profileDetails: mockProfileDetails,
profile: mockProfile,
hasActiveConsultation: false,
);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => false);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
await tester.pumpWidget(
BlocProvider<SettingsCubit>.value(
value: cubit,
child: wrap(PhysicalActivityScreen(settingsEntity: settingsEntity)),
),
);
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
await tester.tap(find.text('Сохранить'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
expect(toastCalls.where((call) => call.method == 'showToast'), isEmpty);
expect(find.byType(PhysicalActivityScreen), findsOneWidget);
});
});
}

View File

@@ -10,6 +10,7 @@ import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/se
import 'package:eatvio_app/features/settings/presentation/pages/physical_form_screen.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -22,6 +23,8 @@ import 'physical_form_screen_test.mocks.dart';
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
void main() {
group('PhysicalFormScreen smoke', () {
final toastCalls = <MethodCall>[];
setUpAll(() async {
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
});
@@ -29,6 +32,21 @@ void main() {
setUp(() async {
await sl.reset();
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
toastCalls.clear();
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
(MethodCall methodCall) async {
toastCalls.add(methodCall);
return null;
},
);
});
tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
null,
);
});
const mockProfile = ProfileModel(
@@ -92,7 +110,20 @@ void main() {
supportedLocales: const [Locale('ru')],
routerConfig: GoRouter(
initialLocation: '/',
routes: [GoRoute(path: '/', builder: (context, state) => child)],
routes: [
GoRoute(
path: '/',
builder: (context, state) => Scaffold(
body: Center(
child: TextButton(
onPressed: () => context.push('/screen'),
child: const Text('open screen'),
),
),
),
),
GoRoute(path: '/screen', builder: (context, state) => child),
],
),
);
}
@@ -109,7 +140,7 @@ void main() {
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
@@ -119,10 +150,82 @@ void main() {
child: wrap(PhysicalFormScreen(settingsEntity: settingsEntity)),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
expect(find.byType(PhysicalFormScreen), findsOneWidget);
});
testWidgets('показывает уведомление и возвращается к настройкам после успешного сохранения', (tester) async {
final cubit = MockSettingsCubit();
const state = SettingsState.loaded(
profileSettings: mockProfileSettings,
profileDetails: mockProfileDetails,
profile: mockProfile,
hasActiveConsultation: false,
);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
await tester.pumpWidget(
BlocProvider<SettingsCubit>.value(
value: cubit,
child: wrap(PhysicalFormScreen(settingsEntity: settingsEntity)),
),
);
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
await tester.tap(find.text('Сохранить'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
final toastMessages = toastCalls.where((call) => call.method == 'showToast').map((call) => call.arguments['msg']);
expect(toastMessages, contains('Данные успешно сохранены'));
await tester.pumpAndSettle();
expect(find.byType(PhysicalFormScreen), findsNothing);
expect(find.text('open screen'), findsOneWidget);
await tester.pump(const Duration(seconds: 2));
});
testWidgets('не показывает уведомление и остаётся на экране при ошибке сохранения', (tester) async {
final cubit = MockSettingsCubit();
const state = SettingsState.loaded(
profileSettings: mockProfileSettings,
profileDetails: mockProfileDetails,
profile: mockProfile,
hasActiveConsultation: false,
);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => false);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
await tester.pumpWidget(
BlocProvider<SettingsCubit>.value(
value: cubit,
child: wrap(PhysicalFormScreen(settingsEntity: settingsEntity)),
),
);
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
await tester.tap(find.text('Сохранить'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
expect(toastCalls.where((call) => call.method == 'showToast'), isEmpty);
expect(find.byType(PhysicalFormScreen), findsOneWidget);
});
});
}

View File

@@ -10,6 +10,7 @@ import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/se
import 'package:eatvio_app/features/settings/presentation/pages/pressure_screen.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -22,6 +23,8 @@ import 'pressure_screen_test.mocks.dart';
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
void main() {
group('PressureScreen smoke', () {
final toastCalls = <MethodCall>[];
setUpAll(() async {
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
});
@@ -29,6 +32,21 @@ void main() {
setUp(() async {
await sl.reset();
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
toastCalls.clear();
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
(MethodCall methodCall) async {
toastCalls.add(methodCall);
return null;
},
);
});
tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
null,
);
});
const mockProfile = ProfileModel(
@@ -92,7 +110,20 @@ void main() {
supportedLocales: const [Locale('ru')],
routerConfig: GoRouter(
initialLocation: '/',
routes: [GoRoute(path: '/', builder: (context, state) => child)],
routes: [
GoRoute(
path: '/',
builder: (context, state) => Scaffold(
body: Center(
child: TextButton(
onPressed: () => context.push('/screen'),
child: const Text('open screen'),
),
),
),
),
GoRoute(path: '/screen', builder: (context, state) => child),
],
),
);
}
@@ -109,7 +140,7 @@ void main() {
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
@@ -119,10 +150,82 @@ void main() {
child: wrap(PressureScreen(settingsEntity: settingsEntity)),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
expect(find.byType(PressureScreen), findsOneWidget);
});
testWidgets('показывает уведомление и возвращается к настройкам после успешного сохранения', (tester) async {
final cubit = MockSettingsCubit();
const state = SettingsState.loaded(
profileSettings: mockProfileSettings,
profileDetails: mockProfileDetails,
profile: mockProfile,
hasActiveConsultation: false,
);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
await tester.pumpWidget(
BlocProvider<SettingsCubit>.value(
value: cubit,
child: wrap(PressureScreen(settingsEntity: settingsEntity)),
),
);
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
await tester.tap(find.text('Сохранить'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
final toastMessages = toastCalls.where((call) => call.method == 'showToast').map((call) => call.arguments['msg']);
expect(toastMessages, contains('Данные успешно сохранены'));
await tester.pumpAndSettle();
expect(find.byType(PressureScreen), findsNothing);
expect(find.text('open screen'), findsOneWidget);
await tester.pump(const Duration(seconds: 2));
});
testWidgets('не показывает уведомление и остаётся на экране при ошибке сохранения', (tester) async {
final cubit = MockSettingsCubit();
const state = SettingsState.loaded(
profileSettings: mockProfileSettings,
profileDetails: mockProfileDetails,
profile: mockProfile,
hasActiveConsultation: false,
);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => false);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
await tester.pumpWidget(
BlocProvider<SettingsCubit>.value(
value: cubit,
child: wrap(PressureScreen(settingsEntity: settingsEntity)),
),
);
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
await tester.tap(find.text('Сохранить'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
expect(toastCalls.where((call) => call.method == 'showToast'), isEmpty);
expect(find.byType(PressureScreen), findsOneWidget);
});
});
}

View File

@@ -0,0 +1,162 @@
import 'package:eatvio_app/core/locator_service.dart';
import 'package:eatvio_app/core/models/pagination_model.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/video_calls/recordings/models/recording_status.dart';
import 'package:eatvio_app/features/video_calls/recordings/models/video_call_recording_model.dart';
import 'package:eatvio_app/features/video_calls/recordings/presentation/cubit/video_call_recordings_cubit.dart';
import 'package:eatvio_app/features/video_calls/recordings/presentation/pages/video_call_recordings_screen.dart';
import 'package:eatvio_app/features/video_calls/recordings/repositories/video_call_recordings_repository.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:network_image_mock/network_image_mock.dart';
class _MockRecordingsRepository extends Mock implements VideoCallRecordingsRepository {}
void main() {
late _MockRecordingsRepository repository;
VideoCallRecordingsPagination page(
List<VideoCallRecordingModel> data, {
int lastPage = 1,
}) {
return VideoCallRecordingsPagination(
data: data,
links: const Links(
first: 'https://example.com?page=1',
last: 'https://example.com?page=1',
prev: null,
next: null,
),
meta: Meta(
currentPage: 1,
from: data.isEmpty ? null : 1,
lastPage: lastPage,
links: const [],
perPage: 20,
to: data.isEmpty ? null : data.length,
total: data.length,
),
);
}
VideoCallRecordingModel recording(int id) {
return VideoCallRecordingModel(
id: id,
status: RecordingStatus.ready,
durationSeconds: 60,
createdAt: DateTime.utc(2026, 9, 21, 10),
previewUrl: 'https://example.com/preview.jpg',
fileUrl: 'https://example.com/file.mp4',
counterpart: const VideoCallRecordingCounterpartModel(name: 'Сидни', slug: 'sydney'),
);
}
setUp(() async {
await sl.reset();
repository = _MockRecordingsRepository();
sl.registerFactory<VideoCallRecordingsCubit>(
() => VideoCallRecordingsCubit(repository: repository),
);
});
tearDown(() async {
await sl.reset();
});
Widget wrap(Widget child) {
return MaterialApp(
theme: ThemeHelper().themeData(),
localizationsDelegates: const [S.delegate, ...GlobalMaterialLocalizations.delegates],
supportedLocales: const [Locale('ru')],
home: child,
);
}
testWidgets('short list can be pulled to refresh', (tester) async {
await mockNetworkImagesFor(() async {
when(() => repository.getRecordings(page: 1, period: null)).thenAnswer(
(_) async => page([recording(1)]),
);
await tester.pumpWidget(wrap(const VideoCallRecordingsScreen()));
await tester.pumpAndSettle();
final list = tester.widget<ListView>(find.byType(ListView));
expect(list.physics, isA<AlwaysScrollableScrollPhysics>());
await tester.fling(find.byType(ListView), const Offset(0, 400), 1200);
await tester.pump();
await tester.pump(const Duration(seconds: 1));
await tester.pumpAndSettle();
verify(() => repository.getRecordings(page: 1, period: null)).called(2);
});
});
testWidgets('pull on a short list does not request the next page', (tester) async {
await mockNetworkImagesFor(() async {
when(() => repository.getRecordings(page: 1, period: null)).thenAnswer(
(_) async => page([recording(1)], lastPage: 2),
);
when(() => repository.getRecordings(page: 2, period: null)).thenAnswer(
(_) async => page([recording(2)], lastPage: 2),
);
await tester.pumpWidget(wrap(const VideoCallRecordingsScreen()));
await tester.pumpAndSettle();
await tester.fling(find.byType(ListView), const Offset(0, 400), 1200);
await tester.pump();
await tester.pump(const Duration(seconds: 1));
await tester.pumpAndSettle();
verifyNever(() => repository.getRecordings(page: 2, period: null));
});
});
testWidgets('empty state text stays visible at a large text scale', (tester) async {
tester.view.physicalSize = const Size(320, 240);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
when(() => repository.getRecordings(page: 1, period: null)).thenAnswer(
(_) async => page(const []),
);
await tester.pumpWidget(
wrap(
const MediaQuery(
data: MediaQueryData(textScaler: TextScaler.linear(3)),
child: VideoCallRecordingsScreen(),
),
),
);
await tester.pumpAndSettle();
expect(find.text('Пока нет видеоконсультаций'), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets('empty list can be pulled to refresh', (tester) async {
when(() => repository.getRecordings(page: 1, period: null)).thenAnswer(
(_) async => page(const []),
);
await tester.pumpWidget(wrap(const VideoCallRecordingsScreen()));
await tester.pumpAndSettle();
expect(find.text('Пока нет видеоконсультаций'), findsOneWidget);
final list = tester.widget<ListView>(find.byType(ListView));
expect(list.physics, isA<AlwaysScrollableScrollPhysics>());
await tester.fling(find.text('Пока нет видеоконсультаций'), const Offset(0, 400), 1200);
await tester.pump();
await tester.pump(const Duration(seconds: 1));
await tester.pumpAndSettle();
verify(() => repository.getRecordings(page: 1, period: null)).called(2);
});
}

View File

@@ -14,6 +14,7 @@ class _MockDio extends Mock implements Dio {}
class _FakeDownloadsSaver extends Fake implements PublicDownloadsSaver {
String? lastSourcePath;
String? lastFileName;
String? lastSubfolder;
@override
Future<String> saveToDownloads({
@@ -24,7 +25,8 @@ class _FakeDownloadsSaver extends Fake implements PublicDownloadsSaver {
}) async {
lastSourcePath = sourcePath;
lastFileName = fileName;
return 'content://downloads/Itvio/$fileName';
lastSubfolder = subfolder;
return 'content://downloads/$subfolder/$fileName';
}
}
@@ -157,7 +159,8 @@ void main() {
);
expect(downloadsSaver.lastFileName, 'recording_1.mp4');
expect(saved, contains('Itvio'));
expect(downloadsSaver.lastSubfolder, 'Eatvio');
expect(saved, contains('Eatvio'));
expect(File(downloadsSaver.lastSourcePath!).existsSync(), isFalse);
});
}

View File

@@ -19,6 +19,7 @@ void main() {
testWidgets('VideoCallParticipantNameLabel renders consultant role above name', (tester) async {
await tester.pumpWidget(
MaterialApp(
locale: const Locale('en'),
localizationsDelegates: const [S.delegate, ...GlobalMaterialLocalizations.delegates],
supportedLocales: S.delegate.supportedLocales,
home: const Scaffold(
@@ -26,6 +27,7 @@ void main() {
),
),
);
await tester.pump();
expect(find.text('Alex'), findsOneWidget);
expect(find.text('Eatvio consultant'), findsOneWidget);