From 28ae75474aca432cab740cbe707096a698fc1c1c Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Tue, 10 Nov 2026 13:52:06 +0300 Subject: [PATCH] fix: localize diet notification and type plan options --- .../chat/presentation/pages/chat_screen.dart | 1 - .../widgets/notification_widget.dart | 9 ++- .../presentation/info_by_order_screen.dart | 10 +-- .../plans/enums/plan_option_type_enum.dart | 29 ++++++++ .../plans/models/chosen_plan_model.dart | 14 ++-- .../presentation/cubit/about_plan_cubit.dart | 9 +-- lib/generated/intl/messages_en.dart | 69 +++++++++++-------- lib/generated/intl/messages_ru.dart | 33 +++++---- lib/generated/l10n.dart | 28 ++++++++ lib/l10n/intl_en.arb | 14 ++++ lib/l10n/intl_ru.arb | 14 ++++ .../widgets/notification_widget_test.dart | 62 ++++++++++++++++- .../plans/models/chosen_plan_model_test.dart | 60 ++++++++++++++++ 13 files changed, 281 insertions(+), 71 deletions(-) create mode 100644 lib/features/plans/enums/plan_option_type_enum.dart diff --git a/lib/features/chat/presentation/pages/chat_screen.dart b/lib/features/chat/presentation/pages/chat_screen.dart index ee1b351f..5c8db98c 100644 --- a/lib/features/chat/presentation/pages/chat_screen.dart +++ b/lib/features/chat/presentation/pages/chat_screen.dart @@ -30,7 +30,6 @@ import 'package:eatvio_app/features/chat/utils/chat_counterpart_utils.dart'; import 'package:eatvio_app/features/consultations/utils/consultation_progress_mapper.dart'; import 'package:eatvio_app/features/order_info/presentation/info_by_order_screen.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/features/user_details/presentation/user_details_screen.dart'; import 'package:eatvio_app/features/video_calls/managers/video_call_manager.dart'; import 'package:eatvio_app/features/video_calls/presentation/pages/video_call_screen.dart'; diff --git a/lib/features/notifications/presentation/widgets/notification_widget.dart b/lib/features/notifications/presentation/widgets/notification_widget.dart index ed3c4dab..2c6dfd2e 100644 --- a/lib/features/notifications/presentation/widgets/notification_widget.dart +++ b/lib/features/notifications/presentation/widgets/notification_widget.dart @@ -1281,12 +1281,15 @@ class _PersonalDietIsDefinedToAuthorWidget extends StatelessWidget { final PersonalDietIsDefinedToAuthorNotification notification; @override Widget build(BuildContext context) { - final userName = notification.userName.isNotEmpty ? notification.userName : 'Пользователь'; - final dietName = notification.dietName.isNotEmpty ? ', выбранная диета: «${notification.dietName}»' : ''; + final s = S.of(context); + final userName = notification.userName.isNotEmpty ? notification.userName : s.default_user_name; + final notificationsText = notification.dietName.isEmpty + ? s.personal_diet_defined_to_author(userName) + : s.personal_diet_defined_to_author_named(userName, notification.dietName); return _BaseNotificationWidget( isRead: notification.isRead, - notificationsText: 'Вы предложили персональную диету пользователю $userName$dietName', + notificationsText: notificationsText, createdAt: notification.createdAt, onTap: notification.peerSlug.isEmpty ? null diff --git a/lib/features/order_info/presentation/info_by_order_screen.dart b/lib/features/order_info/presentation/info_by_order_screen.dart index 40a5f8c2..f6fd1771 100644 --- a/lib/features/order_info/presentation/info_by_order_screen.dart +++ b/lib/features/order_info/presentation/info_by_order_screen.dart @@ -6,7 +6,6 @@ import 'package:eatvio_app/features/cancel_plan_bottom_sheet/cancel_plan_bottom_ import 'package:eatvio_app/core/widgets/custom_outlined_button.dart'; import 'package:eatvio_app/core/widgets/loader.dart'; import 'package:eatvio_app/features/diets/presentation/widgets/author_card.dart'; -import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart'; import 'package:eatvio_app/features/order_info/cubit/order_info_cubit.dart'; import 'package:eatvio_app/features/order_info/cubit/order_info_state.dart'; import 'package:eatvio_app/features/order_info/presentation/widgets/collect_charge_banner.dart'; @@ -106,14 +105,7 @@ class _InfoByOrderScreenContentState extends State { ), ); } - PacketOptions? chosenOption; - if (plan.optionType == 'options1') { - chosenOption = plan.plan.packet1Options; - } else if (plan.optionType == 'options2') { - chosenOption = plan.plan.packet2Options; - } else { - chosenOption = plan.plan.packet3Options; - } + final chosenOption = plan.chosenOption; PlanStatusValues planStatus; if (widget.successfulPayment == true) { diff --git a/lib/features/plans/enums/plan_option_type_enum.dart b/lib/features/plans/enums/plan_option_type_enum.dart new file mode 100644 index 00000000..4b231bdc --- /dev/null +++ b/lib/features/plans/enums/plan_option_type_enum.dart @@ -0,0 +1,29 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +enum PlanOptionType { + @JsonValue('options1') + options1('options1'), + @JsonValue('options2') + options2('options2'), + @JsonValue('options3') + options3('options3'); + + const PlanOptionType(this.apiValue); + + final String apiValue; + + static PlanOptionType? tryParse(String? raw) { + for (final option in values) { + if (option.apiValue == raw) { + return option; + } + } + return null; + } + + static PlanOptionType fromIndex(int index) => switch (index) { + 1 => PlanOptionType.options2, + 2 => PlanOptionType.options3, + _ => PlanOptionType.options1, + }; +} diff --git a/lib/features/plans/models/chosen_plan_model.dart b/lib/features/plans/models/chosen_plan_model.dart index de1e61d3..73724a56 100644 --- a/lib/features/plans/models/chosen_plan_model.dart +++ b/lib/features/plans/models/chosen_plan_model.dart @@ -1,5 +1,6 @@ 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/enums/plan_option_type_enum.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; part 'chosen_plan_model.freezed.dart'; @@ -7,6 +8,7 @@ part 'chosen_plan_model.g.dart'; @freezed abstract class ChosenPlanModel with _$ChosenPlanModel { + const ChosenPlanModel._(); factory ChosenPlanModel({ @JsonKey() required int id, @@ -20,18 +22,16 @@ abstract class ChosenPlanModel with _$ChosenPlanModel { }) = _ChosenPlanModel; factory ChosenPlanModel.fromJson(Map json) => _$ChosenPlanModelFromJson(json); -} -extension ChosenPlanModelX on ChosenPlanModel { PacketOptions? get chosenOption { - switch (optionType) { - case 'options1': + switch (PlanOptionType.tryParse(optionType)) { + case PlanOptionType.options1: return plan.packet1Options; - case 'options2': + case PlanOptionType.options2: return plan.packet2Options; - case 'options3': + case PlanOptionType.options3: return plan.packet3Options; - default: + case null: return null; } } diff --git a/lib/features/plans/presentation/cubit/about_plan_cubit.dart b/lib/features/plans/presentation/cubit/about_plan_cubit.dart index 2c5b6b72..6cd354aa 100644 --- a/lib/features/plans/presentation/cubit/about_plan_cubit.dart +++ b/lib/features/plans/presentation/cubit/about_plan_cubit.dart @@ -4,6 +4,7 @@ import 'package:dio/dio.dart'; import 'package:easy_debounce/easy_debounce.dart'; import 'package:eatvio_app/core/utils/toasts.dart'; import 'package:eatvio_app/features/diets/repositories/diet_repository.dart'; +import 'package:eatvio_app/features/plans/enums/plan_option_type_enum.dart'; import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart'; import 'package:eatvio_app/features/plans/presentation/cubit/about_plan_state.dart'; import 'package:eatvio_app/features/plans/repositories/plan_repository.dart'; @@ -133,7 +134,7 @@ class AboutPlanCubit extends Cubit { final slug = state.planModel?.slug; final optionIndex = state.chosenOptionIndex; if (slug != null) { - final optionName = _getOptionNameFromIndex(optionIndex); + final optionName = PlanOptionType.fromIndex(optionIndex).apiValue; final body = {'options_type': optionName}; return (await planRepository.chosePlan(slug, body), null); } @@ -181,10 +182,4 @@ class AboutPlanCubit extends Cubit { return false; } } - - String _getOptionNameFromIndex(int index) => switch (index) { - 1 => 'options2', - 2 => 'options3', - _ => 'options1', - }; } diff --git a/lib/generated/intl/messages_en.dart b/lib/generated/intl/messages_en.dart index 8a5fffea..99a1c3c0 100644 --- a/lib/generated/intl/messages_en.dart +++ b/lib/generated/intl/messages_en.dart @@ -22,44 +22,50 @@ class MessageLookup extends MessageLookupByLibrary { static String m0(date) => "Консультант прокомментировал день ${date}"; - static String m1(duration, dayWord) => + static String m1(userName) => + "You have proposed a personal diet to ${userName}"; + + static String m2(userName, dietName) => + "You have proposed a personal diet to ${userName}, selected diet: «${dietName}»"; + + static String m3(duration, dayWord) => "The diet lasts ${duration} ${dayWord}. It can only be offered for a plan with the same duration."; - static String m2(dietDuration, dietDayWord, planDuration, planDayWord) => + static String m4(dietDuration, dietDayWord, planDuration, planDayWord) => "Not suitable: diet lasts ${dietDuration} ${dietDayWord}, plan lasts ${planDuration} ${planDayWord}."; - static String m3(name) => "Diet «${name}» proposed"; + static String m5(name) => "Diet «${name}» proposed"; - static String m4(planName) => "План «${planName}» начался"; + static String m6(planName) => "План «${planName}» начался"; - static String m5(planName, name) => + static String m7(planName, name) => "План «${planName}» с пользователем ${name} начался"; - static String m6(duration, dayWord) => "Plan for ${duration} ${dayWord}"; + static String m8(duration, dayWord) => "Plan for ${duration} ${dayWord}"; - static String m7(percent, amount) => + static String m9(percent, amount) => "Discount ${percent}% — you save ${amount} ₽"; - static String m8(date) => "Start: ${date}"; + static String m10(date) => "Start: ${date}"; - static String m9(step) => "шаг ${step} из 2"; + static String m11(step) => "шаг ${step} из 2"; - static String m10(planName, name) => + static String m12(planName, name) => "Завтра начинается план «${planName}» с пользователем ${name}"; - static String m11(planName) => + static String m13(planName) => "Завтра начнется прохождение плана «${planName}»"; - static String m12(name, planName) => + static String m14(name, planName) => "Пользователь ${name} отменил подписку на план «${planName}»"; - static String m13(name, planName) => + static String m15(name, planName) => "Пользователь ${name} оплатил план «${planName}»"; - static String m14(name, planName) => + static String m16(name, planName) => "Пользователь ${name} подписался на план «${planName}»"; - static String m15(planName) => "Вы отменили подписку на план «${planName}»"; + static String m17(planName) => "Вы отменили подписку на план «${planName}»"; final messages = _notInlinedMessages(_notInlinedMessages); static Map _notInlinedMessages(_) => { @@ -332,6 +338,7 @@ class MessageLookup extends MessageLookupByLibrary { ), "days": MessageLookupByLibrary.simpleMessage("дней"), "deception": MessageLookupByLibrary.simpleMessage("Обман"), + "default_user_name": MessageLookupByLibrary.simpleMessage("User"), "delete": MessageLookupByLibrary.simpleMessage("Удалить"), "deleteComment": MessageLookupByLibrary.simpleMessage( "Удалить комментарий", @@ -690,15 +697,17 @@ class MessageLookup extends MessageLookupByLibrary { "personalDietCreating": MessageLookupByLibrary.simpleMessage( "Составление индивидуальной диеты", ), - "personal_diet_duration_hint": m1, - "personal_diet_duration_mismatch": m2, + "personal_diet_defined_to_author": m1, + "personal_diet_defined_to_author_named": m2, + "personal_diet_duration_hint": m3, + "personal_diet_duration_mismatch": m4, "personal_diet_not_proposed": MessageLookupByLibrary.simpleMessage( "Personal diet not proposed", ), "personal_diet_proposed": MessageLookupByLibrary.simpleMessage( "Personal diet proposed", ), - "personal_diet_proposed_named": m3, + "personal_diet_proposed_named": m5, "personal_diet_replaces_tomorrow": MessageLookupByLibrary.simpleMessage( "The change takes effect tomorrow", ), @@ -718,18 +727,18 @@ class MessageLookup extends MessageLookupByLibrary { "Физическая форма", ), "place_of_living": MessageLookupByLibrary.simpleMessage("Место проживания"), - "planStarted": m4, + "planStarted": m6, "planWillBeConfirmedAfterThreeDays": MessageLookupByLibrary.simpleMessage( "Если вы не подтвердите, то план через три дня подтвердится автоматически", ), - "planWithUserStarted": m5, + "planWithUserStarted": m7, "plan_author": MessageLookupByLibrary.simpleMessage("Автор плана"), "plan_desc": MessageLookupByLibrary.simpleMessage("Описание плана"), "plan_desc_example": MessageLookupByLibrary.simpleMessage( "Большое подробное, привлекательное описание плана", ), "plan_duration": MessageLookupByLibrary.simpleMessage("Срок плана"), - "plan_duration_label": m6, + "plan_duration_label": m8, "plan_label_desc": MessageLookupByLibrary.simpleMessage( "План для поддержания формы", ), @@ -766,7 +775,7 @@ class MessageLookup extends MessageLookupByLibrary { "Promo code applied!", ), "promo_code": MessageLookupByLibrary.simpleMessage("Promo code"), - "promo_discount_hint": m7, + "promo_discount_hint": m9, "promo_invalid": MessageLookupByLibrary.simpleMessage( "Promo code not found or expired", ), @@ -887,13 +896,13 @@ class MessageLookup extends MessageLookupByLibrary { "Выбрана дата старта", ), "startDiet": MessageLookupByLibrary.simpleMessage("Начать диету"), - "start_date_label": m8, + "start_date_label": m10, "statistic": MessageLookupByLibrary.simpleMessage("Статистика"), "step": MessageLookupByLibrary.simpleMessage("Шаг"), "step_by_step_photo_recipe": MessageLookupByLibrary.simpleMessage( "Пошаговый фоторецепт", ), - "step_widget": m9, + "step_widget": m11, "successfully_published": MessageLookupByLibrary.simpleMessage( "успешно опубликован", ), @@ -918,8 +927,8 @@ class MessageLookup extends MessageLookupByLibrary { "toOffer": MessageLookupByLibrary.simpleMessage("Предложить"), "to_draft": MessageLookupByLibrary.simpleMessage("В черновик"), "to_order": MessageLookupByLibrary.simpleMessage("Заказать"), - "tommorowPlanWithUserWillStart": m10, - "tomorrowYourPlanWillStart": m11, + "tommorowPlanWithUserWillStart": m12, + "tomorrowYourPlanWillStart": m13, "try_again": MessageLookupByLibrary.simpleMessage("Попробовать снова"), "try_again_2": MessageLookupByLibrary.simpleMessage("Попробуйте ещё раз"), "typeAmoutOfReturn": MessageLookupByLibrary.simpleMessage( @@ -953,7 +962,7 @@ class MessageLookup extends MessageLookupByLibrary { "Верхние показатели давления:", ), "upper": MessageLookupByLibrary.simpleMessage("Верхнее"), - "userCanceldThePlanSubscription": m12, + "userCanceldThePlanSubscription": m14, "userConfirmedPlanCompletion": MessageLookupByLibrary.simpleMessage( "Пользователь подтвердил прохождения плана. В ближайшее время Вы получите", ), @@ -961,8 +970,8 @@ class MessageLookup extends MessageLookupByLibrary { MessageLookupByLibrary.simpleMessage( "Пользователь подтвердил прохождения плана.", ), - "userPaidThePlan": m13, - "userSubscribedToPlan": m14, + "userPaidThePlan": m15, + "userSubscribedToPlan": m16, "user_authorization": MessageLookupByLibrary.simpleMessage( "Аутентификация", ), @@ -1092,7 +1101,7 @@ class MessageLookup extends MessageLookupByLibrary { "youCanComplain": MessageLookupByLibrary.simpleMessage( "Если вас что-то не устроило, вы можете подать жалобу", ), - "youCanceledSubscriptionToPlan": m15, + "youCanceledSubscriptionToPlan": m17, "youShureYouWantToCancelOrder": MessageLookupByLibrary.simpleMessage( "Вы уверены, что хотите отменить заказ?", ), diff --git a/lib/generated/intl/messages_ru.dart b/lib/generated/intl/messages_ru.dart index a591ebbd..5f6457d6 100644 --- a/lib/generated/intl/messages_ru.dart +++ b/lib/generated/intl/messages_ru.dart @@ -20,20 +20,26 @@ typedef String MessageIfAbsent(String messageStr, List args); class MessageLookup extends MessageLookupByLibrary { String get localeName => 'ru'; - static String m1(duration, dayWord) => + static String m1(userName) => + "Вы предложили персональную диету пользователю ${userName}"; + + static String m2(userName, dietName) => + "Вы предложили персональную диету пользователю ${userName}, выбранная диета: «${dietName}»"; + + static String m3(duration, dayWord) => "Диета рассчитана на ${duration} ${dayWord}. Предложить её можно только для плана с такой же длительностью."; - static String m2(dietDuration, dietDayWord, planDuration, planDayWord) => + static String m4(dietDuration, dietDayWord, planDuration, planDayWord) => "Не подходит: диета на ${dietDuration} ${dietDayWord}, план на ${planDuration} ${planDayWord}."; - static String m3(name) => "Диета «${name}» предложена"; + static String m5(name) => "Диета «${name}» предложена"; - static String m6(duration, dayWord) => "План на ${duration} ${dayWord}"; + static String m8(duration, dayWord) => "План на ${duration} ${dayWord}"; - static String m7(percent, amount) => + static String m9(percent, amount) => "Скидка ${percent}% — вы экономите ${amount} ₽"; - static String m8(date) => "Старт: ${date}"; + static String m10(date) => "Старт: ${date}"; final messages = _notInlinedMessages(_notInlinedMessages); static Map _notInlinedMessages(_) => { @@ -130,6 +136,7 @@ class MessageLookup extends MessageLookupByLibrary { "date_of_birth": MessageLookupByLibrary.simpleMessage("Дата рождения"), "day": MessageLookupByLibrary.simpleMessage("День"), "days": MessageLookupByLibrary.simpleMessage("дней"), + "default_user_name": MessageLookupByLibrary.simpleMessage("Пользователь"), "deleted": MessageLookupByLibrary.simpleMessage("Удалена"), "diary": MessageLookupByLibrary.simpleMessage("Дневник"), "diet": MessageLookupByLibrary.simpleMessage("Диета"), @@ -334,15 +341,17 @@ 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_defined_to_author": m1, + "personal_diet_defined_to_author_named": m2, + "personal_diet_duration_hint": m3, + "personal_diet_duration_mismatch": m4, "personal_diet_not_proposed": MessageLookupByLibrary.simpleMessage( "Диета не предложена", ), "personal_diet_proposed": MessageLookupByLibrary.simpleMessage( "Диета предложена", ), - "personal_diet_proposed_named": m3, + "personal_diet_proposed_named": m5, "personal_diet_replaces_tomorrow": MessageLookupByLibrary.simpleMessage( "Замена действует со следующего дня", ), @@ -358,7 +367,7 @@ class MessageLookup extends MessageLookupByLibrary { "Большое подробное, привлекательное описание плана", ), "plan_duration": MessageLookupByLibrary.simpleMessage("Срок плана"), - "plan_duration_label": m6, + "plan_duration_label": m8, "plan_label_desc": MessageLookupByLibrary.simpleMessage( "План для поддержания формы", ), @@ -386,7 +395,7 @@ class MessageLookup extends MessageLookupByLibrary { "Промокод применён!", ), "promo_code": MessageLookupByLibrary.simpleMessage("Промокод"), - "promo_discount_hint": m7, + "promo_discount_hint": m9, "promo_invalid": MessageLookupByLibrary.simpleMessage( "Промокод не найден или истёк", ), @@ -447,7 +456,7 @@ class MessageLookup extends MessageLookupByLibrary { "Выбрана дата старта", ), "startDiet": MessageLookupByLibrary.simpleMessage("Начать диету"), - "start_date_label": m8, + "start_date_label": m10, "suggestDiet": MessageLookupByLibrary.simpleMessage("Предложить диету"), "tell_your_schedule": MessageLookupByLibrary.simpleMessage( "Расскажите в свободной форме о том как просыпаетесь, когда едите, когда ложитесь спать:", diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index 5f333859..fc12f142 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -4584,6 +4584,34 @@ class S { ); } + /// `User` + String get default_user_name { + return Intl.message('User', name: 'default_user_name', desc: '', args: []); + } + + /// `You have proposed a personal diet to {userName}` + String personal_diet_defined_to_author(String userName) { + return Intl.message( + 'You have proposed a personal diet to $userName', + name: 'personal_diet_defined_to_author', + desc: '', + args: [userName], + ); + } + + /// `You have proposed a personal diet to {userName}, selected diet: «{dietName}»` + String personal_diet_defined_to_author_named( + String userName, + String dietName, + ) { + return Intl.message( + 'You have proposed a personal diet to $userName, selected diet: «$dietName»', + name: 'personal_diet_defined_to_author_named', + desc: '', + args: [userName, dietName], + ); + } + /// `Personal diet not proposed` String get personal_diet_not_proposed { return Intl.message( diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 4249132f..becf3334 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -546,6 +546,20 @@ "name": {"type": "String"} } }, + "default_user_name": "User", + "personal_diet_defined_to_author": "You have proposed a personal diet to {userName}", + "@personal_diet_defined_to_author": { + "placeholders": { + "userName": {"type": "String"} + } + }, + "personal_diet_defined_to_author_named": "You have proposed a personal diet to {userName}, selected diet: «{dietName}»", + "@personal_diet_defined_to_author_named": { + "placeholders": { + "userName": {"type": "String"}, + "dietName": {"type": "String"} + } + }, "personal_diet_not_proposed": "Personal diet not proposed", "change_personal_diet": "Change personal diet", "personal_diet_replaces_tomorrow": "The change takes effect tomorrow", diff --git a/lib/l10n/intl_ru.arb b/lib/l10n/intl_ru.arb index 17c31301..298a587a 100644 --- a/lib/l10n/intl_ru.arb +++ b/lib/l10n/intl_ru.arb @@ -301,6 +301,20 @@ "name": {"type": "String"} } }, + "default_user_name": "Пользователь", + "personal_diet_defined_to_author": "Вы предложили персональную диету пользователю {userName}", + "@personal_diet_defined_to_author": { + "placeholders": { + "userName": {"type": "String"} + } + }, + "personal_diet_defined_to_author_named": "Вы предложили персональную диету пользователю {userName}, выбранная диета: «{dietName}»", + "@personal_diet_defined_to_author_named": { + "placeholders": { + "userName": {"type": "String"}, + "dietName": {"type": "String"} + } + }, "personal_diet_not_proposed": "Диета не предложена", "change_personal_diet": "Заменить диету", "personal_diet_replaces_tomorrow": "Замена действует со следующего дня", diff --git a/test/features/notifications/presentation/widgets/notification_widget_test.dart b/test/features/notifications/presentation/widgets/notification_widget_test.dart index fdb04862..24d6ec92 100644 --- a/test/features/notifications/presentation/widgets/notification_widget_test.dart +++ b/test/features/notifications/presentation/widgets/notification_widget_test.dart @@ -1233,10 +1233,68 @@ void main() { await tester.pumpWidget(createTestWidget(notification)); await tester.pumpAndSettle(); - expect(find.textContaining('Вы предложили персональную диету пользователю Client'), findsOneWidget); - expect(find.textContaining('Test Diet'), findsOneWidget); + expect( + find.text('Вы предложили персональную диету пользователю Client, выбранная диета: «Test Diet»'), + findsOneWidget, + ); }); + testWidgets( + 'displays PersonalDietIsDefinedToAuthorNotification with fallback user name', + (tester) async { + final notification = PersonalDietIsDefinedToAuthorNotification( + type: NotificationType.personalDietIsDefinedToAuthor, + isRead: false, + createdAt: testDate, + chosenPlanId: 1, + dietId: 1, + planName: 'Plan', + userName: '', + consultantName: 'Consultant', + dietName: 'Test Diet', + role: 'consultant', + peerSlug: 'client-slug', + peerImagePath: '', + ); + + await tester.pumpWidget(createTestWidget(notification)); + await tester.pumpAndSettle(); + + expect( + find.text('Вы предложили персональную диету пользователю Пользователь, выбранная диета: «Test Diet»'), + findsOneWidget, + ); + }, + ); + + testWidgets( + 'displays PersonalDietIsDefinedToAuthorNotification without diet name', + (tester) async { + final notification = PersonalDietIsDefinedToAuthorNotification( + type: NotificationType.personalDietIsDefinedToAuthor, + isRead: false, + createdAt: testDate, + chosenPlanId: 1, + dietId: 1, + planName: 'Plan', + userName: 'Client', + consultantName: 'Consultant', + dietName: '', + role: 'consultant', + peerSlug: 'client-slug', + peerImagePath: '', + ); + + await tester.pumpWidget(createTestWidget(notification)); + await tester.pumpAndSettle(); + + expect( + find.text('Вы предложили персональную диету пользователю Client'), + findsOneWidget, + ); + }, + ); + testWidgets('displays UnknownNotification', (tester) async { final notification = UnknownNotification( type: NotificationType.unknown, diff --git a/test/features/plans/models/chosen_plan_model_test.dart b/test/features/plans/models/chosen_plan_model_test.dart index 5f53ba22..8dfee56b 100644 --- a/test/features/plans/models/chosen_plan_model_test.dart +++ b/test/features/plans/models/chosen_plan_model_test.dart @@ -200,6 +200,66 @@ void main() { }); }); + group('chosenOption', () { + const plan = PlanModel( + id: 1, + slug: 'test-plan', + name: 'Test Plan', + image: 'https://example.com/image.jpg', + duration: 7, + state: 'active', + type: PlanType(fit: true, slim: false, behavior: false, wellness: false), + details: 'Test details', + packetsCount: 3, + packet1Options: PacketOptions(items: ['one'], price: 100, short: 'packet-1', hasPersonalDiet: false), + packet2Options: PacketOptions(items: ['two'], price: 200, short: 'packet-2', hasPersonalDiet: true), + packet3Options: PacketOptions(items: ['three'], price: 300, short: 'packet-3', hasPersonalDiet: false), + author: Author( + authorSlug: 'author', + authorName: 'Author Name', + authorProfileIcon: 'https://example.com/icon.jpg', + authorIsMe: false, + isEntitySubscribedByMe: null, + authorPlaceInRating: null, + ), + totalLikes: 10, + totalViews: 100, + totalComments: 5, + isFavorite: false, + minPriceOfOptions: 100, + maxPriceOfOptions: 300, + wasLikedByMe: false, + ); + + ChosenPlanModel modelWith(String optionType) => ChosenPlanModel( + id: 1, + optionType: optionType, + startDate: DateTime(2024, 1, 1), + chosenPlanState: ChosenPlanStateEnum.stateInited, + chatId: 'chat-1', + consultantId: 1, + plan: plan, + ); + + test('возвращает первую опцию для options1', () { + expect(modelWith('options1').chosenOption?.short, 'packet-1'); + }); + + test('возвращает вторую опцию для options2', () { + expect(modelWith('options2').chosenOption?.short, 'packet-2'); + }); + + test('возвращает третью опцию для options3', () { + expect(modelWith('options3').chosenOption?.short, 'packet-3'); + }); + + test('возвращает null для неизвестного значения', () { + expect(modelWith('unknown').chosenOption, isNull); + expect(modelWith('1').chosenOption, isNull); + expect(modelWith('').chosenOption, isNull); + }); + }); + group('parseChosenPlan', () { test('parseChosenPlan создает ChosenPlanModel из Map', () { final json = {