From 16084ee94c289fa301b17fc69f41876581ed024c Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Tue, 3 Nov 2026 17:40:54 +0300 Subject: [PATCH] fix(chat): guard diet duration and keep progress plank - show diet duration hint and plan duration in suggestion flow - disable diet CTA on duration mismatch with grey visual state - keep progress plank visible for personal_diet_setted - center step labels under their circles --- .../widgets/consultation_progress_plank.dart | 74 ++++++----- .../utils/consultation_progress_mapper.dart | 2 +- .../cubit/personal_diet_suggestion_cubit.dart | 6 +- .../cubit/personal_diet_suggestion_state.dart | 4 +- .../presentation/consultation_widget.dart | 57 ++++++++- .../personal_diet_suggestion_screen.dart | 120 +++++++++++++----- lib/generated/intl/messages_en.dart | 59 +++++---- lib/generated/intl/messages_ru.dart | 23 +++- lib/generated/l10n.dart | 45 +++++++ lib/l10n/intl_en.arb | 26 +++- lib/l10n/intl_ru.arb | 26 +++- .../chat_consultation_header_test.dart | 10 +- .../consultation_progress_plank_test.dart | 30 ++++- .../consultation_progress_mapper_test.dart | 6 +- .../personal_diet_suggestion_cubit_test.dart | 3 + .../personal_diet_suggestion_state_test.dart | 6 +- .../consultation_widget_test.dart | 65 ++++++++++ ...nal_diet_suggestion_screen_smoke_test.dart | 27 ++++ 18 files changed, 483 insertions(+), 106 deletions(-) diff --git a/lib/features/consultations/presentation/widgets/consultation_progress_plank.dart b/lib/features/consultations/presentation/widgets/consultation_progress_plank.dart index bfc71d6d..0ad10a62 100644 --- a/lib/features/consultations/presentation/widgets/consultation_progress_plank.dart +++ b/lib/features/consultations/presentation/widgets/consultation_progress_plank.dart @@ -22,47 +22,58 @@ class ConsultationProgressPlank extends StatelessWidget { return const SizedBox.shrink(); } - return Column( + return Row( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - children: [ - for (var index = 0; index < _steps.length; index++) ...[ - _ProgressStepCircle( - index: index, - isCompleted: progress.isStepCompleted(_steps[index]), - ), - if (index != _steps.length - 1) - Expanded( - child: Container( - height: 2, - color: progress.isStepCompleted(_steps[index]) - ? appTheme.greenA700 - : appTheme.lightGray00, - ), + for (var index = 0; index < _steps.length; index++) + Expanded( + child: Column( + children: [ + Row( + children: [ + Expanded( + child: Container( + height: 2, + color: index == 0 + ? Colors.transparent + : progress.isStepCompleted(_steps[index - 1]) + ? appTheme.greenA700 + : appTheme.lightGray00, + ), + ), + _ProgressStepCircle( + key: ValueKey('consultation_step_circle_$index'), + index: index, + isCompleted: progress.isStepCompleted(_steps[index]), + ), + Expanded( + child: Container( + height: 2, + color: index == _steps.length - 1 + ? Colors.transparent + : progress.isStepCompleted(_steps[index]) + ? appTheme.greenA700 + : appTheme.lightGray00, + ), + ), + ], ), - ], - ], - ), - const SizedBox(height: 6), - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - for (final step in _steps) - Expanded( - child: Text( - _stepLabel(S.of(context), step), + const SizedBox(height: 6), + Text( + _stepLabel(S.of(context), _steps[index]), + key: ValueKey('consultation_step_label_$index'), textAlign: TextAlign.center, maxLines: 2, overflow: TextOverflow.ellipsis, style: TextStyles.textFS10FW500.copyWith( - color: progress.isStepCompleted(step) + color: progress.isStepCompleted(_steps[index]) ? appTheme.black : appTheme.gray, ), ), - ), - ], - ), + ], + ), + ), ], ); } @@ -83,6 +94,7 @@ class ConsultationProgressPlank extends StatelessWidget { class _ProgressStepCircle extends StatelessWidget { const _ProgressStepCircle({ + super.key, required this.index, required this.isCompleted, }); diff --git a/lib/features/consultations/utils/consultation_progress_mapper.dart b/lib/features/consultations/utils/consultation_progress_mapper.dart index c37f6120..98b89d0c 100644 --- a/lib/features/consultations/utils/consultation_progress_mapper.dart +++ b/lib/features/consultations/utils/consultation_progress_mapper.dart @@ -52,7 +52,6 @@ bool _showProgressPlank(ChosenPlanStateEnum state) { switch (state) { case ChosenPlanStateEnum.stateInited: case ChosenPlanStateEnum.stateConfirmedByConsultant: - case ChosenPlanStateEnum.personalDietSet: case ChosenPlanStateEnum.stateChargeWasCollected: case ChosenPlanStateEnum.stateCanceledByTheInitiator: case ChosenPlanStateEnum.statePaymentFailed: @@ -61,6 +60,7 @@ bool _showProgressPlank(ChosenPlanStateEnum state) { case ChosenPlanStateEnum.stateStartDateHasBeenSet: case ChosenPlanStateEnum.statePendingPayment: case ChosenPlanStateEnum.statePaid: + case ChosenPlanStateEnum.personalDietSet: case ChosenPlanStateEnum.stateStarted: case ChosenPlanStateEnum.stateInProgress: case ChosenPlanStateEnum.stateLastDayStarted: diff --git a/lib/features/personal_diet_suggestion/cubit/personal_diet_suggestion_cubit.dart b/lib/features/personal_diet_suggestion/cubit/personal_diet_suggestion_cubit.dart index fb15fcea..1d8f150e 100644 --- a/lib/features/personal_diet_suggestion/cubit/personal_diet_suggestion_cubit.dart +++ b/lib/features/personal_diet_suggestion/cubit/personal_diet_suggestion_cubit.dart @@ -19,7 +19,11 @@ class PersonalDietSuggestionCubit extends Cubit { } final diet = await dietRepository.getDiet(dietId); if (!isClosed) { - emit(state.copyWith(isLoading: false, dietName: diet.name)); + emit(state.copyWith( + isLoading: false, + dietName: diet.name, + dietDuration: diet.duration, + )); } } catch (e, st) { await reportFrom(e, st, this); diff --git a/lib/features/personal_diet_suggestion/cubit/personal_diet_suggestion_state.dart b/lib/features/personal_diet_suggestion/cubit/personal_diet_suggestion_state.dart index da927703..0270dc4d 100644 --- a/lib/features/personal_diet_suggestion/cubit/personal_diet_suggestion_state.dart +++ b/lib/features/personal_diet_suggestion/cubit/personal_diet_suggestion_state.dart @@ -9,8 +9,8 @@ abstract class PersonalDietSuggestionState with _$PersonalDietSuggestionState { @Default([]) List consultationsWithDiet, @Default([]) List consultationsWithoutDiet, @Default('') String dietName, + @Default(0) int dietDuration, @Default(false) bool isLoading, @Default(null) String? error, }) = _PersonalDietSuggestionState; - -} \ No newline at end of file +} diff --git a/lib/features/personal_diet_suggestion/presentation/consultation_widget.dart b/lib/features/personal_diet_suggestion/presentation/consultation_widget.dart index 2e74e582..a6846e57 100644 --- a/lib/features/personal_diet_suggestion/presentation/consultation_widget.dart +++ b/lib/features/personal_diet_suggestion/presentation/consultation_widget.dart @@ -4,6 +4,7 @@ import 'package:eatvio_app/core/app_router.dart'; import 'package:eatvio_app/core/locator_service.dart'; import 'package:eatvio_app/core/theme/custom_text_style.dart'; import 'package:eatvio_app/core/theme/theme_helper.dart'; +import 'package:eatvio_app/core/utils/localization_utils.dart'; import 'package:eatvio_app/core/widgets/bottom_sheet_handler_bar.dart'; import 'package:eatvio_app/core/widgets/bottom_sheet_with_blur.dart'; import 'package:eatvio_app/core/widgets/custom_outlined_button.dart'; @@ -20,9 +21,15 @@ class ConsultationWidget extends StatelessWidget { super.key, required this.consultationModel, required this.dietName, + this.dietDuration = 0, }); final ConsultationModel consultationModel; final String dietName; + final int dietDuration; + + bool get _isDurationMismatch => + dietDuration > 0 && consultationModel.duration != dietDuration; + @override Widget build(BuildContext context) { final s = S.of(context); @@ -64,6 +71,15 @@ class ConsultationWidget extends StatelessWidget { color: const Color(0xFF88949F), ), ), + Text( + s.plan_duration_label( + consultationModel.duration, + getDayForm(consultationModel.duration, s), + ), + style: TextStyles.textMMedium.copyWith( + color: const Color(0xFF88949F), + ), + ), Text( s.start_date_label( DateFormat('dd.MM.yyyy').format( @@ -108,15 +124,47 @@ class ConsultationWidget extends StatelessWidget { color: const Color(0xFF88949F), ), ), + Text( + s.plan_duration_label( + consultationModel.duration, + getDayForm(consultationModel.duration, s), + ), + style: TextStyles.textMMedium.copyWith( + color: const Color(0xFF88949F), + ), + ), ], ), ], ), const SizedBox(height: 12), + if (_isDurationMismatch) + Padding( + padding: const EdgeInsets.only(bottom: 8), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Icon(Icons.error_outline, size: 18, color: appTheme.red), + const SizedBox(width: 8), + Expanded( + child: Text( + s.personal_diet_duration_mismatch( + dietDuration, + getDayForm(dietDuration, s), + consultationModel.duration, + getDayForm(consultationModel.duration, s), + ), + style: TextStyles.textSMedium.copyWith(color: appTheme.red), + ), + ), + ], + ), + ), if (consultationModel.personalDietId != null) CustomOutlinedButton( text: s.changeDiet, height: 52, + isDisabled: _isDurationMismatch, buttonTextStyle: TextStyles.textMSemibold.copyWith( color: appTheme.gray, ), @@ -171,12 +219,17 @@ class ConsultationWidget extends StatelessWidget { CustomOutlinedButton( text: s.suggestDiet, height: 52, + isDisabled: _isDurationMismatch, buttonTextStyle: TextStyles.textMSemibold.copyWith( - color: appTheme.whiteA700, + color: _isDurationMismatch ? appTheme.gray : appTheme.whiteA700, ), buttonStyle: ButtonStyle( side: const WidgetStatePropertyAll(BorderSide.none), - backgroundColor: WidgetStatePropertyAll(appTheme.blueA400), + backgroundColor: WidgetStatePropertyAll( + _isDurationMismatch + ? appTheme.dividerColor + : appTheme.blueA400, + ), ), onPressed: () async { showBottomSheetWithBlur( diff --git a/lib/features/personal_diet_suggestion/presentation/personal_diet_suggestion_screen.dart b/lib/features/personal_diet_suggestion/presentation/personal_diet_suggestion_screen.dart index 32398019..0821f978 100644 --- a/lib/features/personal_diet_suggestion/presentation/personal_diet_suggestion_screen.dart +++ b/lib/features/personal_diet_suggestion/presentation/personal_diet_suggestion_screen.dart @@ -1,6 +1,7 @@ import 'package:eatvio_app/core/locator_service.dart'; import 'package:eatvio_app/core/theme/custom_text_style.dart'; import 'package:eatvio_app/core/theme/theme_helper.dart'; +import 'package:eatvio_app/core/utils/localization_utils.dart'; import 'package:eatvio_app/core/widgets/loader.dart'; import 'package:eatvio_app/features/personal_diet_suggestion/cubit/personal_diet_suggestion_cubit.dart'; import 'package:eatvio_app/features/personal_diet_suggestion/cubit/personal_diet_suggestion_state.dart'; @@ -17,7 +18,9 @@ class PersonalDietSuggestionScreen extends StatelessWidget { @override Widget build(BuildContext context) { return BlocProvider( - create: (context) => sl()..getConsultationWithPersonalDiets(dietId), + create: (context) => + sl() + ..getConsultationWithPersonalDiets(dietId), child: const PersonalDietSuggestionScreenContent(), ); } @@ -28,7 +31,10 @@ class PersonalDietSuggestionScreenContent extends StatelessWidget { @override Widget build(BuildContext context) { final s = S.of(context); - return BlocBuilder( + return BlocBuilder< + PersonalDietSuggestionCubit, + PersonalDietSuggestionState + >( builder: (context, state) { return Scaffold( backgroundColor: appTheme.gray100, @@ -36,45 +42,97 @@ class PersonalDietSuggestionScreenContent extends StatelessWidget { centerTitle: true, title: Text( '${s.dietSuggestion}\n«${state.dietName}»', - style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black), + style: TextStyles.headingXLSemibold.copyWith( + color: appTheme.black, + ), ), ), body: state.isLoading ? const Center(child: Loader()) - : (state.consultationsWithDiet.isEmpty && state.consultationsWithoutDiet.isEmpty) - ? Center( - child: Padding( - padding: const EdgeInsets.all(32.0), - child: Text( - 'Нет активных консультаций с персональной диетой', - style: TextStyles.textMSemibold.copyWith(color: appTheme.gray), - textAlign: TextAlign.center, - ), - ), - ) - : SingleChildScrollView( - child: Column( - children: [ - ...List.generate(state.consultationsWithDiet.length, (index) { - return ConsultationWidget( - consultationModel: state.consultationsWithDiet[index], - dietName: state.dietName, - ); - }), - const SizedBox( - height: 12, + : SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + if (state.dietDuration > 0) + Padding( + padding: const EdgeInsets.fromLTRB(16, 16, 16, 0), + child: _PersonalDietDurationHint( + duration: state.dietDuration, ), - ...List.generate(state.consultationsWithoutDiet.length, (index) { + ), + if (state.consultationsWithDiet.isEmpty && + state.consultationsWithoutDiet.isEmpty) + Padding( + padding: const EdgeInsets.all(32), + child: Text( + s.no_active_personal_diet_consultations, + style: TextStyles.textMSemibold.copyWith( + color: appTheme.gray, + ), + textAlign: TextAlign.center, + ), + ) + else ...[ + ...List.generate(state.consultationsWithDiet.length, ( + index, + ) { + return ConsultationWidget( + consultationModel: + state.consultationsWithDiet[index], + dietName: state.dietName, + dietDuration: state.dietDuration, + ); + }), + const SizedBox(height: 12), + ...List.generate( + state.consultationsWithoutDiet.length, + (index) { return ConsultationWidget( - consultationModel: state.consultationsWithoutDiet[index], + consultationModel: + state.consultationsWithoutDiet[index], dietName: state.dietName, + dietDuration: state.dietDuration, ); - }) - ], - ), - ), + }, + ), + ], + ], + ), + ), ); }, ); } } + +class _PersonalDietDurationHint extends StatelessWidget { + const _PersonalDietDurationHint({required this.duration}); + + final int duration; + + @override + Widget build(BuildContext context) { + final s = S.of(context); + return Container( + padding: const EdgeInsets.all(12), + decoration: BoxDecoration( + color: appTheme.gray50, + borderRadius: BorderRadius.circular(12), + border: Border.all(color: appTheme.dividerColor), + ), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Icon(Icons.info_outline, size: 20, color: appTheme.blueA400), + const SizedBox(width: 8), + Expanded( + child: Text( + s.personal_diet_duration_hint(duration, getDayForm(duration, s)), + style: TextStyles.textSMedium.copyWith(color: appTheme.gray), + ), + ), + ], + ), + ); + } +} diff --git a/lib/generated/intl/messages_en.dart b/lib/generated/intl/messages_en.dart index 2a2f9203..30ef7582 100644 --- a/lib/generated/intl/messages_en.dart +++ b/lib/generated/intl/messages_en.dart @@ -22,34 +22,42 @@ class MessageLookup extends MessageLookupByLibrary { static String m0(date) => "Консультант прокомментировал день ${date}"; - static String m1(planName) => "План «${planName}» начался"; + static String m1(duration, dayWord) => + "The diet lasts ${duration} ${dayWord}. It can only be offered for a plan with the same duration."; - static String m2(planName, name) => + static String m2(dietDuration, dietDayWord, planDuration, planDayWord) => + "Not suitable: diet lasts ${dietDuration} ${dietDayWord}, plan lasts ${planDuration} ${planDayWord}."; + + static String m3(planName) => "План «${planName}» начался"; + + static String m4(planName, name) => "План «${planName}» с пользователем ${name} начался"; - static String m3(percent, amount) => + static String m5(duration, dayWord) => "Plan for ${duration} ${dayWord}"; + + static String m6(percent, amount) => "Discount ${percent}% — you save ${amount} ₽"; - static String m4(date) => "Start: ${date}"; + static String m7(date) => "Start: ${date}"; - static String m5(step) => "шаг ${step} из 2"; + static String m8(step) => "шаг ${step} из 2"; - static String m6(planName, name) => + static String m9(planName, name) => "Завтра начинается план «${planName}» с пользователем ${name}"; - static String m7(planName) => + static String m10(planName) => "Завтра начнется прохождение плана «${planName}»"; - static String m8(name, planName) => + static String m11(name, planName) => "Пользователь ${name} отменил подписку на план «${planName}»"; - static String m9(name, planName) => + static String m12(name, planName) => "Пользователь ${name} оплатил план «${planName}»"; - static String m10(name, planName) => + static String m13(name, planName) => "Пользователь ${name} подписался на план «${planName}»"; - static String m11(planName) => "Вы отменили подписку на план «${planName}»"; + static String m14(planName) => "Вы отменили подписку на план «${planName}»"; final messages = _notInlinedMessages(_notInlinedMessages); static Map _notInlinedMessages(_) => { @@ -609,6 +617,10 @@ class MessageLookup extends MessageLookupByLibrary { "nicotine": MessageLookupByLibrary.simpleMessage("Никотин"), "no": MessageLookupByLibrary.simpleMessage("Нет"), "no_account": MessageLookupByLibrary.simpleMessage("У меня нет аккаунта"), + "no_active_personal_diet_consultations": + MessageLookupByLibrary.simpleMessage( + "No active consultations with a personal diet", + ), "no_default_cards": MessageLookupByLibrary.simpleMessage( "У вас нет привязанных карт. Что бы начать работу, привяжите карту", ), @@ -673,6 +685,8 @@ class MessageLookup extends MessageLookupByLibrary { "personalDietCreating": MessageLookupByLibrary.simpleMessage( "Составление индивидуальной диеты", ), + "personal_diet_duration_hint": m1, + "personal_diet_duration_mismatch": m2, "personal_diet_not_proposed": MessageLookupByLibrary.simpleMessage( "Personal diet not proposed", ), @@ -698,17 +712,18 @@ class MessageLookup extends MessageLookupByLibrary { "Физическая форма", ), "place_of_living": MessageLookupByLibrary.simpleMessage("Место проживания"), - "planStarted": m1, + "planStarted": m3, "planWillBeConfirmedAfterThreeDays": MessageLookupByLibrary.simpleMessage( "Если вы не подтвердите, то план через три дня подтвердится автоматически", ), - "planWithUserStarted": m2, + "planWithUserStarted": m4, "plan_author": MessageLookupByLibrary.simpleMessage("Автор плана"), "plan_desc": MessageLookupByLibrary.simpleMessage("Описание плана"), "plan_desc_example": MessageLookupByLibrary.simpleMessage( "Большое подробное, привлекательное описание плана", ), "plan_duration": MessageLookupByLibrary.simpleMessage("Срок плана"), + "plan_duration_label": m5, "plan_label_desc": MessageLookupByLibrary.simpleMessage( "План для поддержания формы", ), @@ -745,7 +760,7 @@ class MessageLookup extends MessageLookupByLibrary { "Promo code applied!", ), "promo_code": MessageLookupByLibrary.simpleMessage("Promo code"), - "promo_discount_hint": m3, + "promo_discount_hint": m6, "promo_invalid": MessageLookupByLibrary.simpleMessage( "Promo code not found or expired", ), @@ -838,13 +853,13 @@ class MessageLookup extends MessageLookupByLibrary { "Выбрана дата старта", ), "startDiet": MessageLookupByLibrary.simpleMessage("Начать диету"), - "start_date_label": m4, + "start_date_label": m7, "statistic": MessageLookupByLibrary.simpleMessage("Статистика"), "step": MessageLookupByLibrary.simpleMessage("Шаг"), "step_by_step_photo_recipe": MessageLookupByLibrary.simpleMessage( "Пошаговый фоторецепт", ), - "step_widget": m5, + "step_widget": m8, "successfully_published": MessageLookupByLibrary.simpleMessage( "успешно опубликован", ), @@ -869,8 +884,8 @@ class MessageLookup extends MessageLookupByLibrary { "toOffer": MessageLookupByLibrary.simpleMessage("Предложить"), "to_draft": MessageLookupByLibrary.simpleMessage("В черновик"), "to_order": MessageLookupByLibrary.simpleMessage("Заказать"), - "tommorowPlanWithUserWillStart": m6, - "tomorrowYourPlanWillStart": m7, + "tommorowPlanWithUserWillStart": m9, + "tomorrowYourPlanWillStart": m10, "try_again": MessageLookupByLibrary.simpleMessage("Попробовать снова"), "try_again_2": MessageLookupByLibrary.simpleMessage("Попробуйте ещё раз"), "typeAmoutOfReturn": MessageLookupByLibrary.simpleMessage( @@ -904,7 +919,7 @@ class MessageLookup extends MessageLookupByLibrary { "Верхние показатели давления:", ), "upper": MessageLookupByLibrary.simpleMessage("Верхнее"), - "userCanceldThePlanSubscription": m8, + "userCanceldThePlanSubscription": m11, "userConfirmedPlanCompletion": MessageLookupByLibrary.simpleMessage( "Пользователь подтвердил прохождения плана. В ближайшее время Вы получите", ), @@ -912,8 +927,8 @@ class MessageLookup extends MessageLookupByLibrary { MessageLookupByLibrary.simpleMessage( "Пользователь подтвердил прохождения плана.", ), - "userPaidThePlan": m9, - "userSubscribedToPlan": m10, + "userPaidThePlan": m12, + "userSubscribedToPlan": m13, "user_authorization": MessageLookupByLibrary.simpleMessage( "Аутентификация", ), @@ -1043,7 +1058,7 @@ class MessageLookup extends MessageLookupByLibrary { "youCanComplain": MessageLookupByLibrary.simpleMessage( "Если вас что-то не устроило, вы можете подать жалобу", ), - "youCanceledSubscriptionToPlan": m11, + "youCanceledSubscriptionToPlan": m14, "youShureYouWantToCancelOrder": MessageLookupByLibrary.simpleMessage( "Вы уверены, что хотите отменить заказ?", ), diff --git a/lib/generated/intl/messages_ru.dart b/lib/generated/intl/messages_ru.dart index 34a668d5..f6788ff2 100644 --- a/lib/generated/intl/messages_ru.dart +++ b/lib/generated/intl/messages_ru.dart @@ -20,10 +20,18 @@ typedef String MessageIfAbsent(String messageStr, List args); class MessageLookup extends MessageLookupByLibrary { String get localeName => 'ru'; - static String m3(percent, amount) => + static String m1(duration, dayWord) => + "Диета рассчитана на ${duration} ${dayWord}. Предложить её можно только для плана с такой же длительностью."; + + static String m2(dietDuration, dietDayWord, planDuration, planDayWord) => + "Не подходит: диета на ${dietDuration} ${dietDayWord}, план на ${planDuration} ${planDayWord}."; + + static String m5(duration, dayWord) => "План на ${duration} ${dayWord}"; + + static String m6(percent, amount) => "Скидка ${percent}% — вы экономите ${amount} ₽"; - static String m4(date) => "Старт: ${date}"; + static String m7(date) => "Старт: ${date}"; final messages = _notInlinedMessages(_notInlinedMessages); static Map _notInlinedMessages(_) => { @@ -276,6 +284,10 @@ class MessageLookup extends MessageLookupByLibrary { ), "no": MessageLookupByLibrary.simpleMessage("Нет"), "no_account": MessageLookupByLibrary.simpleMessage("У меня нет аккаунта"), + "no_active_personal_diet_consultations": + MessageLookupByLibrary.simpleMessage( + "Нет активных консультаций с персональной диетой", + ), "no_installed_banks": MessageLookupByLibrary.simpleMessage( "Нет установленных банков", ), @@ -317,6 +329,8 @@ class MessageLookup extends MessageLookupByLibrary { "payment_failed": MessageLookupByLibrary.simpleMessage("Оплата не прошла"), "pcs": MessageLookupByLibrary.simpleMessage("шт"), "personal": MessageLookupByLibrary.simpleMessage("Персональные"), + "personal_diet_duration_hint": m1, + "personal_diet_duration_mismatch": m2, "personal_diet_not_proposed": MessageLookupByLibrary.simpleMessage( "Диета не предложена", ), @@ -338,6 +352,7 @@ class MessageLookup extends MessageLookupByLibrary { "Большое подробное, привлекательное описание плана", ), "plan_duration": MessageLookupByLibrary.simpleMessage("Срок плана"), + "plan_duration_label": m5, "plan_label_desc": MessageLookupByLibrary.simpleMessage( "План для поддержания формы", ), @@ -365,7 +380,7 @@ class MessageLookup extends MessageLookupByLibrary { "Промокод применён!", ), "promo_code": MessageLookupByLibrary.simpleMessage("Промокод"), - "promo_discount_hint": m3, + "promo_discount_hint": m6, "promo_invalid": MessageLookupByLibrary.simpleMessage( "Промокод не найден или истёк", ), @@ -398,7 +413,7 @@ class MessageLookup extends MessageLookupByLibrary { "Выбрана дата старта", ), "startDiet": MessageLookupByLibrary.simpleMessage("Начать диету"), - "start_date_label": m4, + "start_date_label": m7, "suggestDiet": MessageLookupByLibrary.simpleMessage("Предложить диету"), "tell_your_schedule": MessageLookupByLibrary.simpleMessage( "Расскажите в свободной форме о том как просыпаетесь, когда едите, когда ложитесь спать:", diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index 69416eec..6079aad0 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -4503,6 +4503,51 @@ class S { args: [date], ); } + + /// `The diet lasts {duration} {dayWord}. It can only be offered for a plan with the same duration.` + String personal_diet_duration_hint(int duration, String dayWord) { + return Intl.message( + 'The diet lasts $duration $dayWord. It can only be offered for a plan with the same duration.', + name: 'personal_diet_duration_hint', + desc: '', + args: [duration, dayWord], + ); + } + + /// `Not suitable: diet lasts {dietDuration} {dietDayWord}, plan lasts {planDuration} {planDayWord}.` + String personal_diet_duration_mismatch( + int dietDuration, + String dietDayWord, + int planDuration, + String planDayWord, + ) { + return Intl.message( + 'Not suitable: diet lasts $dietDuration $dietDayWord, plan lasts $planDuration $planDayWord.', + name: 'personal_diet_duration_mismatch', + desc: '', + args: [dietDuration, dietDayWord, planDuration, planDayWord], + ); + } + + /// `Plan for {duration} {dayWord}` + String plan_duration_label(int duration, String dayWord) { + return Intl.message( + 'Plan for $duration $dayWord', + name: 'plan_duration_label', + desc: '', + args: [duration, dayWord], + ); + } + + /// `No active consultations with a personal diet` + String get no_active_personal_diet_consultations { + return Intl.message( + 'No active consultations with a personal diet', + name: 'no_active_personal_diet_consultations', + desc: '', + args: [], + ); + } } class AppLocalizationDelegate extends LocalizationsDelegate { diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 910e15e7..e26e2262 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -537,6 +537,30 @@ "placeholders": { "date": {"type": "String"} } - } + }, + "personal_diet_duration_hint": "The diet lasts {duration} {dayWord}. It can only be offered for a plan with the same duration.", + "@personal_diet_duration_hint": { + "placeholders": { + "duration": {"type": "int"}, + "dayWord": {"type": "String"} + } + }, + "personal_diet_duration_mismatch": "Not suitable: diet lasts {dietDuration} {dietDayWord}, plan lasts {planDuration} {planDayWord}.", + "@personal_diet_duration_mismatch": { + "placeholders": { + "dietDuration": {"type": "int"}, + "dietDayWord": {"type": "String"}, + "planDuration": {"type": "int"}, + "planDayWord": {"type": "String"} + } + }, + "plan_duration_label": "Plan for {duration} {dayWord}", + "@plan_duration_label": { + "placeholders": { + "duration": {"type": "int"}, + "dayWord": {"type": "String"} + } + }, + "no_active_personal_diet_consultations": "No active consultations with a personal diet" } diff --git a/lib/l10n/intl_ru.arb b/lib/l10n/intl_ru.arb index 04a2af45..0f161936 100644 --- a/lib/l10n/intl_ru.arb +++ b/lib/l10n/intl_ru.arb @@ -292,5 +292,29 @@ "placeholders": { "date": {"type": "String"} } - } + }, + "personal_diet_duration_hint": "Диета рассчитана на {duration} {dayWord}. Предложить её можно только для плана с такой же длительностью.", + "@personal_diet_duration_hint": { + "placeholders": { + "duration": {"type": "int"}, + "dayWord": {"type": "String"} + } + }, + "personal_diet_duration_mismatch": "Не подходит: диета на {dietDuration} {dietDayWord}, план на {planDuration} {planDayWord}.", + "@personal_diet_duration_mismatch": { + "placeholders": { + "dietDuration": {"type": "int"}, + "dietDayWord": {"type": "String"}, + "planDuration": {"type": "int"}, + "planDayWord": {"type": "String"} + } + }, + "plan_duration_label": "План на {duration} {dayWord}", + "@plan_duration_label": { + "placeholders": { + "duration": {"type": "int"}, + "dayWord": {"type": "String"} + } + }, + "no_active_personal_diet_consultations": "Нет активных консультаций с персональной диетой" } diff --git a/test/features/chat/presentation/widgets/chat_consultation_header_test.dart b/test/features/chat/presentation/widgets/chat_consultation_header_test.dart index 18d154e4..96c10b05 100644 --- a/test/features/chat/presentation/widgets/chat_consultation_header_test.dart +++ b/test/features/chat/presentation/widgets/chat_consultation_header_test.dart @@ -50,13 +50,13 @@ void main() { }); testWidgets( - 'при showProgressPlank=false и proposed видны заголовок и чип, плашки нет', + 'personal_diet_setted показывает плашку и чип вместе с баннером замены', (tester) async { final progress = mapConsultationProgress( state: ChosenPlanStateEnum.personalDietSet, hasPersonalDiet: true, ); - expect(progress.showProgressPlank, isFalse); + expect(progress.showProgressPlank, isTrue); expect(progress.dietStatus, PersonalDietStatus.proposed); await tester.pumpWidget( @@ -71,11 +71,11 @@ void main() { final s = S.of(tester.element(find.byType(ChatConsultationHeader))); - expect(find.text(s.more_about_order), findsOneWidget); + expect(find.text(s.order_in_progress), findsNWidgets(2)); expect(find.byType(PersonalDietStatusChip), findsOneWidget); expect(find.text(s.personal_diet_proposed), findsOneWidget); - expect(find.byType(ConsultationProgressPlank), findsNothing); - expect(find.byIcon(Icons.check), findsNothing); + expect(find.byType(ConsultationProgressPlank), findsOneWidget); + expect(find.byIcon(Icons.check), findsNWidgets(2)); }, ); }); diff --git a/test/features/consultations/presentation/widgets/consultation_progress_plank_test.dart b/test/features/consultations/presentation/widgets/consultation_progress_plank_test.dart index a7e81ce1..6d50d483 100644 --- a/test/features/consultations/presentation/widgets/consultation_progress_plank_test.dart +++ b/test/features/consultations/presentation/widgets/consultation_progress_plank_test.dart @@ -25,7 +25,7 @@ void main() { group('ConsultationProgressPlank', () { testWidgets('не строит шаги при showProgressPlank=false', (tester) async { final progress = mapConsultationProgress( - state: ChosenPlanStateEnum.personalDietSet, + state: ChosenPlanStateEnum.stateConfirmedByConsultant, hasPersonalDiet: true, ); expect(progress.showProgressPlank, isFalse); @@ -67,5 +67,33 @@ void main() { expect(find.text(s.done), findsOneWidget); }, ); + + testWidgets('подписи шагов центрированы под своими кружками', ( + tester, + ) async { + final progress = mapConsultationProgress( + state: ChosenPlanStateEnum.stateDone, + hasPersonalDiet: false, + ); + + await tester.pumpWidget( + _wrap( + SizedBox( + width: 360, + child: ConsultationProgressPlank(progress: progress), + ), + ), + ); + + for (var index = 0; index < 4; index++) { + final circle = tester.getCenter( + find.byKey(ValueKey('consultation_step_circle_$index')), + ); + final label = tester.getCenter( + find.byKey(ValueKey('consultation_step_label_$index')), + ); + expect(label.dx, closeTo(circle.dx, 0.5)); + } + }); }); } diff --git a/test/features/consultations/utils/consultation_progress_mapper_test.dart b/test/features/consultations/utils/consultation_progress_mapper_test.dart index 09ee87a8..16c0f1c5 100644 --- a/test/features/consultations/utils/consultation_progress_mapper_test.dart +++ b/test/features/consultations/utils/consultation_progress_mapper_test.dart @@ -96,7 +96,7 @@ final Map _expectations = { ), ChosenPlanStateEnum.personalDietSet: ( steps: {_startDate, _paid}, - plank: false, + plank: true, diet: PersonalDietStatus.proposed, phase: ConsultationPhase.active, ), @@ -148,14 +148,14 @@ void main() { }); test( - 'personal_diet_setted не показывает плашку и завершает startDate+paid', + 'personal_diet_setted показывает плашку и завершает startDate+paid', () { final progress = mapConsultationProgress( state: ChosenPlanStateEnum.personalDietSet, hasPersonalDiet: true, ); - expect(progress.showProgressPlank, isFalse); + expect(progress.showProgressPlank, isTrue); expect(progress.completedSteps, unorderedEquals([_startDate, _paid])); }, ); diff --git a/test/features/personal_diet_suggestion/cubit/personal_diet_suggestion_cubit_test.dart b/test/features/personal_diet_suggestion/cubit/personal_diet_suggestion_cubit_test.dart index f1e5cfc3..c30b99f3 100644 --- a/test/features/personal_diet_suggestion/cubit/personal_diet_suggestion_cubit_test.dart +++ b/test/features/personal_diet_suggestion/cubit/personal_diet_suggestion_cubit_test.dart @@ -34,6 +34,7 @@ void main() { expect(cubit.state.consultationsWithDiet, isEmpty); expect(cubit.state.consultationsWithoutDiet, isEmpty); expect(cubit.state.dietName, isEmpty); + expect(cubit.state.dietDuration, 0); expect(cubit.state.isLoading, isFalse); expect(cubit.state.error, isNull); }); @@ -71,6 +72,7 @@ void main() { await cubit.setDietName(dietId); expect(cubit.state.dietName, equals(dietName)); + expect(cubit.state.dietDuration, 30); expect(cubit.state.isLoading, isFalse); verify(mockDietRepository.getDiet(dietId)).called(1); }); @@ -161,6 +163,7 @@ void main() { await cubit.getConsultationWithPersonalDiets(dietId); expect(cubit.state.dietName, equals(dietName)); + expect(cubit.state.dietDuration, 30); expect(cubit.state.consultationsWithDiet.length, 1); expect(cubit.state.consultationsWithoutDiet.length, 1); expect(cubit.state.isLoading, isFalse); diff --git a/test/features/personal_diet_suggestion/cubit/personal_diet_suggestion_state_test.dart b/test/features/personal_diet_suggestion/cubit/personal_diet_suggestion_state_test.dart index 256bb75b..23be2f78 100644 --- a/test/features/personal_diet_suggestion/cubit/personal_diet_suggestion_state_test.dart +++ b/test/features/personal_diet_suggestion/cubit/personal_diet_suggestion_state_test.dart @@ -9,6 +9,7 @@ void main() { expect(state.consultationsWithDiet, isEmpty); expect(state.consultationsWithoutDiet, isEmpty); expect(state.dietName, ''); + expect(state.dietDuration, 0); expect(state.isLoading, isFalse); expect(state.error, isNull); }); @@ -16,6 +17,7 @@ void main() { test('creates instance with custom values', () { final state = PersonalDietSuggestionState( dietName: 'Test Diet', + dietDuration: 14, isLoading: true, error: 'Test error', ); @@ -23,6 +25,7 @@ void main() { expect(state.consultationsWithDiet, isEmpty); expect(state.consultationsWithoutDiet, isEmpty); expect(state.dietName, 'Test Diet'); + expect(state.dietDuration, 14); expect(state.isLoading, isTrue); expect(state.error, 'Test error'); }); @@ -31,14 +34,15 @@ void main() { final original = PersonalDietSuggestionState(); final updated = original.copyWith( dietName: 'New Diet', + dietDuration: 7, isLoading: true, ); expect(updated.dietName, 'New Diet'); + expect(updated.dietDuration, 7); expect(updated.isLoading, isTrue); expect(updated.consultationsWithDiet, original.consultationsWithDiet); expect(updated.error, original.error); }); }); } - diff --git a/test/features/personal_diet_suggestion/presentation/consultation_widget_test.dart b/test/features/personal_diet_suggestion/presentation/consultation_widget_test.dart index 1f6fb0e1..6aef200f 100644 --- a/test/features/personal_diet_suggestion/presentation/consultation_widget_test.dart +++ b/test/features/personal_diet_suggestion/presentation/consultation_widget_test.dart @@ -2,6 +2,7 @@ import 'package:eatvio_app/core/app_config.dart'; import 'package:eatvio_app/core/app_initializer.dart'; import 'package:eatvio_app/core/locator_service.dart'; import 'package:eatvio_app/core/theme/theme_helper.dart'; +import 'package:eatvio_app/core/utils/localization_utils.dart'; import 'package:eatvio_app/features/consultations/models/consultation_model.dart'; import 'package:eatvio_app/features/plans/enums/chosen_plan_state_enum.dart'; import 'package:eatvio_app/features/personal_diet_suggestion/cubit/personal_diet_suggestion_cubit.dart'; @@ -369,5 +370,69 @@ void main() { expect(find.text('Старт: 01.01.2025'), findsNothing); }); }); + + testWidgets('disables CTA when plan duration differs from diet duration', (tester) async { + await mockNetworkImagesFor(() async { + final cubit = MockPersonalDietSuggestionCubit(); + final consultation = ConsultationModel( + id: 1, + chosenPlanState: ChosenPlanStateEnum.stateInProgress, + planTitle: 'Test Plan', + userName: 'Test User', + userSlug: 'test-user', + consultantPayment: 1000.0, + duration: 14, + currentDiaryDay: 3, + userProfilePhotoUrl: '/avatar.jpg', + consultationOptionPrice: 500, + startDate: DateTime(2025, 1, 1), + endDate: DateTime(2025, 1, 15), + consultantId: 1, + diaries: [], + personalDietId: null, + ); + + when(cubit.state).thenReturn(PersonalDietSuggestionState()); + when(cubit.stream).thenAnswer((_) => const Stream.empty()); + when(cubit.close()).thenAnswer((_) async => Future.value()); + + await tester.pumpWidget( + BlocProvider.value( + value: cubit, + child: wrap( + ConsultationWidget( + consultationModel: consultation, + dietName: 'Test Diet', + dietDuration: 7, + ), + ), + ), + ); + await tester.pumpAndSettle(); + + final s = S.of(tester.element(find.byType(ConsultationWidget))); + expect( + find.text( + s.personal_diet_duration_mismatch( + 7, + getDayForm(7, s), + 14, + getDayForm(14, s), + ), + ), + findsOneWidget, + ); + final button = tester.widget(find.byType(OutlinedButton)); + expect(button.onPressed, isNull); + expect( + button.style?.backgroundColor?.resolve({WidgetState.disabled}), + appTheme.dividerColor, + ); + expect( + tester.widget(find.text(s.suggestDiet)).style?.color, + appTheme.gray, + ); + }); + }); }); } diff --git a/test/features/personal_diet_suggestion/presentation/personal_diet_suggestion_screen_smoke_test.dart b/test/features/personal_diet_suggestion/presentation/personal_diet_suggestion_screen_smoke_test.dart index b74938ae..624d85ac 100644 --- a/test/features/personal_diet_suggestion/presentation/personal_diet_suggestion_screen_smoke_test.dart +++ b/test/features/personal_diet_suggestion/presentation/personal_diet_suggestion_screen_smoke_test.dart @@ -2,6 +2,7 @@ import 'package:eatvio_app/core/app_config.dart'; import 'package:eatvio_app/core/app_initializer.dart'; import 'package:eatvio_app/core/locator_service.dart'; import 'package:eatvio_app/core/theme/theme_helper.dart'; +import 'package:eatvio_app/core/utils/localization_utils.dart'; import 'package:eatvio_app/features/personal_diet_suggestion/cubit/personal_diet_suggestion_cubit.dart'; import 'package:eatvio_app/features/personal_diet_suggestion/cubit/personal_diet_suggestion_state.dart'; import 'package:eatvio_app/features/personal_diet_suggestion/presentation/personal_diet_suggestion_screen.dart'; @@ -84,5 +85,31 @@ void main() { expect(find.textContaining('Test Diet Name'), findsOneWidget); }); + + testWidgets('shows diet duration hint and empty state', (tester) async { + final cubit = MockPersonalDietSuggestionCubit(); + const dietDuration = 7; + final state = PersonalDietSuggestionState( + isLoading: false, + dietName: 'Test Diet', + dietDuration: dietDuration, + consultationsWithDiet: [], + consultationsWithoutDiet: [], + ); + + when(cubit.state).thenReturn(state); + when(cubit.stream).thenAnswer((_) => Stream.value(state)); + when(cubit.close()).thenAnswer((_) async => Future.value()); + + await tester.pumpWidget(wrap(const PersonalDietSuggestionScreenContent(), cubit)); + await tester.pump(); + + final s = S.of(tester.element(find.byType(PersonalDietSuggestionScreenContent))); + expect( + find.text(s.personal_diet_duration_hint(dietDuration, getDayForm(dietDuration, s))), + findsOneWidget, + ); + expect(find.text(s.no_active_personal_diet_consultations), findsOneWidget); + }); }); }