forked from eatvio/eatvio_app
Compare commits
11 Commits
issue-1140
...
issue-851
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
65219bce77 | ||
|
|
ad122ed2f7 | ||
| 8a8a01721e | |||
| 61b77bfaec | |||
| 78192b742d | |||
| ca59186e63 | |||
| 608016c8ad | |||
| 0df474b2b5 | |||
| 23f24c0be0 | |||
| 66d7028d0f | |||
| 0c66994644 |
@@ -183,7 +183,10 @@ class CubitRegistrations {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
sl.registerFactory<profile_plans.PlansCubit>(
|
sl.registerFactory<profile_plans.PlansCubit>(
|
||||||
() => profile_plans.PlansCubit(plansRepository: sl()),
|
() => profile_plans.PlansCubit(
|
||||||
|
plansRepository: sl(),
|
||||||
|
planRepository: sl(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
sl.registerFactory<SubCubit>(() => SubCubit(profileRepository: sl()));
|
sl.registerFactory<SubCubit>(() => SubCubit(profileRepository: sl()));
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ class CustomPopup extends StatelessWidget {
|
|||||||
final PlanModel? plan;
|
final PlanModel? plan;
|
||||||
final String userSlug;
|
final String userSlug;
|
||||||
final VoidCallback? onPostsChanged;
|
final VoidCallback? onPostsChanged;
|
||||||
|
final VoidCallback? onPlanChanged;
|
||||||
|
|
||||||
const CustomPopup({
|
const CustomPopup({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -59,6 +60,7 @@ class CustomPopup extends StatelessWidget {
|
|||||||
this.plan,
|
this.plan,
|
||||||
required this.userSlug,
|
required this.userSlug,
|
||||||
this.onPostsChanged,
|
this.onPostsChanged,
|
||||||
|
this.onPlanChanged,
|
||||||
});
|
});
|
||||||
|
|
||||||
bool get _isAdminAuthor =>
|
bool get _isAdminAuthor =>
|
||||||
@@ -166,9 +168,13 @@ class CustomPopup extends StatelessWidget {
|
|||||||
try {
|
try {
|
||||||
context.read<AboutPlanCubit>().getPlan(slug: currentPlan.slug);
|
context.read<AboutPlanCubit>().getPlan(slug: currentPlan.slug);
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
try {
|
if (onPlanChanged != null) {
|
||||||
context.read<PlansCubit>().loadPlans();
|
onPlanChanged!();
|
||||||
} catch (_) {}
|
} else {
|
||||||
|
try {
|
||||||
|
context.read<PlansCubit>().loadPlans();
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
context.read<MyPlansCubit>().loadPlans();
|
context.read<MyPlansCubit>().loadPlans();
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
|
|||||||
@@ -122,7 +122,10 @@ class _DiaryScreenContentState extends State<DiaryScreenContent> {
|
|||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
),
|
),
|
||||||
body: SingleChildScrollView(
|
body: SingleChildScrollView(
|
||||||
padding: const EdgeInsets.only(bottom: 16, top: 8),
|
padding: EdgeInsets.only(
|
||||||
|
bottom: 16,
|
||||||
|
top: widget.diaryId == null ? 0 : 8,
|
||||||
|
),
|
||||||
physics: const BouncingScrollPhysics(),
|
physics: const BouncingScrollPhysics(),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
@@ -133,7 +136,12 @@ class _DiaryScreenContentState extends State<DiaryScreenContent> {
|
|||||||
],
|
],
|
||||||
if (state is DiaryStateLoaded && _canShowInsights(state))
|
if (state is DiaryStateLoaded && _canShowInsights(state))
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(4, 12, 4, 12),
|
padding: EdgeInsets.fromLTRB(
|
||||||
|
4,
|
||||||
|
widget.diaryId == null ? 0 : 12,
|
||||||
|
4,
|
||||||
|
12,
|
||||||
|
),
|
||||||
child: _DiaryInsights(
|
child: _DiaryInsights(
|
||||||
slug: state.isConsultantView ? _ownerSlug(state) : null,
|
slug: state.isConsultantView ? _ownerSlug(state) : null,
|
||||||
canAdd: !state.isConsultantView,
|
canAdd: !state.isConsultantView,
|
||||||
@@ -325,6 +333,7 @@ class _DiaryInsightsState extends State<_DiaryInsights> {
|
|||||||
canAdd: widget.canAdd,
|
canAdd: widget.canAdd,
|
||||||
refreshToken: _refreshToken,
|
refreshToken: _refreshToken,
|
||||||
initialIntraDate: widget.diaryDate,
|
initialIntraDate: widget.diaryDate,
|
||||||
|
showShadow: false,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ import 'package:eatvio_app/core/widgets/show_error_dialog.dart';
|
|||||||
import 'package:eatvio_app/features/diary/presentation/bloc/diary_cubit.dart';
|
import 'package:eatvio_app/features/diary/presentation/bloc/diary_cubit.dart';
|
||||||
import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart';
|
import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart';
|
||||||
import 'package:eatvio_app/generated/l10n.dart';
|
import 'package:eatvio_app/generated/l10n.dart';
|
||||||
import 'package:material_ui/material_ui.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:table_calendar/table_calendar.dart';
|
import 'package:table_calendar/table_calendar.dart';
|
||||||
|
|
||||||
class CalendarWidget extends StatefulWidget {
|
class CalendarWidget extends StatefulWidget {
|
||||||
@@ -15,13 +17,21 @@ class CalendarWidget extends StatefulWidget {
|
|||||||
State<CalendarWidget> createState() => _CalendarWidgetState();
|
State<CalendarWidget> createState() => _CalendarWidgetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CalendarWidgetState extends State<CalendarWidget> {
|
class _CalendarWidgetState extends State<CalendarWidget>
|
||||||
|
with SingleTickerProviderStateMixin {
|
||||||
|
static const _locale = 'ru_RU';
|
||||||
static const _kDaysOfWeekHeight = 16.0;
|
static const _kDaysOfWeekHeight = 16.0;
|
||||||
static const _kRowHeight = 52.0;
|
static const _kRowHeight = 52.0;
|
||||||
|
static const _dayCellMargin = 6.0;
|
||||||
|
static const _dragHandlePadding = 5.0;
|
||||||
|
|
||||||
CalendarFormat _calendarFormat = CalendarFormat.week;
|
late final _expansion = AnimationController(
|
||||||
|
vsync: this,
|
||||||
|
duration: const Duration(milliseconds: 180),
|
||||||
|
);
|
||||||
DateTime _focusedDay = DateTime.now();
|
DateTime _focusedDay = DateTime.now();
|
||||||
DateTime _selectedDay = DateTime.now();
|
DateTime _selectedDay = DateTime.now();
|
||||||
|
|
||||||
DateTime? _dayFromState(DiaryState state) {
|
DateTime? _dayFromState(DiaryState state) {
|
||||||
if (state is DiaryStateLoaded) {
|
if (state is DiaryStateLoaded) {
|
||||||
return state.selectedDay;
|
return state.selectedDay;
|
||||||
@@ -35,11 +45,9 @@ class _CalendarWidgetState extends State<CalendarWidget> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
final selected = _dayFromState(context.read<DiaryCubit>().state);
|
final selected =
|
||||||
if (widget.date != null) {
|
widget.date ?? _dayFromState(context.read<DiaryCubit>().state);
|
||||||
_selectedDay = widget.date!;
|
if (selected != null) {
|
||||||
_focusedDay = widget.date!;
|
|
||||||
} else if (selected != null) {
|
|
||||||
_selectedDay = selected;
|
_selectedDay = selected;
|
||||||
_focusedDay = selected;
|
_focusedDay = selected;
|
||||||
}
|
}
|
||||||
@@ -54,13 +62,30 @@ class _CalendarWidgetState extends State<CalendarWidget> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_expansion.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final s = S.of(context);
|
final rowHeight = MediaQuery.textScalerOf(context).scale(_kRowHeight);
|
||||||
final textScaler = MediaQuery.textScalerOf(context);
|
final firstOfMonth = DateTime.utc(_focusedDay.year, _focusedDay.month);
|
||||||
final daysOfWeekHeight = _scaledDaysOfWeekHeight(context);
|
final daysInMonth = DateTime.utc(
|
||||||
return BlocConsumer<DiaryCubit, DiaryState>(
|
_focusedDay.year,
|
||||||
listener: (BuildContext context, DiaryState state) {
|
_focusedDay.month + 1,
|
||||||
|
0,
|
||||||
|
).day;
|
||||||
|
final daysBeforeMonth = firstOfMonth.weekday - DateTime.monday;
|
||||||
|
final weekCount = (daysBeforeMonth + daysInMonth + 6) ~/ 7;
|
||||||
|
final focusedWeek = (daysBeforeMonth + _focusedDay.day - 1) ~/ 7;
|
||||||
|
final extraHeight = (weekCount - 1) * rowHeight;
|
||||||
|
final week = _buildDays(rowHeight, CalendarFormat.week);
|
||||||
|
final month = _buildDays(rowHeight, CalendarFormat.month);
|
||||||
|
|
||||||
|
return BlocListener<DiaryCubit, DiaryState>(
|
||||||
|
listener: (context, state) {
|
||||||
final selected = _dayFromState(state);
|
final selected = _dayFromState(state);
|
||||||
if (selected != null) {
|
if (selected != null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -69,80 +94,167 @@ class _CalendarWidgetState extends State<CalendarWidget> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
builder: (BuildContext context, DiaryState state) {
|
child: Padding(
|
||||||
return Column(
|
padding: const EdgeInsets.only(top: 4),
|
||||||
mainAxisSize: MainAxisSize.min,
|
child: AnimatedBuilder(
|
||||||
children: [
|
animation: _expansion,
|
||||||
Padding(
|
child: _buildWeekdays(context),
|
||||||
padding: const EdgeInsets.only(top: 16),
|
builder: (context, weekdays) {
|
||||||
child: TableCalendar(
|
return Column(
|
||||||
focusedDay: _focusedDay,
|
mainAxisSize: MainAxisSize.min,
|
||||||
firstDay: DateTime.utc(2020, 10, 16),
|
children: [
|
||||||
lastDay: DateTime.utc(2030, 3, 14),
|
_buildHeader(context),
|
||||||
locale: 'ru_RU',
|
weekdays!,
|
||||||
startingDayOfWeek: StartingDayOfWeek.monday,
|
ClipRect(
|
||||||
calendarFormat: _calendarFormat,
|
child: SizedBox(
|
||||||
daysOfWeekHeight: daysOfWeekHeight,
|
height: rowHeight + extraHeight * _expansion.value,
|
||||||
rowHeight: textScaler.scale(_kRowHeight),
|
child: OverflowBox(
|
||||||
headerStyle: const HeaderStyle(titleCentered: true, formatButtonVisible: false, leftChevronVisible: false, rightChevronVisible: false),
|
// При раскрытии показываем строки вокруг открытой недели.
|
||||||
onDaySelected: (selectedDay, focusedDay) async {
|
alignment: Alignment(
|
||||||
if (!isSameDay(_selectedDay, selectedDay)) {
|
0,
|
||||||
final previousSelectedDay = _selectedDay;
|
2 * focusedWeek / (weekCount - 1) - 1,
|
||||||
final previousFocusedDay = _selectedDay;
|
),
|
||||||
setState(() {
|
minHeight: 0,
|
||||||
_selectedDay = selectedDay;
|
maxHeight: double.infinity,
|
||||||
_focusedDay = focusedDay;
|
child: _expansion.value == 0 ? week : month,
|
||||||
});
|
),
|
||||||
final cubit = context.read<DiaryCubit>();
|
|
||||||
final canOpenNextDay = await cubit.setSelectedDay(selectedDay);
|
|
||||||
if (!context.mounted || cubit.state is DiaryStateError) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!canOpenNextDay) {
|
|
||||||
showErrorDialog(context, title: s.want_to_see_tomorrow, description: s.can_not_see_next_day);
|
|
||||||
setState(() {
|
|
||||||
_selectedDay = previousSelectedDay;
|
|
||||||
_focusedDay = previousFocusedDay;
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
selectedDayPredicate: (day) {
|
|
||||||
return isSameDay(_selectedDay, day);
|
|
||||||
},
|
|
||||||
onPageChanged: (focusedDay) {
|
|
||||||
setState(() {
|
|
||||||
_focusedDay = focusedDay;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onFormatChanged: (format) {
|
|
||||||
if (_calendarFormat != format) {
|
|
||||||
setState(() {
|
|
||||||
_calendarFormat = format;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
calendarStyle: CalendarStyle(
|
|
||||||
weekendDecoration: const BoxDecoration(color: Colors.white, shape: BoxShape.circle),
|
|
||||||
defaultDecoration: const BoxDecoration(color: Colors.white, shape: BoxShape.circle),
|
|
||||||
selectedDecoration: BoxDecoration(color: appTheme.blueA400, shape: BoxShape.circle),
|
|
||||||
todayTextStyle: const TextStyle(color: Colors.black),
|
|
||||||
todayDecoration: BoxDecoration(
|
|
||||||
border: Border.all(color: appTheme.blueA400, width: 2),
|
|
||||||
color: Colors.white,
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
_buildDragHandle(extraHeight),
|
||||||
),
|
],
|
||||||
_arrowDown(),
|
);
|
||||||
],
|
},
|
||||||
);
|
),
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildHeader(BuildContext context) {
|
||||||
|
final s = S.of(context);
|
||||||
|
final expanded = _expansion.value >= 0.5;
|
||||||
|
final label = DateFormat.yMMMM(_locale).format(_focusedDay);
|
||||||
|
|
||||||
|
return Tooltip(
|
||||||
|
message: expanded ? s.hide : s.expand,
|
||||||
|
child: InkWell(
|
||||||
|
onTap: () => _expansion.value = expanded ? 0 : 1,
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(label, style: const HeaderStyle().titleTextStyle),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Icon(
|
||||||
|
expanded
|
||||||
|
? Icons.keyboard_arrow_up_rounded
|
||||||
|
: Icons.keyboard_arrow_down_rounded,
|
||||||
|
size: 18,
|
||||||
|
color: appTheme.blueA400,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildWeekdays(BuildContext context) {
|
||||||
|
const style = DaysOfWeekStyle();
|
||||||
|
final format = DateFormat.E(_locale);
|
||||||
|
|
||||||
|
return ExcludeSemantics(
|
||||||
|
child: SizedBox(
|
||||||
|
height: _scaledDaysOfWeekHeight(context),
|
||||||
|
child: Row(
|
||||||
|
children: List.generate(DateTime.daysPerWeek, (index) {
|
||||||
|
final day = DateTime.utc(
|
||||||
|
_focusedDay.year,
|
||||||
|
_focusedDay.month,
|
||||||
|
_focusedDay.day - _focusedDay.weekday + DateTime.monday + index,
|
||||||
|
);
|
||||||
|
return Expanded(
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
format.format(day),
|
||||||
|
style: day.weekday >= DateTime.saturday
|
||||||
|
? style.weekendStyle
|
||||||
|
: style.weekdayStyle,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildDays(double rowHeight, CalendarFormat format) {
|
||||||
|
return TableCalendar(
|
||||||
|
key: ValueKey(format),
|
||||||
|
focusedDay: _focusedDay,
|
||||||
|
firstDay: DateTime.utc(2020, 10, 16),
|
||||||
|
lastDay: DateTime.utc(2030, 3, 14),
|
||||||
|
locale: _locale,
|
||||||
|
startingDayOfWeek: StartingDayOfWeek.monday,
|
||||||
|
calendarFormat: format,
|
||||||
|
availableGestures: AvailableGestures.horizontalSwipe,
|
||||||
|
headerVisible: false,
|
||||||
|
daysOfWeekVisible: false,
|
||||||
|
rowHeight: rowHeight,
|
||||||
|
onDaySelected: _selectDay,
|
||||||
|
selectedDayPredicate: (day) => isSameDay(_selectedDay, day),
|
||||||
|
onPageChanged: (focusedDay) => setState(() => _focusedDay = focusedDay),
|
||||||
|
calendarStyle: CalendarStyle(
|
||||||
|
cellMargin: const EdgeInsets.all(_dayCellMargin),
|
||||||
|
weekendDecoration: const BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
defaultDecoration: const BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
selectedDecoration: BoxDecoration(
|
||||||
|
color: appTheme.blueA400,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
todayTextStyle: const TextStyle(color: Colors.black),
|
||||||
|
todayDecoration: BoxDecoration(
|
||||||
|
border: Border.all(color: appTheme.blueA400, width: 2),
|
||||||
|
color: Colors.white,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _selectDay(DateTime selectedDay, DateTime focusedDay) async {
|
||||||
|
if (isSameDay(_selectedDay, selectedDay)) return;
|
||||||
|
|
||||||
|
final previousSelectedDay = _selectedDay;
|
||||||
|
final previousFocusedDay = _focusedDay;
|
||||||
|
setState(() {
|
||||||
|
_selectedDay = selectedDay;
|
||||||
|
_focusedDay = focusedDay;
|
||||||
|
});
|
||||||
|
final cubit = context.read<DiaryCubit>();
|
||||||
|
final canOpenNextDay = await cubit.setSelectedDay(selectedDay);
|
||||||
|
if (!mounted || cubit.state is DiaryStateError || canOpenNextDay) return;
|
||||||
|
|
||||||
|
final s = S.of(context);
|
||||||
|
showErrorDialog(
|
||||||
|
context,
|
||||||
|
title: s.want_to_see_tomorrow,
|
||||||
|
description: s.can_not_see_next_day,
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
_selectedDay = previousSelectedDay;
|
||||||
|
_focusedDay = previousFocusedDay;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
double _scaledDaysOfWeekHeight(BuildContext context) {
|
double _scaledDaysOfWeekHeight(BuildContext context) {
|
||||||
final painter = TextPainter(
|
final painter = TextPainter(
|
||||||
text: TextSpan(text: 'Щy', style: DefaultTextStyle.of(context).style),
|
text: TextSpan(text: 'Щy', style: DefaultTextStyle.of(context).style),
|
||||||
@@ -155,26 +267,44 @@ class _CalendarWidgetState extends State<CalendarWidget> {
|
|||||||
return height.clamp(_kDaysOfWeekHeight, double.infinity);
|
return height.clamp(_kDaysOfWeekHeight, double.infinity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _nextCalendarFormat() {
|
Widget _buildDragHandle(double extraHeight) {
|
||||||
setState(() {
|
|
||||||
_calendarFormat = CalendarFormat.values[(_calendarFormat.index - 1) % CalendarFormat.values.length];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
GestureDetector _arrowDown() {
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
behavior: HitTestBehavior.translucent,
|
behavior: HitTestBehavior.opaque,
|
||||||
onVerticalDragStart: (_) {
|
dragStartBehavior: DragStartBehavior.down,
|
||||||
_nextCalendarFormat();
|
onVerticalDragStart: (_) => _expansion.stop(),
|
||||||
|
onVerticalDragUpdate: (details) {
|
||||||
|
_expansion.value = (_expansion.value + details.delta.dy / extraHeight)
|
||||||
|
.clamp(0.0, 1.0);
|
||||||
},
|
},
|
||||||
onTap: () {
|
onVerticalDragEnd: (details) =>
|
||||||
_nextCalendarFormat();
|
_settleExpansion(details.velocity.pixelsPerSecond.dy),
|
||||||
},
|
onVerticalDragCancel: _settleExpansion,
|
||||||
child: Container(
|
child: SizedBox(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
padding: const EdgeInsets.only(top: 8, bottom: 16),
|
child: Padding(
|
||||||
child: Icon(_calendarFormat == CalendarFormat.month ? Icons.keyboard_arrow_up_rounded : Icons.keyboard_arrow_down_rounded, color: Colors.grey.shade600),
|
// Отступ ячеек уже добавляет место над полоской.
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
top: _dragHandlePadding,
|
||||||
|
bottom: _dragHandlePadding + _dayCellMargin,
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: DecoratedBox(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: appTheme.blueA400,
|
||||||
|
borderRadius: BorderRadius.circular(2),
|
||||||
|
),
|
||||||
|
child: const SizedBox(width: 28, height: 4),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _settleExpansion([double velocity = 0]) {
|
||||||
|
final shouldExpand = velocity.abs() >= 400
|
||||||
|
? velocity > 0
|
||||||
|
: _expansion.value >= 0.5;
|
||||||
|
_expansion.animateTo(shouldExpand ? 1 : 0, curve: Curves.easeOutCubic);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import 'package:eatvio_app/core/utils/url_utils.dart';
|
|||||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||||
import 'package:eatvio_app/features/user_details/presentation/user_details_screen.dart';
|
import 'package:eatvio_app/features/user_details/presentation/user_details_screen.dart';
|
||||||
|
import 'package:eatvio_app/generated/l10n.dart';
|
||||||
import 'package:material_ui/material_ui.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:flutter_svg/svg.dart';
|
import 'package:flutter_svg/svg.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
@@ -107,7 +108,9 @@ class AuthorCard extends StatelessWidget {
|
|||||||
backgroundColor: appTheme.cardBackground,
|
backgroundColor: appTheme.cardBackground,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
'${author.authorPlaceInRating}-й в рейтинге',
|
S.of(context).rating_place(
|
||||||
|
author.authorPlaceInRating!,
|
||||||
|
),
|
||||||
style: TextStyles.textMMediumAuto.copyWith(
|
style: TextStyles.textMMediumAuto.copyWith(
|
||||||
color: appTheme.blueA400,
|
color: appTheme.blueA400,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -66,11 +66,13 @@ class LikesState extends Equatable {
|
|||||||
final bool wasLikedByMe;
|
final bool wasLikedByMe;
|
||||||
final int totalLikes;
|
final int totalLikes;
|
||||||
final int index;
|
final int index;
|
||||||
|
final String? slug;
|
||||||
|
|
||||||
const LikesState({
|
const LikesState({
|
||||||
required this.wasLikedByMe,
|
required this.wasLikedByMe,
|
||||||
required this.totalLikes,
|
required this.totalLikes,
|
||||||
required this.index,
|
required this.index,
|
||||||
|
this.slug,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -78,37 +80,44 @@ class LikesState extends Equatable {
|
|||||||
wasLikedByMe,
|
wasLikedByMe,
|
||||||
totalLikes,
|
totalLikes,
|
||||||
index,
|
index,
|
||||||
|
slug,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
class FavoriteState extends Equatable {
|
class FavoriteState extends Equatable {
|
||||||
final bool isFavorite;
|
final bool isFavorite;
|
||||||
final int index;
|
final int index;
|
||||||
|
final String? slug;
|
||||||
|
|
||||||
const FavoriteState({
|
const FavoriteState({
|
||||||
required this.isFavorite,
|
required this.isFavorite,
|
||||||
required this.index,
|
required this.index,
|
||||||
|
this.slug,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [
|
List<Object?> get props => [
|
||||||
isFavorite,
|
isFavorite,
|
||||||
index,
|
index,
|
||||||
|
slug,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
class CommentsState extends Equatable {
|
class CommentsState extends Equatable {
|
||||||
final int index;
|
final int index;
|
||||||
final int totalComments;
|
final int totalComments;
|
||||||
|
final String? slug;
|
||||||
|
|
||||||
const CommentsState({
|
const CommentsState({
|
||||||
required this.index,
|
required this.index,
|
||||||
required this.totalComments,
|
required this.totalComments,
|
||||||
|
this.slug,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [
|
List<Object?> get props => [
|
||||||
index,
|
index,
|
||||||
totalComments,
|
totalComments,
|
||||||
|
slug,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import 'package:easy_debounce/easy_debounce.dart';
|
|||||||
import 'package:eatvio_app/core/const.dart';
|
import 'package:eatvio_app/core/const.dart';
|
||||||
import 'package:eatvio_app/core/utils/toasts.dart';
|
import 'package:eatvio_app/core/utils/toasts.dart';
|
||||||
import 'package:eatvio_app/features/diets/repositories/diet_repository.dart';
|
import 'package:eatvio_app/features/diets/repositories/diet_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
|
||||||
import 'package:eatvio_app/features/feed/presentation/bloc/plans_cubit/plans_state.dart';
|
import 'package:eatvio_app/features/feed/presentation/bloc/plans_cubit/plans_state.dart';
|
||||||
import 'package:eatvio_app/features/feed/repositories/feed_repository.dart';
|
import 'package:eatvio_app/features/feed/repositories/feed_repository.dart';
|
||||||
import 'package:eatvio_app/features/plans/repositories/plan_repository.dart';
|
import 'package:eatvio_app/features/plans/repositories/plan_repository.dart';
|
||||||
@@ -87,57 +88,51 @@ class PlansCubit extends Cubit<PlansState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _changePlanLikeState(LikesState likesState) {
|
void _changePlanLikeState(LikesState likesState) {
|
||||||
final currentPlans = state.plans;
|
_updatePlanAt(
|
||||||
final plansForModification = [...currentPlans];
|
slug: likesState.slug,
|
||||||
final currentPlan = currentPlans[likesState.index];
|
index: likesState.index,
|
||||||
|
transform: (currentPlan) => currentPlan.copyWith(
|
||||||
plansForModification[likesState.index] = currentPlan.copyWith(
|
totalLikes: likesState.totalLikes,
|
||||||
totalLikes: likesState.totalLikes,
|
wasLikedByMe: likesState.wasLikedByMe,
|
||||||
wasLikedByMe: likesState.wasLikedByMe,
|
|
||||||
);
|
|
||||||
emit(
|
|
||||||
state.copyWith(
|
|
||||||
plans: [
|
|
||||||
...plansForModification,
|
|
||||||
],
|
|
||||||
isLoading: isLoading,
|
|
||||||
errorMessage: null,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changePlanFavoriteState(FavoriteState favoriteState) {
|
void _changePlanFavoriteState(FavoriteState favoriteState) {
|
||||||
final currentPlans = state.plans;
|
_updatePlanAt(
|
||||||
final plansForModification = [...currentPlans];
|
slug: favoriteState.slug,
|
||||||
final currentPlan = currentPlans[favoriteState.index];
|
index: favoriteState.index,
|
||||||
|
transform: (currentPlan) => currentPlan.copyWith(
|
||||||
plansForModification[favoriteState.index] = currentPlan.copyWith(
|
isFavorite: favoriteState.isFavorite,
|
||||||
isFavorite: favoriteState.isFavorite,
|
|
||||||
);
|
|
||||||
emit(
|
|
||||||
state.copyWith(
|
|
||||||
plans: [
|
|
||||||
...plansForModification,
|
|
||||||
],
|
|
||||||
isLoading: isLoading,
|
|
||||||
errorMessage: null,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changePlanCommentsState(CommentsState commentsState) {
|
void _changePlanCommentsState(CommentsState commentsState) {
|
||||||
final currentPlans = state.plans;
|
_updatePlanAt(
|
||||||
final plansForModification = [...currentPlans];
|
slug: commentsState.slug,
|
||||||
final currentPlan = currentPlans[commentsState.index];
|
index: commentsState.index,
|
||||||
|
transform: (currentPlan) => currentPlan.copyWith(
|
||||||
plansForModification[commentsState.index] = currentPlan.copyWith(
|
totalComments: commentsState.totalComments,
|
||||||
totalComments: commentsState.totalComments,
|
),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _updatePlanAt({
|
||||||
|
required String? slug,
|
||||||
|
required int index,
|
||||||
|
required PlanModel Function(PlanModel currentPlan) transform,
|
||||||
|
}) {
|
||||||
|
final currentPlans = state.plans;
|
||||||
|
final targetIndex =
|
||||||
|
slug != null ? currentPlans.indexWhere((plan) => plan.slug == slug) : index;
|
||||||
|
if (targetIndex < 0 || targetIndex >= currentPlans.length) return;
|
||||||
|
|
||||||
|
final plansForModification = [...currentPlans];
|
||||||
|
plansForModification[targetIndex] = transform(currentPlans[targetIndex]);
|
||||||
emit(
|
emit(
|
||||||
state.copyWith(
|
state.copyWith(
|
||||||
plans: [
|
plans: plansForModification,
|
||||||
...plansForModification,
|
|
||||||
],
|
|
||||||
isLoading: isLoading,
|
isLoading: isLoading,
|
||||||
errorMessage: null,
|
errorMessage: null,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -13,10 +13,8 @@ import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
|
|||||||
import 'package:eatvio_app/core/theme/custom_text_style.dart';
|
import 'package:eatvio_app/core/theme/custom_text_style.dart';
|
||||||
import 'package:eatvio_app/core/utils/url_utils.dart';
|
import 'package:eatvio_app/core/utils/url_utils.dart';
|
||||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||||
import 'package:eatvio_app/features/feed/presentation/bloc/plans_cubit/plans_cubit.dart';
|
|
||||||
import 'package:eatvio_app/generated/l10n.dart';
|
import 'package:eatvio_app/generated/l10n.dart';
|
||||||
import 'package:material_ui/material_ui.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:share_plus/share_plus.dart';
|
import 'package:share_plus/share_plus.dart';
|
||||||
@@ -24,8 +22,20 @@ import 'package:share_plus/share_plus.dart';
|
|||||||
class PlanWidget extends StatefulWidget {
|
class PlanWidget extends StatefulWidget {
|
||||||
final PlanModel plan;
|
final PlanModel plan;
|
||||||
final int index;
|
final int index;
|
||||||
|
final bool showPriceOnCover;
|
||||||
|
final Future<void> Function(String slug)? onLikeTap;
|
||||||
|
final Future<void> Function(String slug, bool isFavorite)? onToggleFavorite;
|
||||||
|
final VoidCallback? onPlanChanged;
|
||||||
|
|
||||||
const PlanWidget({super.key, required this.plan, required this.index});
|
const PlanWidget({
|
||||||
|
super.key,
|
||||||
|
required this.plan,
|
||||||
|
required this.index,
|
||||||
|
this.showPriceOnCover = false,
|
||||||
|
this.onLikeTap,
|
||||||
|
this.onToggleFavorite,
|
||||||
|
this.onPlanChanged,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<PlanWidget> createState() => _PlanWidgetState();
|
State<PlanWidget> createState() => _PlanWidgetState();
|
||||||
@@ -37,6 +47,10 @@ class _PlanWidgetState extends State<PlanWidget> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final s = S.of(context);
|
final s = S.of(context);
|
||||||
|
final minPrice = widget.plan.minPriceOfOptions.toStringAsFixed(0);
|
||||||
|
final price = widget.plan.packetsCount == 1
|
||||||
|
? '${widget.plan.packet1Options?.price ?? minPrice}₽'
|
||||||
|
: '${s.from} $minPrice₽';
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () => GoRouter.of(context).pushNamed(
|
onTap: () => GoRouter.of(context).pushNamed(
|
||||||
'aboutPlanScreen',
|
'aboutPlanScreen',
|
||||||
@@ -71,17 +85,10 @@ class _PlanWidgetState extends State<PlanWidget> {
|
|||||||
left: 14,
|
left: 14,
|
||||||
child: BookmarkButton(
|
child: BookmarkButton(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
if (widget.plan.isFavorite) {
|
await widget.onToggleFavorite?.call(
|
||||||
await context.read<PlansCubit>().removePlanFromFavorite(
|
widget.plan.slug,
|
||||||
widget.plan.slug,
|
widget.plan.isFavorite,
|
||||||
widget.index,
|
);
|
||||||
);
|
|
||||||
} else {
|
|
||||||
await context.read<PlansCubit>().addPlanToFavorite(
|
|
||||||
widget.plan.slug,
|
|
||||||
widget.index,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
color: appTheme.whiteA700,
|
color: appTheme.whiteA700,
|
||||||
isFavorite: widget.plan.isFavorite,
|
isFavorite: widget.plan.isFavorite,
|
||||||
@@ -111,20 +118,47 @@ class _PlanWidgetState extends State<PlanWidget> {
|
|||||||
plan: widget.plan,
|
plan: widget.plan,
|
||||||
complainedContentType: ComplainedContent.plan,
|
complainedContentType: ComplainedContent.plan,
|
||||||
userSlug: widget.plan.author.authorSlug,
|
userSlug: widget.plan.author.authorSlug,
|
||||||
|
onPlanChanged: widget.onPlanChanged,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Positioned(
|
Positioned(
|
||||||
bottom: 16,
|
bottom: 16,
|
||||||
child: SizedBox(
|
left: 0,
|
||||||
width: MediaQuery.sizeOf(context).width,
|
right: 0,
|
||||||
child: InfoRow(
|
child: Column(
|
||||||
plan: widget.plan,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
itemsBackgroundColor: appTheme.whiteA700,
|
children: [
|
||||||
disableDescriptionOfTypes: true,
|
if (widget.showPriceOnCover)
|
||||||
type: ProductType.plan,
|
Padding(
|
||||||
),
|
padding: const EdgeInsets.only(bottom: 8),
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 14,
|
||||||
|
vertical: 4,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: appTheme.greenA700,
|
||||||
|
borderRadius: const BorderRadius.horizontal(
|
||||||
|
right: Radius.circular(8),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
price,
|
||||||
|
style: TextStyles.textSSemibold.copyWith(
|
||||||
|
color: appTheme.whiteA700,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
InfoRow(
|
||||||
|
plan: widget.plan,
|
||||||
|
itemsBackgroundColor: appTheme.whiteA700,
|
||||||
|
disableDescriptionOfTypes: true,
|
||||||
|
type: ProductType.plan,
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -200,30 +234,35 @@ class _PlanWidgetState extends State<PlanWidget> {
|
|||||||
),
|
),
|
||||||
subtitle: Row(
|
subtitle: Row(
|
||||||
children: [
|
children: [
|
||||||
InfoBouble(
|
if (widget.plan.author.authorPlaceInRating != null)
|
||||||
radius: 12,
|
InfoBouble(
|
||||||
backgroundColor: appTheme.gray50,
|
radius: 12,
|
||||||
padding: const EdgeInsets.symmetric(
|
backgroundColor: appTheme.gray50,
|
||||||
vertical: 4,
|
padding: const EdgeInsets.symmetric(
|
||||||
horizontal: 10,
|
vertical: 4,
|
||||||
),
|
horizontal: 10,
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
'${widget.plan.author.authorPlaceInRating}-й в рейтинге',
|
|
||||||
style: TextStyles.textXSSemibold.copyWith(
|
|
||||||
color: appTheme.blueA400,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
children: [
|
||||||
),
|
Text(
|
||||||
const Spacer(),
|
s.rating_place(
|
||||||
Text(
|
widget.plan.author.authorPlaceInRating!,
|
||||||
'${widget.plan.packetsCount == 1 ? widget.plan.packet1Options?.price : '${s.from} ${widget.plan.minPriceOfOptions.toStringAsFixed(0)}'}₽',
|
),
|
||||||
style: TextStyles.headingXLSemibold.copyWith(
|
style: TextStyles.textXSSemibold.copyWith(
|
||||||
color: appTheme.greenA700,
|
color: appTheme.blueA400,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
if (!widget.showPriceOnCover) ...[
|
||||||
const SizedBox(width: 16),
|
const Spacer(),
|
||||||
|
Text(
|
||||||
|
price,
|
||||||
|
style: TextStyles.headingXLSemibold.copyWith(
|
||||||
|
color: appTheme.greenA700,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 16),
|
||||||
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
title: Padding(
|
title: Padding(
|
||||||
@@ -255,10 +294,7 @@ class _PlanWidgetState extends State<PlanWidget> {
|
|||||||
? appTheme.transparentBlue
|
? appTheme.transparentBlue
|
||||||
: null,
|
: null,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
await context.read<PlansCubit>().likePlan(
|
await widget.onLikeTap?.call(widget.plan.slug);
|
||||||
widget.plan.slug,
|
|
||||||
widget.index,
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
|
|||||||
@@ -44,7 +44,15 @@ class Plans extends StatelessWidget {
|
|||||||
final id = state.plans[index].id;
|
final id = state.plans[index].id;
|
||||||
handleVisibility(visibleFraction: info.visibleFraction, id: id, type: ViewableContentType.plans);
|
handleVisibility(visibleFraction: info.visibleFraction, id: id, type: ViewableContentType.plans);
|
||||||
},
|
},
|
||||||
child: PlanWidget(plan: state.plans[index], index: index),
|
child: PlanWidget(
|
||||||
|
plan: state.plans[index],
|
||||||
|
index: index,
|
||||||
|
onLikeTap: (slug) => context.read<PlansCubit>().likePlan(slug, index),
|
||||||
|
onToggleFavorite: (slug, isFavorite) => isFavorite
|
||||||
|
? context.read<PlansCubit>().removePlanFromFavorite(slug, index)
|
||||||
|
: context.read<PlansCubit>().addPlanToFavorite(slug, index),
|
||||||
|
onPlanChanged: () => context.read<PlansCubit>().loadPlans(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
separatorBuilder: (context, index) {
|
separatorBuilder: (context, index) {
|
||||||
|
|||||||
@@ -39,12 +39,14 @@ class InsightsCard extends StatelessWidget {
|
|||||||
this.kbjuEnabled = InsightsFeatureFlags.kbjuEnabled,
|
this.kbjuEnabled = InsightsFeatureFlags.kbjuEnabled,
|
||||||
this.refreshToken = 0,
|
this.refreshToken = 0,
|
||||||
this.initialIntraDate,
|
this.initialIntraDate,
|
||||||
|
this.showShadow = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String? slug;
|
final String? slug;
|
||||||
final bool canAdd;
|
final bool canAdd;
|
||||||
final InsightsRepository? repository;
|
final InsightsRepository? repository;
|
||||||
final bool kbjuEnabled;
|
final bool kbjuEnabled;
|
||||||
|
final bool showShadow;
|
||||||
|
|
||||||
/// При смене значения блок перезапрашивает данные (например, после правок
|
/// При смене значения блок перезапрашивает данные (например, после правок
|
||||||
/// в дневнике), сохраняя вкладку, период и выбранный день.
|
/// в дневнике), сохраняя вкладку, период и выбранный день.
|
||||||
@@ -68,6 +70,7 @@ class InsightsCard extends StatelessWidget {
|
|||||||
child: _InsightsView(
|
child: _InsightsView(
|
||||||
refreshToken: refreshToken,
|
refreshToken: refreshToken,
|
||||||
initialIntraDate: initialIntraDate,
|
initialIntraDate: initialIntraDate,
|
||||||
|
showShadow: showShadow,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -78,10 +81,12 @@ class _InsightsView extends StatefulWidget {
|
|||||||
const _InsightsView({
|
const _InsightsView({
|
||||||
required this.refreshToken,
|
required this.refreshToken,
|
||||||
required this.initialIntraDate,
|
required this.initialIntraDate,
|
||||||
|
required this.showShadow,
|
||||||
});
|
});
|
||||||
|
|
||||||
final int refreshToken;
|
final int refreshToken;
|
||||||
final String? initialIntraDate;
|
final String? initialIntraDate;
|
||||||
|
final bool showShadow;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<_InsightsView> createState() => _InsightsViewState();
|
State<_InsightsView> createState() => _InsightsViewState();
|
||||||
@@ -112,9 +117,13 @@ class _InsightsViewState extends State<_InsightsView> {
|
|||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return switch (state) {
|
return switch (state) {
|
||||||
InsightsStateLoaded() => _CardShell(
|
InsightsStateLoaded() => _CardShell(
|
||||||
|
showShadow: widget.showShadow,
|
||||||
child: _LoadedContent(state: state),
|
child: _LoadedContent(state: state),
|
||||||
),
|
),
|
||||||
InsightsStateError() => const _CardShell(child: _ErrorContent()),
|
InsightsStateError() => _CardShell(
|
||||||
|
showShadow: widget.showShadow,
|
||||||
|
child: const _ErrorContent(),
|
||||||
|
),
|
||||||
_ => const SizedBox.shrink(),
|
_ => const SizedBox.shrink(),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -123,9 +132,10 @@ class _InsightsViewState extends State<_InsightsView> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _CardShell extends StatelessWidget {
|
class _CardShell extends StatelessWidget {
|
||||||
const _CardShell({required this.child});
|
const _CardShell({required this.child, required this.showShadow});
|
||||||
|
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
final bool showShadow;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -135,12 +145,13 @@ class _CardShell extends StatelessWidget {
|
|||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
boxShadow: const [
|
boxShadow: [
|
||||||
BoxShadow(
|
if (showShadow)
|
||||||
color: InsightsColors.cardShadow,
|
const BoxShadow(
|
||||||
blurRadius: 4,
|
color: InsightsColors.cardShadow,
|
||||||
offset: Offset(0, 2),
|
blurRadius: 4,
|
||||||
),
|
offset: Offset(0, 2),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: child,
|
child: child,
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ class AboutPlanCubit extends Cubit<AboutPlanState> {
|
|||||||
Future<void> getPlan({required String slug, int? index}) async {
|
Future<void> getPlan({required String slug, int? index}) async {
|
||||||
try {
|
try {
|
||||||
final plan = await planRepository.getPlan(slug);
|
final plan = await planRepository.getPlan(slug);
|
||||||
if (index != null) {
|
planRepository.emitCommentsStateToFeed(
|
||||||
planRepository.emitCommentsStateToFeed(CommentsState(index: index, totalComments: plan.totalComments));
|
CommentsState(index: index ?? 0, totalComments: plan.totalComments, slug: slug),
|
||||||
}
|
);
|
||||||
emit(state.copyWith(planModel: plan, error: null));
|
emit(state.copyWith(planModel: plan, error: null));
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
await reportFrom(e, stackTrace, this);
|
await reportFrom(e, stackTrace, this);
|
||||||
@@ -59,14 +59,20 @@ class AboutPlanCubit extends Cubit<AboutPlanState> {
|
|||||||
if (currentPlan == null) return;
|
if (currentPlan == null) return;
|
||||||
if (currentPlan.wasLikedByMe) {
|
if (currentPlan.wasLikedByMe) {
|
||||||
emit(state.copyWith(planModel: currentPlan.copyWith(wasLikedByMe: false, totalLikes: currentPlan.totalLikes - 1), error: null));
|
emit(state.copyWith(planModel: currentPlan.copyWith(wasLikedByMe: false, totalLikes: currentPlan.totalLikes - 1), error: null));
|
||||||
if (index != null) {
|
planRepository.emitLikesStateToFeed(LikesState(
|
||||||
planRepository.emitLikesStateToFeed(LikesState(wasLikedByMe: false, totalLikes: currentPlan.totalLikes - 1, index: index));
|
wasLikedByMe: false,
|
||||||
}
|
totalLikes: currentPlan.totalLikes - 1,
|
||||||
|
index: index ?? 0,
|
||||||
|
slug: slug,
|
||||||
|
));
|
||||||
} else {
|
} else {
|
||||||
emit(state.copyWith(planModel: currentPlan.copyWith(wasLikedByMe: true, totalLikes: currentPlan.totalLikes + 1), error: null));
|
emit(state.copyWith(planModel: currentPlan.copyWith(wasLikedByMe: true, totalLikes: currentPlan.totalLikes + 1), error: null));
|
||||||
if (index != null) {
|
planRepository.emitLikesStateToFeed(LikesState(
|
||||||
planRepository.emitLikesStateToFeed(LikesState(wasLikedByMe: true, totalLikes: currentPlan.totalLikes + 1, index: index));
|
wasLikedByMe: true,
|
||||||
}
|
totalLikes: currentPlan.totalLikes + 1,
|
||||||
|
index: index ?? 0,
|
||||||
|
slug: slug,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
EasyDebounce.debounce('like_plan_$slug', const Duration(seconds: 1), () async {
|
EasyDebounce.debounce('like_plan_$slug', const Duration(seconds: 1), () async {
|
||||||
@@ -75,9 +81,12 @@ class AboutPlanCubit extends Cubit<AboutPlanState> {
|
|||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
await reportFrom(e, st, this);
|
await reportFrom(e, st, this);
|
||||||
log(e.toString());
|
log(e.toString());
|
||||||
if (index != null) {
|
planRepository.emitLikesStateToFeed(LikesState(
|
||||||
planRepository.emitLikesStateToFeed(LikesState(wasLikedByMe: currentPlan.wasLikedByMe, totalLikes: currentPlan.totalLikes, index: index));
|
wasLikedByMe: currentPlan.wasLikedByMe,
|
||||||
}
|
totalLikes: currentPlan.totalLikes,
|
||||||
|
index: index ?? 0,
|
||||||
|
slug: slug,
|
||||||
|
));
|
||||||
emit(state.copyWith(planModel: currentPlan, error: null));
|
emit(state.copyWith(planModel: currentPlan, error: null));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -88,9 +97,9 @@ class AboutPlanCubit extends Cubit<AboutPlanState> {
|
|||||||
if (currentPlan == null) return;
|
if (currentPlan == null) return;
|
||||||
|
|
||||||
emit(state.copyWith(planModel: currentPlan.copyWith(isFavorite: true)));
|
emit(state.copyWith(planModel: currentPlan.copyWith(isFavorite: true)));
|
||||||
if (index != null) {
|
planRepository.emitFavoriteStateToFeed(
|
||||||
planRepository.emitFavoriteStateToFeed(FavoriteState(isFavorite: true, index: index));
|
FavoriteState(isFavorite: true, index: index ?? 0, slug: slug),
|
||||||
}
|
);
|
||||||
EasyDebounce.debounce('add_or_remove_plan_to_favorites', const Duration(seconds: 1), () async {
|
EasyDebounce.debounce('add_or_remove_plan_to_favorites', const Duration(seconds: 1), () async {
|
||||||
try {
|
try {
|
||||||
await planRepository.addToFavorite(slug);
|
await planRepository.addToFavorite(slug);
|
||||||
@@ -98,9 +107,9 @@ class AboutPlanCubit extends Cubit<AboutPlanState> {
|
|||||||
await reportFrom(e, st, this);
|
await reportFrom(e, st, this);
|
||||||
log(e.toString());
|
log(e.toString());
|
||||||
showErrorToast('Произошла ошибка. Попробуйте ещё раз через некоторое время');
|
showErrorToast('Произошла ошибка. Попробуйте ещё раз через некоторое время');
|
||||||
if (index != null) {
|
planRepository.emitFavoriteStateToFeed(
|
||||||
planRepository.emitFavoriteStateToFeed(FavoriteState(isFavorite: currentPlan.isFavorite, index: index));
|
FavoriteState(isFavorite: currentPlan.isFavorite, index: index ?? 0, slug: slug),
|
||||||
}
|
);
|
||||||
emit(state.copyWith(planModel: currentPlan, error: null));
|
emit(state.copyWith(planModel: currentPlan, error: null));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -111,9 +120,9 @@ class AboutPlanCubit extends Cubit<AboutPlanState> {
|
|||||||
if (currentPlan == null) return;
|
if (currentPlan == null) return;
|
||||||
|
|
||||||
emit(state.copyWith(planModel: currentPlan.copyWith(isFavorite: false)));
|
emit(state.copyWith(planModel: currentPlan.copyWith(isFavorite: false)));
|
||||||
if (index != null) {
|
planRepository.emitFavoriteStateToFeed(
|
||||||
planRepository.emitFavoriteStateToFeed(FavoriteState(isFavorite: false, index: index));
|
FavoriteState(isFavorite: false, index: index ?? 0, slug: slug),
|
||||||
}
|
);
|
||||||
EasyDebounce.debounce('add_or_remove_plan_to_favorites', const Duration(seconds: 1), () async {
|
EasyDebounce.debounce('add_or_remove_plan_to_favorites', const Duration(seconds: 1), () async {
|
||||||
try {
|
try {
|
||||||
await planRepository.removeFromFavorite(slug);
|
await planRepository.removeFromFavorite(slug);
|
||||||
@@ -121,9 +130,9 @@ class AboutPlanCubit extends Cubit<AboutPlanState> {
|
|||||||
await reportFrom(e, st, this);
|
await reportFrom(e, st, this);
|
||||||
log(e.toString());
|
log(e.toString());
|
||||||
showErrorToast('Произошла ошибка. Попробуйте ещё раз через некоторое время');
|
showErrorToast('Произошла ошибка. Попробуйте ещё раз через некоторое время');
|
||||||
if (index != null) {
|
planRepository.emitFavoriteStateToFeed(
|
||||||
planRepository.emitFavoriteStateToFeed(FavoriteState(isFavorite: currentPlan.isFavorite, index: index));
|
FavoriteState(isFavorite: currentPlan.isFavorite, index: index ?? 0, slug: slug),
|
||||||
}
|
);
|
||||||
emit(state.copyWith(planModel: currentPlan, error: null));
|
emit(state.copyWith(planModel: currentPlan, error: null));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ class PlanRepository {
|
|||||||
final _planLikeStateStreamController = StreamController<LikesState>.broadcast();
|
final _planLikeStateStreamController = StreamController<LikesState>.broadcast();
|
||||||
final _planFavoriteStateStreamController = StreamController<FavoriteState>.broadcast();
|
final _planFavoriteStateStreamController = StreamController<FavoriteState>.broadcast();
|
||||||
final _planCommentsStateStreamController = StreamController<CommentsState>.broadcast();
|
final _planCommentsStateStreamController = StreamController<CommentsState>.broadcast();
|
||||||
Stream get planLikeState => _planLikeStateStreamController.stream;
|
Stream<LikesState> get planLikeState => _planLikeStateStreamController.stream;
|
||||||
Stream get planFavoriteState => _planFavoriteStateStreamController.stream;
|
Stream<FavoriteState> get planFavoriteState => _planFavoriteStateStreamController.stream;
|
||||||
Stream get planCommentsState => _planCommentsStateStreamController.stream;
|
Stream<CommentsState> get planCommentsState => _planCommentsStateStreamController.stream;
|
||||||
|
|
||||||
Future<PlanModel> getPlan(String slug) async {
|
Future<PlanModel> getPlan(String slug) async {
|
||||||
return planService.getPlan(slug);
|
return planService.getPlan(slug);
|
||||||
|
|||||||
@@ -1,25 +1,197 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'dart:developer';
|
import 'dart:developer';
|
||||||
|
|
||||||
|
import 'package:easy_debounce/easy_debounce.dart';
|
||||||
|
import 'package:eatvio_app/core/error_reporting/report_from.dart';
|
||||||
|
import 'package:eatvio_app/core/utils/toasts.dart';
|
||||||
|
import 'package:eatvio_app/features/diets/repositories/diet_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
|
||||||
|
import 'package:eatvio_app/features/plans/repositories/plan_repository.dart';
|
||||||
import 'package:eatvio_app/features/plans/repositories/plans_repository.dart';
|
import 'package:eatvio_app/features/plans/repositories/plans_repository.dart';
|
||||||
import 'package:eatvio_app/features/profile/presentation/bloc/plans_cubit/plans_state.dart';
|
import 'package:eatvio_app/features/profile/presentation/bloc/plans_cubit/plans_state.dart';
|
||||||
|
import 'package:eatvio_app/generated/l10n.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:eatvio_app/core/error_reporting/report_from.dart';
|
|
||||||
|
|
||||||
class PlansCubit extends Cubit<PlansState> {
|
class PlansCubit extends Cubit<PlansState> {
|
||||||
final PlansRepository plansRepository;
|
final PlansRepository plansRepository;
|
||||||
|
final PlanRepository planRepository;
|
||||||
|
|
||||||
|
static const Duration _debounceDuration = Duration(milliseconds: 200);
|
||||||
|
|
||||||
|
late final StreamSubscription<LikesState> likesStateSubscription;
|
||||||
|
late final StreamSubscription<FavoriteState> favoriteStateSubscription;
|
||||||
|
late final StreamSubscription<CommentsState> commentsStateSubscription;
|
||||||
|
|
||||||
|
final Set<String> _pendingDebounceTags = {};
|
||||||
|
|
||||||
PlansCubit({
|
PlansCubit({
|
||||||
required this.plansRepository,
|
required this.plansRepository,
|
||||||
}) : super(const PlansState());
|
required this.planRepository,
|
||||||
|
}) : super(const PlansState()) {
|
||||||
|
likesStateSubscription = planRepository.planLikeState.listen(_changePlanLikeState);
|
||||||
|
favoriteStateSubscription = planRepository.planFavoriteState.listen(_changePlanFavoriteState);
|
||||||
|
commentsStateSubscription = planRepository.planCommentsState.listen(_changePlanCommentsState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> close() async {
|
||||||
|
for (final tag in _pendingDebounceTags) {
|
||||||
|
EasyDebounce.cancel(tag);
|
||||||
|
}
|
||||||
|
_pendingDebounceTags.clear();
|
||||||
|
await likesStateSubscription.cancel();
|
||||||
|
await favoriteStateSubscription.cancel();
|
||||||
|
await commentsStateSubscription.cancel();
|
||||||
|
await super.close();
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> getPlans(String slug) async {
|
Future<void> getPlans(String slug) async {
|
||||||
emit(const PlansState.loading());
|
emit(const PlansState.loading());
|
||||||
try {
|
try {
|
||||||
emit(PlansState.loaded(plansList: await plansRepository.getPlansBySlug(slug)));
|
final plansList = await plansRepository.getPlansBySlug(slug);
|
||||||
|
if (!isClosed) emit(PlansState.loaded(plansList: plansList));
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
await reportFrom(e, st, this);
|
await reportFrom(e, st, this);
|
||||||
log(e.toString());
|
log(e.toString());
|
||||||
emit(PlansState.error(errorMessage: e.toString()));
|
if (!isClosed) emit(PlansState.error(errorMessage: e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> likePlan(String slug) async {
|
||||||
|
final plan = _planBySlug(slug);
|
||||||
|
if (plan == null) return;
|
||||||
|
|
||||||
|
final wasLikedByMe = plan.wasLikedByMe;
|
||||||
|
final totalLikes = plan.totalLikes;
|
||||||
|
|
||||||
|
_updatePlanBySlug(
|
||||||
|
slug,
|
||||||
|
(plan) => plan.copyWith(
|
||||||
|
wasLikedByMe: !plan.wasLikedByMe,
|
||||||
|
totalLikes: plan.wasLikedByMe ? plan.totalLikes - 1 : plan.totalLikes + 1,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
_debounce('profile_like_plan_$slug', () async {
|
||||||
|
try {
|
||||||
|
await planRepository.likePlan(slug);
|
||||||
|
} catch (e, st) {
|
||||||
|
await reportFrom(e, st, this);
|
||||||
|
if (isClosed) return;
|
||||||
|
_updatePlanBySlug(
|
||||||
|
slug,
|
||||||
|
(plan) => plan.copyWith(wasLikedByMe: wasLikedByMe, totalLikes: totalLikes),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> addPlanToFavorite(String slug) => _changeFavorite(slug, true);
|
||||||
|
|
||||||
|
Future<void> removePlanFromFavorite(String slug) => _changeFavorite(slug, false);
|
||||||
|
|
||||||
|
Future<void> _changeFavorite(String slug, bool isFavorite) async {
|
||||||
|
final plan = _planBySlug(slug);
|
||||||
|
if (plan == null) return;
|
||||||
|
|
||||||
|
final previousIsFavorite = plan.isFavorite;
|
||||||
|
|
||||||
|
_updatePlanBySlug(slug, (plan) => plan.copyWith(isFavorite: isFavorite));
|
||||||
|
|
||||||
|
_debounce('profile_favorite_$slug', () async {
|
||||||
|
try {
|
||||||
|
if (isFavorite) {
|
||||||
|
await planRepository.addToFavorite(slug);
|
||||||
|
} else {
|
||||||
|
await planRepository.removeFromFavorite(slug);
|
||||||
|
}
|
||||||
|
} catch (e, st) {
|
||||||
|
await reportFrom(e, st, this);
|
||||||
|
if (isClosed) return;
|
||||||
|
_updatePlanBySlug(slug, (plan) => plan.copyWith(isFavorite: previousIsFavorite));
|
||||||
|
showErrorToast(S.current.error_try_again_later);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _changePlanLikeState(LikesState likesState) {
|
||||||
|
_updatePlan(
|
||||||
|
slug: likesState.slug,
|
||||||
|
index: likesState.index,
|
||||||
|
transform: (plan) => plan.copyWith(
|
||||||
|
totalLikes: likesState.totalLikes,
|
||||||
|
wasLikedByMe: likesState.wasLikedByMe,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _changePlanFavoriteState(FavoriteState favoriteState) {
|
||||||
|
_updatePlan(
|
||||||
|
slug: favoriteState.slug,
|
||||||
|
index: favoriteState.index,
|
||||||
|
transform: (plan) => plan.copyWith(isFavorite: favoriteState.isFavorite),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _changePlanCommentsState(CommentsState commentsState) {
|
||||||
|
_updatePlan(
|
||||||
|
slug: commentsState.slug,
|
||||||
|
index: commentsState.index,
|
||||||
|
transform: (plan) => plan.copyWith(totalComments: commentsState.totalComments),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _updatePlan({
|
||||||
|
required String? slug,
|
||||||
|
required int index,
|
||||||
|
required PlanModel Function(PlanModel plan) transform,
|
||||||
|
}) {
|
||||||
|
if (slug != null) {
|
||||||
|
_updatePlanBySlug(slug, transform);
|
||||||
|
} else {
|
||||||
|
_updatePlanByIndex(index, transform);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _updatePlanBySlug(String slug, PlanModel Function(PlanModel plan) transform) {
|
||||||
|
final current = state;
|
||||||
|
if (current is! PlansStateLoaded || isClosed) return;
|
||||||
|
|
||||||
|
final index = current.plansList.indexWhere((plan) => plan.slug == slug);
|
||||||
|
if (index == -1) return;
|
||||||
|
|
||||||
|
_emitPlanAt(current, index, transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _updatePlanByIndex(int index, PlanModel Function(PlanModel plan) transform) {
|
||||||
|
final current = state;
|
||||||
|
if (current is! PlansStateLoaded || isClosed) return;
|
||||||
|
if (index < 0 || index >= current.plansList.length) return;
|
||||||
|
|
||||||
|
_emitPlanAt(current, index, transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _emitPlanAt(PlansStateLoaded current, int index, PlanModel Function(PlanModel plan) transform) {
|
||||||
|
final plansList = [...current.plansList];
|
||||||
|
plansList[index] = transform(plansList[index]);
|
||||||
|
emit(current.copyWith(plansList: plansList));
|
||||||
|
}
|
||||||
|
|
||||||
|
PlanModel? _planBySlug(String slug) {
|
||||||
|
final current = state;
|
||||||
|
if (current is! PlansStateLoaded) return null;
|
||||||
|
|
||||||
|
for (final plan in current.plansList) {
|
||||||
|
if (plan.slug == slug) return plan;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _debounce(String tag, Future<void> Function() action) {
|
||||||
|
_pendingDebounceTags.add(tag);
|
||||||
|
EasyDebounce.debounce(tag, _debounceDuration, () async {
|
||||||
|
_pendingDebounceTags.remove(tag);
|
||||||
|
await action();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ class ProfileCubit extends Cubit<ProfileState> {
|
|||||||
void updateFeedBlogPostList(FeedBlogPostModel feedBlogPostModel, bool wasLikedByMe) {
|
void updateFeedBlogPostList(FeedBlogPostModel feedBlogPostModel, bool wasLikedByMe) {
|
||||||
List<FeedBlogPostModel> feedBlogPostList = [...(state as ProfileStateLoaded).blogPosts];
|
List<FeedBlogPostModel> feedBlogPostList = [...(state as ProfileStateLoaded).blogPosts];
|
||||||
final int index = feedBlogPostList.indexOf(feedBlogPostModel);
|
final int index = feedBlogPostList.indexOf(feedBlogPostModel);
|
||||||
|
if (index == -1) return;
|
||||||
feedBlogPostList[index] = feedBlogPostModel.copyWith(
|
feedBlogPostList[index] = feedBlogPostModel.copyWith(
|
||||||
wasLikedByMe: wasLikedByMe,
|
wasLikedByMe: wasLikedByMe,
|
||||||
totalLikes: wasLikedByMe == false ? feedBlogPostList[index].totalLikes - 1 : feedBlogPostList[index].totalLikes + 1,
|
totalLikes: wasLikedByMe == false ? feedBlogPostList[index].totalLikes - 1 : feedBlogPostList[index].totalLikes + 1,
|
||||||
|
|||||||
@@ -205,24 +205,27 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
Container(
|
if (state.consultantInfo!.ratingPlace != null)
|
||||||
padding: const EdgeInsets.symmetric(
|
Container(
|
||||||
horizontal: 12,
|
padding: const EdgeInsets.symmetric(
|
||||||
vertical: 8,
|
horizontal: 12,
|
||||||
),
|
vertical: 8,
|
||||||
decoration: BoxDecoration(
|
),
|
||||||
color: const Color(0xFFF6FAFF),
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(12),
|
color: const Color(0xFFF6FAFF),
|
||||||
),
|
borderRadius: BorderRadius.circular(12),
|
||||||
child: Text(
|
),
|
||||||
'${state.consultantInfo!.ratingPlace}-й в рейтинге',
|
child: Text(
|
||||||
style: TextStyle(
|
S.of(context).rating_place(
|
||||||
fontSize: 16,
|
state.consultantInfo!.ratingPlace!,
|
||||||
fontWeight: FontWeight.w600,
|
),
|
||||||
color: appTheme.blueA400,
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: appTheme.blueA400,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (state
|
if (state
|
||||||
@@ -331,6 +334,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Scaffold _myProfileScreen(ProfileStateLoaded state) {
|
Scaffold _myProfileScreen(ProfileStateLoaded state) {
|
||||||
|
final consultantInfo = state.consultantInfo;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Colors.grey.shade200,
|
backgroundColor: Colors.grey.shade200,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
@@ -360,7 +364,8 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
_header(state),
|
_header(state),
|
||||||
if (state.profile.roles.contains('consultant'))
|
if (state.profile.roles.contains('consultant') &&
|
||||||
|
consultantInfo != null)
|
||||||
Column(
|
Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
@@ -376,31 +381,30 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
Container(
|
if (consultantInfo.ratingPlace != null)
|
||||||
padding: const EdgeInsets.symmetric(
|
Container(
|
||||||
horizontal: 12,
|
padding: const EdgeInsets.symmetric(
|
||||||
vertical: 8,
|
horizontal: 12,
|
||||||
),
|
vertical: 8,
|
||||||
decoration: BoxDecoration(
|
),
|
||||||
color: const Color(0xFFF6FAFF),
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(12),
|
color: const Color(0xFFF6FAFF),
|
||||||
),
|
borderRadius: BorderRadius.circular(12),
|
||||||
child: Text(
|
),
|
||||||
'${state.consultantInfo!.ratingPlace}-й в рейтинге',
|
child: Text(
|
||||||
style: TextStyle(
|
S.of(context).rating_place(
|
||||||
fontSize: 16,
|
consultantInfo.ratingPlace!,
|
||||||
fontWeight: FontWeight.w600,
|
),
|
||||||
color: appTheme.blueA400,
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: appTheme.blueA400,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (state
|
if (consultantInfo.educationModel.hasMedicalEducation == 1)
|
||||||
.consultantInfo!
|
|
||||||
.educationModel
|
|
||||||
.hasMedicalEducation ==
|
|
||||||
1)
|
|
||||||
const Row(
|
const Row(
|
||||||
children: [
|
children: [
|
||||||
SizedBox(width: 16),
|
SizedBox(width: 16),
|
||||||
@@ -451,6 +455,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
if (!state.profile.roles.contains('consultant') || hidePlans) {
|
if (!state.profile.roles.contains('consultant') || hidePlans) {
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
|
final profileSlug = state.profile.slug;
|
||||||
return BlocBuilder<PlansCubit, PlansState>(
|
return BlocBuilder<PlansCubit, PlansState>(
|
||||||
bloc: plansCubit,
|
bloc: plansCubit,
|
||||||
builder: (BuildContext context, PlansState state) {
|
builder: (BuildContext context, PlansState state) {
|
||||||
@@ -486,7 +491,16 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return PlanWidget(plan: state.plansList[index], index: index);
|
return PlanWidget(
|
||||||
|
plan: state.plansList[index],
|
||||||
|
index: index,
|
||||||
|
showPriceOnCover: true,
|
||||||
|
onLikeTap: (slug) => plansCubit.likePlan(slug),
|
||||||
|
onToggleFavorite: (slug, isFavorite) => isFavorite
|
||||||
|
? plansCubit.removePlanFromFavorite(slug)
|
||||||
|
: plansCubit.addPlanToFavorite(slug),
|
||||||
|
onPlanChanged: () => plansCubit.getPlans(profileSlug),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
@@ -895,10 +909,11 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SingleChildRenderObjectWidget _socialLinks(ProfileStateLoaded state) {
|
SingleChildRenderObjectWidget _socialLinks(ProfileStateLoaded state) {
|
||||||
if (!state.profile.roles.contains('consultant') &&
|
final consultantInfo = state.consultantInfo;
|
||||||
state.consultantInfo != null) {
|
if (!state.profile.roles.contains('consultant') || consultantInfo == null) {
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
|
final educationModel = consultantInfo.educationModel;
|
||||||
return Padding(
|
return Padding(
|
||||||
padding:
|
padding:
|
||||||
const EdgeInsets.symmetric(horizontal: 4) +
|
const EdgeInsets.symmetric(horizontal: 4) +
|
||||||
@@ -913,47 +928,34 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
_socialLinkButton(
|
_socialLinkButton(
|
||||||
() {
|
() {
|
||||||
launchUrl(
|
launchUrl(
|
||||||
Uri.parse(
|
Uri.parse(educationModel.vkLink ?? ''),
|
||||||
state.consultantInfo!.educationModel.vkLink ?? '',
|
|
||||||
),
|
|
||||||
mode: LaunchMode.externalApplication,
|
mode: LaunchMode.externalApplication,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'assets/icons/vk.svg',
|
'assets/icons/vk.svg',
|
||||||
state.consultantInfo!.educationModel.vkLink!.isEmpty
|
educationModel.vkLink?.isEmpty ?? true,
|
||||||
? true
|
|
||||||
: false,
|
|
||||||
),
|
),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
_socialLinkButton(
|
_socialLinkButton(
|
||||||
() {
|
() {
|
||||||
launchUrl(
|
launchUrl(
|
||||||
Uri.parse(
|
Uri.parse(educationModel.tgLink ?? ''),
|
||||||
state.consultantInfo!.educationModel.tgLink ?? '',
|
|
||||||
),
|
|
||||||
mode: LaunchMode.externalApplication,
|
mode: LaunchMode.externalApplication,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'assets/icons/telegram.svg',
|
'assets/icons/telegram.svg',
|
||||||
state.consultantInfo!.educationModel.tgLink!.isEmpty
|
educationModel.tgLink?.isEmpty ?? true,
|
||||||
? true
|
|
||||||
: false,
|
|
||||||
),
|
),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
_socialLinkButton(
|
_socialLinkButton(
|
||||||
() {
|
() {
|
||||||
launchUrl(
|
launchUrl(
|
||||||
Uri.parse(
|
Uri.parse(educationModel.personalSiteLink ?? ''),
|
||||||
state.consultantInfo!.educationModel.personalSiteLink ??
|
|
||||||
'',
|
|
||||||
),
|
|
||||||
mode: LaunchMode.externalApplication,
|
mode: LaunchMode.externalApplication,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'assets/icons/web.svg',
|
'assets/icons/web.svg',
|
||||||
state.consultantInfo!.educationModel.personalSiteLink!.isEmpty
|
educationModel.personalSiteLink?.isEmpty ?? true,
|
||||||
? true
|
|
||||||
: false,
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -191,21 +191,24 @@ class _ProfileBlogPostWidgetState extends State<ProfileBlogPostWidget> {
|
|||||||
? Colors.red.withValues(alpha: 0.8)
|
? Colors.red.withValues(alpha: 0.8)
|
||||||
: null,
|
: null,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
|
final nextLiked = !isLiked;
|
||||||
setState(() {
|
setState(() {
|
||||||
isLiked = !isLiked;
|
isLiked = nextLiked;
|
||||||
isLiked ? totalLikes++ : totalLikes--;
|
nextLiked ? totalLikes++ : totalLikes--;
|
||||||
});
|
});
|
||||||
isLiked
|
|
||||||
? await context.read<FeedCubit>().likePost(
|
|
||||||
post.id,
|
|
||||||
)
|
|
||||||
: await context.read<FeedCubit>().unlikedPost(
|
|
||||||
post.id,
|
|
||||||
);
|
|
||||||
widget.profileCubit.updateFeedBlogPostList(
|
widget.profileCubit.updateFeedBlogPostList(
|
||||||
post,
|
post,
|
||||||
isLiked ? false : true,
|
nextLiked,
|
||||||
);
|
);
|
||||||
|
if (nextLiked) {
|
||||||
|
await context.read<FeedCubit>().likePost(
|
||||||
|
post.id,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await context.read<FeedCubit>().unlikedPost(
|
||||||
|
post.id,
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
|
|||||||
@@ -80,29 +80,33 @@ class SettingsCubit extends Cubit<SettingsState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateProfileDetails({
|
Future<bool> updateProfileDetails({
|
||||||
required ProfileDetailsModel profileDetailsModel,
|
required ProfileDetailsModel profileDetailsModel,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
await settingsRepository.updateProfileDetails(
|
await settingsRepository.updateProfileDetails(
|
||||||
profileDetailsModel: profileDetailsModel,
|
profileDetailsModel: profileDetailsModel,
|
||||||
);
|
);
|
||||||
|
return true;
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
await reportFrom(e, st, this);
|
await reportFrom(e, st, this);
|
||||||
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
await init();
|
await init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateProfileSettings({
|
Future<bool> updateProfileSettings({
|
||||||
required ProfileSettingsModel profileSettingsModel,
|
required ProfileSettingsModel profileSettingsModel,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
await settingsRepository.updateProfileSettings(
|
await settingsRepository.updateProfileSettings(
|
||||||
profileSettingsModel: profileSettingsModel,
|
profileSettingsModel: profileSettingsModel,
|
||||||
);
|
);
|
||||||
|
return true;
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
await reportFrom(e, st, this);
|
await reportFrom(e, st, this);
|
||||||
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
await init();
|
await init();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:eatvio_app/core/data/selectionPopupModel/selection_popup_model.dart';
|
import 'package:eatvio_app/core/data/selectionPopupModel/selection_popup_model.dart';
|
||||||
import 'package:eatvio_app/core/utils/date_time_utils.dart';
|
import 'package:eatvio_app/core/utils/date_time_utils.dart';
|
||||||
|
import 'package:eatvio_app/core/utils/toasts.dart';
|
||||||
import 'package:eatvio_app/core/widgets/custom_drop_down.dart';
|
import 'package:eatvio_app/core/widgets/custom_drop_down.dart';
|
||||||
import 'package:eatvio_app/core/widgets/loader.dart';
|
import 'package:eatvio_app/core/widgets/loader.dart';
|
||||||
import 'package:eatvio_app/features/create_diet/presentation/widgets/error_widget.dart';
|
import 'package:eatvio_app/features/create_diet/presentation/widgets/error_widget.dart';
|
||||||
@@ -10,6 +11,7 @@ import 'package:eatvio_app/core/theme/theme_helper.dart';
|
|||||||
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
|
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
|
||||||
import 'package:material_ui/material_ui.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:cupertino_ui/cupertino_ui.dart';
|
import 'package:cupertino_ui/cupertino_ui.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
class GeneralInfoScreen extends StatefulWidget {
|
class GeneralInfoScreen extends StatefulWidget {
|
||||||
final SettingsEntity settingsEntity;
|
final SettingsEntity settingsEntity;
|
||||||
@@ -233,7 +235,7 @@ class _GeneralInfoScreenState extends State<GeneralInfoScreen> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
});
|
});
|
||||||
await widget.settingsEntity.settingsCubit.updateProfileDetails(
|
final detailsSaved = await widget.settingsEntity.settingsCubit.updateProfileDetails(
|
||||||
profileDetailsModel: (widget.settingsEntity.settingsCubit.state as SettingsStateLoaded).profileDetails.copyWith(
|
profileDetailsModel: (widget.settingsEntity.settingsCubit.state as SettingsStateLoaded).profileDetails.copyWith(
|
||||||
firstName: firstNameController.text,
|
firstName: firstNameController.text,
|
||||||
lastName: lastNameController.text,
|
lastName: lastNameController.text,
|
||||||
@@ -244,7 +246,7 @@ class _GeneralInfoScreenState extends State<GeneralInfoScreen> {
|
|||||||
lang: languageController.text,
|
lang: languageController.text,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
await widget.settingsEntity.settingsCubit.updateProfileSettings(
|
final settingsSaved = await widget.settingsEntity.settingsCubit.updateProfileSettings(
|
||||||
profileSettingsModel: (widget.settingsEntity.settingsCubit.state as SettingsStateLoaded).profileSettings.copyWith(
|
profileSettingsModel: (widget.settingsEntity.settingsCubit.state as SettingsStateLoaded).profileSettings.copyWith(
|
||||||
isPublicProfile: isPublicProfile.value,
|
isPublicProfile: isPublicProfile.value,
|
||||||
),
|
),
|
||||||
@@ -253,6 +255,10 @@ class _GeneralInfoScreenState extends State<GeneralInfoScreen> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
});
|
});
|
||||||
|
if (detailsSaved && settingsSaved) {
|
||||||
|
showSuccessToast(S.of(context).data_saved_successfully);
|
||||||
|
context.pop();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
child: Ink(
|
child: Ink(
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:eatvio_app/features/settings/entities/settings_entity.dart';
|
|||||||
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart';
|
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart';
|
||||||
import 'package:eatvio_app/generated/l10n.dart';
|
import 'package:eatvio_app/generated/l10n.dart';
|
||||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||||
|
import 'package:eatvio_app/core/utils/toasts.dart';
|
||||||
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
|
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
|
||||||
import 'package:material_ui/material_ui.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
@@ -137,8 +138,8 @@ class _OtherInfoScreenState extends State<OtherInfoScreen> {
|
|||||||
|
|
||||||
InkWell _saveButton() {
|
InkWell _saveButton() {
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
widget.settingsEntity.settingsCubit.updateProfileDetails(
|
final saved = await widget.settingsEntity.settingsCubit.updateProfileDetails(
|
||||||
profileDetailsModel: (widget.settingsEntity.settingsCubit.state as SettingsStateLoaded).profileDetails.copyWith(
|
profileDetailsModel: (widget.settingsEntity.settingsCubit.state as SettingsStateLoaded).profileDetails.copyWith(
|
||||||
aboutAlergy: aboutAllergyController.text,
|
aboutAlergy: aboutAllergyController.text,
|
||||||
aboutTakingPils: aboutTakingPillsController.text,
|
aboutTakingPils: aboutTakingPillsController.text,
|
||||||
@@ -148,7 +149,11 @@ class _OtherInfoScreenState extends State<OtherInfoScreen> {
|
|||||||
additionalInfo: additionalInfoController.text,
|
additionalInfo: additionalInfoController.text,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
GoRouter.of(context).pop();
|
if (!mounted) return;
|
||||||
|
if (saved) {
|
||||||
|
showSuccessToast(S.of(context).data_saved_successfully);
|
||||||
|
GoRouter.of(context).pop();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
child: Ink(
|
child: Ink(
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import 'package:eatvio_app/features/settings/entities/settings_entity.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_cubit.dart';
|
||||||
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart';
|
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart';
|
||||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||||
|
import 'package:eatvio_app/core/utils/toasts.dart';
|
||||||
|
import 'package:eatvio_app/generated/l10n.dart';
|
||||||
import 'package:material_ui/material_ui.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
@@ -200,7 +202,7 @@ class _PhysicalActivityScreenState extends State<PhysicalActivityScreen> {
|
|||||||
|
|
||||||
InkWell _saveButton() {
|
InkWell _saveButton() {
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
late final double activityCoefficient;
|
late final double activityCoefficient;
|
||||||
switch (_physicalActivity) {
|
switch (_physicalActivity) {
|
||||||
case PhysicalActivity.minimum:
|
case PhysicalActivity.minimum:
|
||||||
@@ -221,12 +223,16 @@ class _PhysicalActivityScreenState extends State<PhysicalActivityScreen> {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
widget.settingsEntity.settingsCubit.updateProfileDetails(
|
final saved = await widget.settingsEntity.settingsCubit.updateProfileDetails(
|
||||||
profileDetailsModel: (widget.settingsEntity.settingsCubit.state as SettingsStateLoaded).profileDetails.copyWith(
|
profileDetailsModel: (widget.settingsEntity.settingsCubit.state as SettingsStateLoaded).profileDetails.copyWith(
|
||||||
activityCoefficient: activityCoefficient,
|
activityCoefficient: activityCoefficient,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
GoRouter.of(context).pop();
|
if (!mounted) return;
|
||||||
|
if (saved) {
|
||||||
|
showSuccessToast(S.of(context).data_saved_successfully);
|
||||||
|
GoRouter.of(context).pop();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
child: Ink(
|
child: Ink(
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:eatvio_app/features/settings/entities/settings_entity.dart';
|
|||||||
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart';
|
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart';
|
||||||
import 'package:eatvio_app/generated/l10n.dart';
|
import 'package:eatvio_app/generated/l10n.dart';
|
||||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||||
|
import 'package:eatvio_app/core/utils/toasts.dart';
|
||||||
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
|
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
|
||||||
import 'package:material_ui/material_ui.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
@@ -108,8 +109,8 @@ class _PhysicalFormScreenState extends State<PhysicalFormScreen> {
|
|||||||
|
|
||||||
InkWell _saveButton() {
|
InkWell _saveButton() {
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
widget.settingsEntity.settingsCubit.updateProfileDetails(
|
final saved = await widget.settingsEntity.settingsCubit.updateProfileDetails(
|
||||||
profileDetailsModel: (widget.settingsEntity.settingsCubit.state as SettingsStateLoaded).profileDetails.copyWith(
|
profileDetailsModel: (widget.settingsEntity.settingsCubit.state as SettingsStateLoaded).profileDetails.copyWith(
|
||||||
chestCircumference: int.parse(chestCircumferenceController.text),
|
chestCircumference: int.parse(chestCircumferenceController.text),
|
||||||
waistCircumference: int.parse(waistCircumferenceController.text),
|
waistCircumference: int.parse(waistCircumferenceController.text),
|
||||||
@@ -118,7 +119,11 @@ class _PhysicalFormScreenState extends State<PhysicalFormScreen> {
|
|||||||
weight: double.parse(weightController.text),
|
weight: double.parse(weightController.text),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
GoRouter.of(context).pop();
|
if (!mounted) return;
|
||||||
|
if (saved) {
|
||||||
|
showSuccessToast(S.of(context).data_saved_successfully);
|
||||||
|
GoRouter.of(context).pop();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
child: Ink(
|
child: Ink(
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import 'package:eatvio_app/features/settings/entities/settings_entity.dart';
|
|||||||
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart';
|
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart';
|
||||||
import 'package:eatvio_app/generated/l10n.dart';
|
import 'package:eatvio_app/generated/l10n.dart';
|
||||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||||
|
import 'package:eatvio_app/core/utils/toasts.dart';
|
||||||
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
|
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
|
||||||
import 'package:material_ui/material_ui.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
@@ -114,8 +115,8 @@ class _PressureScreenState extends State<PressureScreen> {
|
|||||||
|
|
||||||
InkWell _saveButton() {
|
InkWell _saveButton() {
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
widget.settingsEntity.settingsCubit.updateProfileDetails(
|
final saved = await widget.settingsEntity.settingsCubit.updateProfileDetails(
|
||||||
profileDetailsModel: (widget.settingsEntity.settingsCubit.state as SettingsStateLoaded).profileDetails.copyWith(
|
profileDetailsModel: (widget.settingsEntity.settingsCubit.state as SettingsStateLoaded).profileDetails.copyWith(
|
||||||
bloodPressureUp: int.parse(bloodPressureUpController.text),
|
bloodPressureUp: int.parse(bloodPressureUpController.text),
|
||||||
bloodPressureDown: int.parse(bloodPressureDownController.text),
|
bloodPressureDown: int.parse(bloodPressureDownController.text),
|
||||||
@@ -123,7 +124,11 @@ class _PressureScreenState extends State<PressureScreen> {
|
|||||||
hasHypo: hypo.value,
|
hasHypo: hypo.value,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
GoRouter.of(context).pop();
|
if (!mounted) return;
|
||||||
|
if (saved) {
|
||||||
|
showSuccessToast(S.of(context).data_saved_successfully);
|
||||||
|
GoRouter.of(context).pop();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
child: Ink(
|
child: Ink(
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:intl/message_lookup_by_library.dart';
|
import 'package:intl/message_lookup_by_library.dart';
|
||||||
import 'package:intl/src/intl_helpers.dart';
|
import 'package:intl/src/intl_helpers.dart';
|
||||||
@@ -20,8 +21,8 @@ import 'messages_ru.dart' as messages_ru;
|
|||||||
|
|
||||||
typedef Future<dynamic> LibraryLoader();
|
typedef Future<dynamic> LibraryLoader();
|
||||||
Map<String, LibraryLoader> _deferredLibraries = {
|
Map<String, LibraryLoader> _deferredLibraries = {
|
||||||
'en': () => new Future.value(null),
|
'en': () => new SynchronousFuture(null),
|
||||||
'ru': () => new Future.value(null),
|
'ru': () => new SynchronousFuture(null),
|
||||||
};
|
};
|
||||||
|
|
||||||
MessageLookupByLibrary? _findExact(String localeName) {
|
MessageLookupByLibrary? _findExact(String localeName) {
|
||||||
@@ -36,18 +37,20 @@ MessageLookupByLibrary? _findExact(String localeName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// User programs should call this before using [localeName] for messages.
|
/// User programs should call this before using [localeName] for messages.
|
||||||
Future<bool> initializeMessages(String localeName) async {
|
Future<bool> initializeMessages(String localeName) {
|
||||||
var availableLocale = Intl.verifiedLocale(
|
var availableLocale = Intl.verifiedLocale(
|
||||||
localeName, (locale) => _deferredLibraries[locale] != null,
|
localeName,
|
||||||
onFailure: (_) => null);
|
(locale) => _deferredLibraries[locale] != null,
|
||||||
|
onFailure: (_) => null,
|
||||||
|
);
|
||||||
if (availableLocale == null) {
|
if (availableLocale == null) {
|
||||||
return new Future.value(false);
|
return new SynchronousFuture(false);
|
||||||
}
|
}
|
||||||
var lib = _deferredLibraries[availableLocale];
|
var lib = _deferredLibraries[availableLocale];
|
||||||
await (lib == null ? new Future.value(false) : lib());
|
lib == null ? new SynchronousFuture(false) : lib();
|
||||||
initializeInternalMessageLookup(() => new CompositeMessageLookup());
|
initializeInternalMessageLookup(() => new CompositeMessageLookup());
|
||||||
messageLookup.addLocale(availableLocale, _findGeneratedMessagesFor);
|
messageLookup.addLocale(availableLocale, _findGeneratedMessagesFor);
|
||||||
return new Future.value(true);
|
return new SynchronousFuture(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _messagesExistFor(String locale) {
|
bool _messagesExistFor(String locale) {
|
||||||
@@ -59,8 +62,11 @@ bool _messagesExistFor(String locale) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MessageLookupByLibrary? _findGeneratedMessagesFor(String locale) {
|
MessageLookupByLibrary? _findGeneratedMessagesFor(String locale) {
|
||||||
var actualLocale =
|
var actualLocale = Intl.verifiedLocale(
|
||||||
Intl.verifiedLocale(locale, _messagesExistFor, onFailure: (_) => null);
|
locale,
|
||||||
|
_messagesExistFor,
|
||||||
|
onFailure: (_) => null,
|
||||||
|
);
|
||||||
if (actualLocale == null) return null;
|
if (actualLocale == null) return null;
|
||||||
return _findExact(actualLocale);
|
return _findExact(actualLocale);
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,7 @@
|
|||||||
"last_name": "Фамилия",
|
"last_name": "Фамилия",
|
||||||
"what_is_your_name": "Как вас зовут?",
|
"what_is_your_name": "Как вас зовут?",
|
||||||
"date_of_birth": "Дата рождения",
|
"date_of_birth": "Дата рождения",
|
||||||
|
"data_saved_successfully": "Data saved successfully",
|
||||||
"country": "Страна",
|
"country": "Страна",
|
||||||
"Russia": "Россия",
|
"Russia": "Россия",
|
||||||
"city": "Город",
|
"city": "Город",
|
||||||
@@ -837,5 +838,12 @@
|
|||||||
"video_call_recordings_period_week": "7 days",
|
"video_call_recordings_period_week": "7 days",
|
||||||
"video_call_recordings_period_current_month": "Current month",
|
"video_call_recordings_period_current_month": "Current month",
|
||||||
"video_call_recordings_period_prev_month": "Previous month",
|
"video_call_recordings_period_prev_month": "Previous month",
|
||||||
"video_call_recordings_period_all": "All time"
|
"video_call_recordings_period_all": "All time",
|
||||||
|
"rating_place": "#{place} in the ranking",
|
||||||
|
"@rating_place": {
|
||||||
|
"placeholders": {
|
||||||
|
"place": {"type": "int"}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"error_try_again_later": "Something went wrong. Please try again later."
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
"last_name": "Фамилия",
|
"last_name": "Фамилия",
|
||||||
"what_is_your_name": "Как вас зовут?",
|
"what_is_your_name": "Как вас зовут?",
|
||||||
"date_of_birth": "Дата рождения",
|
"date_of_birth": "Дата рождения",
|
||||||
|
"data_saved_successfully": "Данные успешно сохранены",
|
||||||
"country": "Страна",
|
"country": "Страна",
|
||||||
"Russia": "Россия",
|
"Russia": "Россия",
|
||||||
"city": "Город",
|
"city": "Город",
|
||||||
@@ -592,5 +593,12 @@
|
|||||||
"video_call_recordings_period_week": "7 дней",
|
"video_call_recordings_period_week": "7 дней",
|
||||||
"video_call_recordings_period_current_month": "Текущий месяц",
|
"video_call_recordings_period_current_month": "Текущий месяц",
|
||||||
"video_call_recordings_period_prev_month": "Прошлый месяц",
|
"video_call_recordings_period_prev_month": "Прошлый месяц",
|
||||||
"video_call_recordings_period_all": "Всё время"
|
"video_call_recordings_period_all": "Всё время",
|
||||||
|
"rating_place": "{place}-й в рейтинге",
|
||||||
|
"@rating_place": {
|
||||||
|
"placeholders": {
|
||||||
|
"place": {"type": "int"}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"error_try_again_later": "Произошла ошибка. Попробуйте ещё раз через некоторое время"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import 'package:flutter/rendering.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:intl/date_symbol_data_local.dart';
|
import 'package:intl/date_symbol_data_local.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
import 'package:table_calendar/table_calendar.dart';
|
import 'package:table_calendar/table_calendar.dart';
|
||||||
|
|
||||||
class FakeDiaryCubit extends Cubit<DiaryState> implements DiaryCubit {
|
class FakeDiaryCubit extends Cubit<DiaryState> implements DiaryCubit {
|
||||||
@@ -28,15 +29,20 @@ void main() {
|
|||||||
theme: ThemeHelper().themeData(),
|
theme: ThemeHelper().themeData(),
|
||||||
builder: (context, appChild) {
|
builder: (context, appChild) {
|
||||||
return MediaQuery(
|
return MediaQuery(
|
||||||
data: MediaQuery.of(context).copyWith(textScaler: TextScaler.linear(textScale)),
|
data: MediaQuery.of(
|
||||||
|
context,
|
||||||
|
).copyWith(textScaler: TextScaler.linear(textScale)),
|
||||||
child: appChild!,
|
child: appChild!,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
localizationsDelegates: const [S.delegate, ...GlobalMaterialLocalizations.delegates],
|
localizationsDelegates: const [
|
||||||
|
S.delegate,
|
||||||
|
...GlobalMaterialLocalizations.delegates,
|
||||||
|
],
|
||||||
supportedLocales: const [Locale('ru')],
|
supportedLocales: const [Locale('ru')],
|
||||||
home: BlocProvider<DiaryCubit>.value(
|
home: BlocProvider<DiaryCubit>.value(
|
||||||
value: cubit,
|
value: cubit,
|
||||||
child: Scaffold(body: child),
|
child: Scaffold(body: SingleChildScrollView(child: child)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -52,19 +58,124 @@ void main() {
|
|||||||
testWidgets('scales weekday row when system font is large', (tester) async {
|
testWidgets('scales weekday row when system font is large', (tester) async {
|
||||||
const textScale = 2.0;
|
const textScale = 2.0;
|
||||||
final cubit = FakeDiaryCubit(const DiaryState.loading());
|
final cubit = FakeDiaryCubit(const DiaryState.loading());
|
||||||
await tester.pumpWidget(wrap(const CalendarWidget(), cubit, textScale: textScale));
|
await tester.pumpWidget(
|
||||||
|
wrap(const CalendarWidget(), cubit, textScale: textScale),
|
||||||
|
);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
|
|
||||||
final calendar = tester.widget<TableCalendar<dynamic>>(find.byType(TableCalendar<dynamic>));
|
final calendar = tester.widget<TableCalendar<dynamic>>(
|
||||||
expect(calendar.daysOfWeekHeight, greaterThan(16 * textScale * 0.9));
|
find.byType(TableCalendar<dynamic>),
|
||||||
|
);
|
||||||
expect(calendar.rowHeight, 52 * textScale);
|
expect(calendar.rowHeight, 52 * textScale);
|
||||||
|
|
||||||
expect(find.text('пн'), findsWidgets);
|
expect(find.text('пн'), findsWidgets);
|
||||||
final weekday = tester.renderObject<RenderParagraph>(find.text('пн').first);
|
final weekday = tester.renderObject<RenderParagraph>(
|
||||||
expect(weekday.size.height, lessThanOrEqualTo(calendar.daysOfWeekHeight + 0.5));
|
find.text('пн').first,
|
||||||
|
);
|
||||||
|
expect(weekday.size.height, greaterThan(16 * textScale * 0.9));
|
||||||
|
expect(
|
||||||
|
tester.getBottomLeft(find.text('пн')).dy,
|
||||||
|
lessThanOrEqualTo(
|
||||||
|
tester.getTopLeft(find.byType(TableCalendar<dynamic>)).dy,
|
||||||
|
),
|
||||||
|
);
|
||||||
expect(tester.takeException(), isNull);
|
expect(tester.takeException(), isNull);
|
||||||
|
|
||||||
await cubit.close();
|
await cubit.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'header chevron switches directly between the focused week and month',
|
||||||
|
(tester) async {
|
||||||
|
final cubit = FakeDiaryCubit(const DiaryState.loading());
|
||||||
|
addTearDown(cubit.close);
|
||||||
|
final widget = find.byType(CalendarWidget);
|
||||||
|
final date = DateTime(2026, 11, 23);
|
||||||
|
await tester.pumpWidget(wrap(CalendarWidget(date: date), cubit));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
final header = find.text(DateFormat.yMMMM('ru_RU').format(date));
|
||||||
|
final weekHeight = tester.getSize(widget).height;
|
||||||
|
expect(find.text('23').hitTestable(), findsOneWidget);
|
||||||
|
expect(find.text('9').hitTestable(), findsNothing);
|
||||||
|
|
||||||
|
await tester.tap(find.byIcon(Icons.keyboard_arrow_down_rounded));
|
||||||
|
await tester.pump();
|
||||||
|
expect(header, findsOneWidget);
|
||||||
|
expect(tester.getSize(widget).height, weekHeight + 5 * 52);
|
||||||
|
expect(find.text('9').hitTestable(), findsOneWidget);
|
||||||
|
expect(find.text('23').hitTestable(), findsOneWidget);
|
||||||
|
|
||||||
|
await tester.tap(find.byIcon(Icons.keyboard_arrow_up_rounded));
|
||||||
|
await tester.pump();
|
||||||
|
expect(tester.getSize(widget).height, weekHeight);
|
||||||
|
expect(find.text('23').hitTestable(), findsOneWidget);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets('horizontal swipes still page by week and by month', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
final cubit = FakeDiaryCubit(const DiaryState.loading());
|
||||||
|
addTearDown(cubit.close);
|
||||||
|
await tester.pumpWidget(
|
||||||
|
wrap(CalendarWidget(date: DateTime(2026, 11, 23)), cubit),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
final days = find.byType(TableCalendar<dynamic>);
|
||||||
|
await tester.fling(days, const Offset(-450, 0), 1000);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('30').hitTestable(), findsOneWidget);
|
||||||
|
expect(find.text('23').hitTestable(), findsNothing);
|
||||||
|
|
||||||
|
await tester.tap(find.byIcon(Icons.keyboard_arrow_down_rounded));
|
||||||
|
await tester.pump();
|
||||||
|
await tester.fling(days, const Offset(-450, 0), 1000);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(
|
||||||
|
find.text(DateFormat.yMMMM('ru_RU').format(DateTime(2026, 12))),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'dragging the bottom handle resizes the calendar before release',
|
||||||
|
(tester) async {
|
||||||
|
final cubit = FakeDiaryCubit(const DiaryState.loading());
|
||||||
|
addTearDown(cubit.close);
|
||||||
|
final widget = find.byType(CalendarWidget);
|
||||||
|
await tester.pumpWidget(
|
||||||
|
wrap(CalendarWidget(date: DateTime(2026, 11, 23)), cubit),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
final weekBottom = tester.getBottomLeft(widget).dy;
|
||||||
|
final centerX = tester.getCenter(widget).dx;
|
||||||
|
final drag = await tester.startGesture(
|
||||||
|
Offset(centerX, weekBottom - 12),
|
||||||
|
);
|
||||||
|
await drag.moveBy(const Offset(0, 64));
|
||||||
|
await tester.pump();
|
||||||
|
expect(tester.getBottomLeft(widget).dy, closeTo(weekBottom + 64, 1));
|
||||||
|
expect(find.text('23').hitTestable(), findsOneWidget);
|
||||||
|
|
||||||
|
await drag.moveBy(const Offset(0, 100));
|
||||||
|
await drag.up();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
final monthBottom = weekBottom + 5 * 52;
|
||||||
|
expect(tester.getBottomLeft(widget).dy, closeTo(monthBottom, 1));
|
||||||
|
|
||||||
|
final reverse = await tester.startGesture(
|
||||||
|
Offset(centerX, monthBottom - 12),
|
||||||
|
);
|
||||||
|
await reverse.moveBy(const Offset(0, -160));
|
||||||
|
await tester.pump();
|
||||||
|
expect(tester.getBottomLeft(widget).dy, closeTo(monthBottom - 160, 1));
|
||||||
|
await reverse.up();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(tester.getBottomLeft(widget).dy, closeTo(weekBottom, 1));
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,194 @@
|
|||||||
|
import 'package:easy_debounce/easy_debounce.dart';
|
||||||
|
import 'package:eatvio_app/core/models/pagination_model.dart';
|
||||||
|
import 'package:eatvio_app/features/diets/repositories/diet_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||||
|
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
|
||||||
|
import 'package:eatvio_app/features/feed/presentation/bloc/plans_cubit/plans_cubit.dart';
|
||||||
|
import 'package:eatvio_app/features/feed/repositories/feed_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/plans/repositories/plan_repository.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:mockito/annotations.dart';
|
||||||
|
import 'package:mockito/mockito.dart';
|
||||||
|
import 'package:rxdart/rxdart.dart';
|
||||||
|
|
||||||
|
import 'plans_cubit_slug_sync_test.mocks.dart';
|
||||||
|
|
||||||
|
@GenerateNiceMocks([MockSpec<FeedRepository>(), MockSpec<PlanRepository>()])
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
group('feed PlansCubit — slug-based stream sync', () {
|
||||||
|
PlanModel plan({required String slug, int totalLikes = 10}) {
|
||||||
|
return PlanModel(
|
||||||
|
id: slug.hashCode,
|
||||||
|
slug: slug,
|
||||||
|
name: slug,
|
||||||
|
image: 'https://example.com/image.jpg',
|
||||||
|
duration: 7,
|
||||||
|
state: 'active',
|
||||||
|
type: const PlanType(
|
||||||
|
fit: true,
|
||||||
|
slim: false,
|
||||||
|
behavior: false,
|
||||||
|
wellness: false,
|
||||||
|
),
|
||||||
|
details: 'details',
|
||||||
|
packetsCount: 1,
|
||||||
|
minPriceOfOptions: 1000.0,
|
||||||
|
maxPriceOfOptions: 2000.0,
|
||||||
|
author: const Author(
|
||||||
|
authorSlug: 'author',
|
||||||
|
authorName: 'Author Name',
|
||||||
|
authorProfileIcon: 'https://example.com/icon.jpg',
|
||||||
|
authorIsMe: false,
|
||||||
|
isEntitySubscribedByMe: null,
|
||||||
|
authorPlaceInRating: null,
|
||||||
|
),
|
||||||
|
totalLikes: totalLikes,
|
||||||
|
totalViews: 100,
|
||||||
|
totalComments: 5,
|
||||||
|
wasLikedByMe: false,
|
||||||
|
isFavorite: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
PlanPaginationModel pagination(List<PlanModel> plans) {
|
||||||
|
return PlanPaginationModel(
|
||||||
|
data: plans,
|
||||||
|
links: const Links(
|
||||||
|
first: 'https://example.com?page=1',
|
||||||
|
last: 'https://example.com?page=1',
|
||||||
|
prev: null,
|
||||||
|
next: null,
|
||||||
|
),
|
||||||
|
meta: Meta(
|
||||||
|
currentPage: 1,
|
||||||
|
from: 1,
|
||||||
|
lastPage: 1,
|
||||||
|
links: const [],
|
||||||
|
perPage: 10,
|
||||||
|
to: plans.length,
|
||||||
|
total: plans.length,
|
||||||
|
totalMinPrice: 1000,
|
||||||
|
totalMaxPrice: 2000,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
late MockFeedRepository feedRepository;
|
||||||
|
late MockPlanRepository planRepository;
|
||||||
|
late BehaviorSubject<LikesState> likeState;
|
||||||
|
late BehaviorSubject<FavoriteState> favoriteState;
|
||||||
|
late BehaviorSubject<CommentsState> commentsState;
|
||||||
|
late PlansCubit cubit;
|
||||||
|
|
||||||
|
setUp(() async {
|
||||||
|
feedRepository = MockFeedRepository();
|
||||||
|
planRepository = MockPlanRepository();
|
||||||
|
likeState = BehaviorSubject<LikesState>();
|
||||||
|
favoriteState = BehaviorSubject<FavoriteState>();
|
||||||
|
commentsState = BehaviorSubject<CommentsState>();
|
||||||
|
|
||||||
|
when(planRepository.planLikeState).thenAnswer((_) => likeState);
|
||||||
|
when(planRepository.planFavoriteState).thenAnswer((_) => favoriteState);
|
||||||
|
when(planRepository.planCommentsState).thenAnswer((_) => commentsState);
|
||||||
|
|
||||||
|
when(
|
||||||
|
feedRepository.getPlans(
|
||||||
|
query: anyNamed('query'),
|
||||||
|
types: anyNamed('types'),
|
||||||
|
duration: anyNamed('duration'),
|
||||||
|
minPrice: anyNamed('minPrice'),
|
||||||
|
maxPrice: anyNamed('maxPrice'),
|
||||||
|
),
|
||||||
|
).thenAnswer(
|
||||||
|
(_) async => pagination([
|
||||||
|
plan(slug: 'plan-a'),
|
||||||
|
plan(slug: 'plan-b'),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
|
||||||
|
cubit = PlansCubit(
|
||||||
|
feedRepository: feedRepository,
|
||||||
|
planRepository: planRepository,
|
||||||
|
);
|
||||||
|
await cubit.loadPlans();
|
||||||
|
expect(cubit.state.plans.length, 2);
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() async {
|
||||||
|
EasyDebounce.cancel('loadPlans');
|
||||||
|
EasyDebounce.cancel('like_plan');
|
||||||
|
EasyDebounce.cancel('add_or_remove_plan_from_favorite');
|
||||||
|
if (!cubit.isClosed) {
|
||||||
|
await cubit.close();
|
||||||
|
}
|
||||||
|
await likeState.close();
|
||||||
|
await favoriteState.close();
|
||||||
|
await commentsState.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a like event with a slug updates the matching plan, not the index', () async {
|
||||||
|
likeState.add(
|
||||||
|
const LikesState(
|
||||||
|
slug: 'plan-b',
|
||||||
|
index: 0,
|
||||||
|
totalLikes: 42,
|
||||||
|
wasLikedByMe: true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||||
|
|
||||||
|
expect(cubit.state.plans[0].wasLikedByMe, isFalse);
|
||||||
|
expect(cubit.state.plans[0].totalLikes, 10);
|
||||||
|
expect(cubit.state.plans[1].wasLikedByMe, isTrue);
|
||||||
|
expect(cubit.state.plans[1].totalLikes, 42);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a like event with an unknown slug is a no-op', () async {
|
||||||
|
final before = cubit.state.plans;
|
||||||
|
|
||||||
|
likeState.add(
|
||||||
|
const LikesState(
|
||||||
|
slug: 'unknown-plan',
|
||||||
|
index: 0,
|
||||||
|
totalLikes: 42,
|
||||||
|
wasLikedByMe: true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||||
|
|
||||||
|
expect(cubit.state.plans, before);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a legacy like event without a slug keeps index behaviour', () async {
|
||||||
|
likeState.add(
|
||||||
|
const LikesState(index: 1, totalLikes: 42, wasLikedByMe: true),
|
||||||
|
);
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||||
|
|
||||||
|
expect(cubit.state.plans[1].wasLikedByMe, isTrue);
|
||||||
|
expect(cubit.state.plans[1].totalLikes, 42);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a favorite event with a slug updates the matching plan', () async {
|
||||||
|
favoriteState.add(
|
||||||
|
const FavoriteState(slug: 'plan-b', index: 0, isFavorite: true),
|
||||||
|
);
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||||
|
|
||||||
|
expect(cubit.state.plans[0].isFavorite, isFalse);
|
||||||
|
expect(cubit.state.plans[1].isFavorite, isTrue);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a comments event with a slug updates the matching plan', () async {
|
||||||
|
commentsState.add(
|
||||||
|
const CommentsState(slug: 'plan-b', index: 0, totalComments: 7),
|
||||||
|
);
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||||
|
|
||||||
|
expect(cubit.state.plans[0].totalComments, isNot(7));
|
||||||
|
expect(cubit.state.plans[1].totalComments, 7);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,172 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:easy_debounce/easy_debounce.dart';
|
||||||
|
import 'package:eatvio_app/core/models/pagination_model.dart';
|
||||||
|
import 'package:eatvio_app/features/diets/repositories/diet_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||||
|
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
|
||||||
|
import 'package:eatvio_app/features/feed/presentation/bloc/plans_cubit/plans_cubit.dart';
|
||||||
|
import 'package:eatvio_app/features/feed/repositories/feed_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/plans/repositories/plan_repository.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:mockito/annotations.dart';
|
||||||
|
import 'package:mockito/mockito.dart';
|
||||||
|
import 'package:rxdart/rxdart.dart';
|
||||||
|
|
||||||
|
import 'plans_cubit_sync_guard_test.mocks.dart';
|
||||||
|
|
||||||
|
@GenerateNiceMocks([MockSpec<FeedRepository>(), MockSpec<PlanRepository>()])
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
group('feed PlansCubit — index bounds guard', () {
|
||||||
|
const testPlan = 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,
|
||||||
|
minPriceOfOptions: 1000.0,
|
||||||
|
maxPriceOfOptions: 2000.0,
|
||||||
|
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,
|
||||||
|
wasLikedByMe: false,
|
||||||
|
isFavorite: false,
|
||||||
|
);
|
||||||
|
|
||||||
|
const plansPagination = PlanPaginationModel(
|
||||||
|
data: [testPlan],
|
||||||
|
links: Links(
|
||||||
|
first: 'https://example.com?page=1',
|
||||||
|
last: 'https://example.com?page=1',
|
||||||
|
prev: null,
|
||||||
|
next: null,
|
||||||
|
),
|
||||||
|
meta: Meta(
|
||||||
|
currentPage: 1,
|
||||||
|
from: 1,
|
||||||
|
lastPage: 1,
|
||||||
|
links: [],
|
||||||
|
perPage: 10,
|
||||||
|
to: 1,
|
||||||
|
total: 1,
|
||||||
|
totalMinPrice: 1000,
|
||||||
|
totalMaxPrice: 2000,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
late MockFeedRepository feedRepository;
|
||||||
|
late MockPlanRepository planRepository;
|
||||||
|
late BehaviorSubject<LikesState> likeState;
|
||||||
|
late BehaviorSubject<FavoriteState> favoriteState;
|
||||||
|
late BehaviorSubject<CommentsState> commentsState;
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
feedRepository = MockFeedRepository();
|
||||||
|
planRepository = MockPlanRepository();
|
||||||
|
likeState = BehaviorSubject<LikesState>();
|
||||||
|
favoriteState = BehaviorSubject<FavoriteState>();
|
||||||
|
commentsState = BehaviorSubject<CommentsState>();
|
||||||
|
|
||||||
|
when(planRepository.planLikeState).thenAnswer((_) => likeState);
|
||||||
|
when(planRepository.planFavoriteState).thenAnswer((_) => favoriteState);
|
||||||
|
when(planRepository.planCommentsState).thenAnswer((_) => commentsState);
|
||||||
|
|
||||||
|
when(
|
||||||
|
feedRepository.getPlans(
|
||||||
|
query: anyNamed('query'),
|
||||||
|
types: anyNamed('types'),
|
||||||
|
duration: anyNamed('duration'),
|
||||||
|
minPrice: anyNamed('minPrice'),
|
||||||
|
maxPrice: anyNamed('maxPrice'),
|
||||||
|
),
|
||||||
|
).thenAnswer((_) async => plansPagination);
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() async {
|
||||||
|
EasyDebounce.cancel('loadPlans');
|
||||||
|
EasyDebounce.cancel('like_plan');
|
||||||
|
EasyDebounce.cancel('add_or_remove_plan_from_favorite');
|
||||||
|
await likeState.close();
|
||||||
|
await favoriteState.close();
|
||||||
|
await commentsState.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
/// Runs [body] in its own error zone so an unhandled stream-listener error
|
||||||
|
/// is captured instead of failing the test at teardown.
|
||||||
|
Future<List<Object>> errorsFrom(Future<void> Function() body) async {
|
||||||
|
final errors = <Object>[];
|
||||||
|
final done = Completer<void>();
|
||||||
|
runZonedGuarded(
|
||||||
|
() async {
|
||||||
|
try {
|
||||||
|
await body();
|
||||||
|
} finally {
|
||||||
|
done.complete();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(error, stackTrace) => errors.add(error),
|
||||||
|
);
|
||||||
|
await done.future;
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<PlansCubit> loadedCubit() async {
|
||||||
|
final cubit = PlansCubit(
|
||||||
|
feedRepository: feedRepository,
|
||||||
|
planRepository: planRepository,
|
||||||
|
);
|
||||||
|
await cubit.loadPlans();
|
||||||
|
expect(cubit.state.plans.length, 1);
|
||||||
|
return cubit;
|
||||||
|
}
|
||||||
|
|
||||||
|
test('an out-of-range like event is ignored instead of throwing', () async {
|
||||||
|
final errors = await errorsFrom(() async {
|
||||||
|
final cubit = await loadedCubit();
|
||||||
|
likeState.add(
|
||||||
|
const LikesState(index: 5, totalLikes: 99, wasLikedByMe: true),
|
||||||
|
);
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||||
|
await cubit.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(errors, isEmpty);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an out-of-range favorite event is ignored instead of throwing', () async {
|
||||||
|
final errors = await errorsFrom(() async {
|
||||||
|
final cubit = await loadedCubit();
|
||||||
|
favoriteState.add(const FavoriteState(index: 5, isFavorite: true));
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||||
|
await cubit.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(errors, isEmpty);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an out-of-range comments event is ignored instead of throwing', () async {
|
||||||
|
final errors = await errorsFrom(() async {
|
||||||
|
final cubit = await loadedCubit();
|
||||||
|
commentsState.add(const CommentsState(index: 5, totalComments: 99));
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||||
|
await cubit.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(errors, isEmpty);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:eatvio_app/core/error_reporting/error_reporter.dart';
|
||||||
|
import 'package:eatvio_app/core/locator_service.dart';
|
||||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||||
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
|
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
|
||||||
|
import 'package:eatvio_app/features/plans/repositories/plan_repository.dart';
|
||||||
import 'package:eatvio_app/features/plans/repositories/plans_repository.dart';
|
import 'package:eatvio_app/features/plans/repositories/plans_repository.dart';
|
||||||
import 'package:eatvio_app/features/profile/presentation/bloc/plans_cubit/plans_cubit.dart';
|
import 'package:eatvio_app/features/profile/presentation/bloc/plans_cubit/plans_cubit.dart';
|
||||||
import 'package:eatvio_app/features/profile/presentation/bloc/plans_cubit/plans_state.dart';
|
import 'package:eatvio_app/features/profile/presentation/bloc/plans_cubit/plans_state.dart';
|
||||||
@@ -9,14 +14,34 @@ import 'package:mockito/mockito.dart';
|
|||||||
|
|
||||||
import 'plans_cubit_test.mocks.dart';
|
import 'plans_cubit_test.mocks.dart';
|
||||||
|
|
||||||
@GenerateNiceMocks([MockSpec<PlansRepository>()])
|
class _RecordingErrorReporter implements ErrorReporter {
|
||||||
|
final List<Object> errors = [];
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> report(
|
||||||
|
Object error,
|
||||||
|
StackTrace? stackTrace, {
|
||||||
|
String? origin,
|
||||||
|
Map<String, Object?>? extras,
|
||||||
|
}) async {
|
||||||
|
errors.add(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GenerateNiceMocks([MockSpec<PlansRepository>(), MockSpec<PlanRepository>()])
|
||||||
void main() {
|
void main() {
|
||||||
group('PlansCubit', () {
|
group('PlansCubit', () {
|
||||||
PlansCubit? cubit;
|
PlansCubit? cubit;
|
||||||
late MockPlansRepository mockRepository;
|
late MockPlansRepository mockRepository;
|
||||||
|
late MockPlanRepository mockPlanRepository;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() async {
|
||||||
|
await sl.reset();
|
||||||
mockRepository = MockPlansRepository();
|
mockRepository = MockPlansRepository();
|
||||||
|
mockPlanRepository = MockPlanRepository();
|
||||||
|
when(mockPlanRepository.planLikeState).thenAnswer((_) => const Stream.empty());
|
||||||
|
when(mockPlanRepository.planFavoriteState).thenAnswer((_) => const Stream.empty());
|
||||||
|
when(mockPlanRepository.planCommentsState).thenAnswer((_) => const Stream.empty());
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
@@ -24,16 +49,23 @@ void main() {
|
|||||||
await cubit!.close();
|
await cubit!.close();
|
||||||
cubit = null;
|
cubit = null;
|
||||||
}
|
}
|
||||||
|
await sl.reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('начальное состояние - пустое', () {
|
test('начальное состояние - пустое', () {
|
||||||
cubit = PlansCubit(plansRepository: mockRepository);
|
cubit = PlansCubit(
|
||||||
|
plansRepository: mockRepository,
|
||||||
|
planRepository: mockPlanRepository,
|
||||||
|
);
|
||||||
|
|
||||||
expect(cubit!.state, isA<PlansState>());
|
expect(cubit!.state, isA<PlansState>());
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getPlans - успешная загрузка планов', () async {
|
test('getPlans - успешная загрузка планов', () async {
|
||||||
cubit = PlansCubit(plansRepository: mockRepository);
|
cubit = PlansCubit(
|
||||||
|
plansRepository: mockRepository,
|
||||||
|
planRepository: mockPlanRepository,
|
||||||
|
);
|
||||||
|
|
||||||
final testPlans = [
|
final testPlans = [
|
||||||
const PlanModel(
|
const PlanModel(
|
||||||
@@ -75,7 +107,10 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('getPlans - обработка ошибки', () async {
|
test('getPlans - обработка ошибки', () async {
|
||||||
cubit = PlansCubit(plansRepository: mockRepository);
|
cubit = PlansCubit(
|
||||||
|
plansRepository: mockRepository,
|
||||||
|
planRepository: mockPlanRepository,
|
||||||
|
);
|
||||||
|
|
||||||
when(mockRepository.getPlansBySlug(any))
|
when(mockRepository.getPlansBySlug(any))
|
||||||
.thenThrow(Exception('Ошибка загрузки'));
|
.thenThrow(Exception('Ошибка загрузки'));
|
||||||
@@ -84,6 +119,33 @@ void main() {
|
|||||||
|
|
||||||
expect(cubit!.state, isA<PlansStateError>());
|
expect(cubit!.state, isA<PlansStateError>());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('getPlans - close during request does not emit loaded or report an error', () async {
|
||||||
|
final reporter = _RecordingErrorReporter();
|
||||||
|
sl.registerSingleton<ErrorReporter>(reporter);
|
||||||
|
|
||||||
|
cubit = PlansCubit(
|
||||||
|
plansRepository: mockRepository,
|
||||||
|
planRepository: mockPlanRepository,
|
||||||
|
);
|
||||||
|
|
||||||
|
final response = Completer<List<PlanModel>>();
|
||||||
|
when(mockRepository.getPlansBySlug('test-user'))
|
||||||
|
.thenAnswer((_) => response.future);
|
||||||
|
|
||||||
|
final emitted = <PlansState>[];
|
||||||
|
final subscription = cubit!.stream.listen(emitted.add);
|
||||||
|
|
||||||
|
final request = cubit!.getPlans('test-user');
|
||||||
|
await cubit!.close();
|
||||||
|
response.complete(const <PlanModel>[]);
|
||||||
|
await request;
|
||||||
|
await subscription.cancel();
|
||||||
|
|
||||||
|
expect(emitted.whereType<PlansStateLoaded>(), isEmpty);
|
||||||
|
expect(emitted.whereType<PlansStateError>(), isEmpty);
|
||||||
|
expect(reporter.errors, isEmpty);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,366 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:ui' show Locale;
|
||||||
|
|
||||||
|
import 'package:easy_debounce/easy_debounce.dart';
|
||||||
|
import 'package:eatvio_app/core/error_reporting/error_reporter.dart';
|
||||||
|
import 'package:eatvio_app/core/locator_service.dart';
|
||||||
|
import 'package:eatvio_app/features/diets/repositories/diet_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
|
||||||
|
import 'package:eatvio_app/features/plans/repositories/plan_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/plans/repositories/plans_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/presentation/bloc/plans_cubit/plans_cubit.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/presentation/bloc/plans_cubit/plans_state.dart';
|
||||||
|
import 'package:eatvio_app/generated/l10n.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:mockito/annotations.dart';
|
||||||
|
import 'package:mockito/mockito.dart';
|
||||||
|
import 'package:rxdart/rxdart.dart';
|
||||||
|
|
||||||
|
import '../../../../../fixtures/fixture_reader.dart';
|
||||||
|
import 'profile_plans_cubit_like_test.mocks.dart';
|
||||||
|
|
||||||
|
@GenerateNiceMocks([MockSpec<PlansRepository>(), MockSpec<PlanRepository>()])
|
||||||
|
class _RecordingReporter implements ErrorReporter {
|
||||||
|
final List<Object> errors = [];
|
||||||
|
Object? lastError;
|
||||||
|
StackTrace? lastStack;
|
||||||
|
String? lastOrigin;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> report(
|
||||||
|
Object error,
|
||||||
|
StackTrace? stackTrace, {
|
||||||
|
String? origin,
|
||||||
|
Map<String, Object?>? extras,
|
||||||
|
}) async {
|
||||||
|
errors.add(error);
|
||||||
|
lastError = error;
|
||||||
|
lastStack = stackTrace;
|
||||||
|
lastOrigin = origin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
group('profile PlansCubit — like/favorite', () {
|
||||||
|
late MockPlansRepository plansRepository;
|
||||||
|
late MockPlanRepository planRepository;
|
||||||
|
late PlansCubit cubit;
|
||||||
|
late _RecordingReporter reporter;
|
||||||
|
late List<MethodCall> toastCalls;
|
||||||
|
|
||||||
|
const slugA = 'plan-a';
|
||||||
|
const slugB = 'plan-b';
|
||||||
|
|
||||||
|
PlanModel plan({
|
||||||
|
String slug = slugA,
|
||||||
|
bool wasLikedByMe = false,
|
||||||
|
bool isFavorite = false,
|
||||||
|
int totalLikes = 10,
|
||||||
|
}) {
|
||||||
|
return PlanModel.fromJson(
|
||||||
|
FixtureReader.readAsMap('plans/plan_response.json'),
|
||||||
|
).copyWith(
|
||||||
|
slug: slug,
|
||||||
|
state: 'active',
|
||||||
|
wasLikedByMe: wasLikedByMe,
|
||||||
|
isFavorite: isFavorite,
|
||||||
|
totalLikes: totalLikes,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
setUpAll(() async {
|
||||||
|
await S.load(const Locale('ru'));
|
||||||
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||||
|
.setMockMethodCallHandler(
|
||||||
|
const MethodChannel('PonnamKarthik/fluttertoast'),
|
||||||
|
(MethodCall methodCall) async {
|
||||||
|
toastCalls.add(methodCall);
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
setUp(() async {
|
||||||
|
await sl.reset();
|
||||||
|
reporter = _RecordingReporter();
|
||||||
|
sl.registerSingleton<ErrorReporter>(reporter);
|
||||||
|
toastCalls = <MethodCall>[];
|
||||||
|
|
||||||
|
plansRepository = MockPlansRepository();
|
||||||
|
planRepository = MockPlanRepository();
|
||||||
|
|
||||||
|
when(
|
||||||
|
planRepository.planLikeState,
|
||||||
|
).thenAnswer((_) => BehaviorSubject<LikesState>());
|
||||||
|
when(
|
||||||
|
planRepository.planFavoriteState,
|
||||||
|
).thenAnswer((_) => BehaviorSubject<FavoriteState>());
|
||||||
|
when(
|
||||||
|
planRepository.planCommentsState,
|
||||||
|
).thenAnswer((_) => BehaviorSubject<CommentsState>());
|
||||||
|
|
||||||
|
cubit = PlansCubit(
|
||||||
|
plansRepository: plansRepository,
|
||||||
|
planRepository: planRepository,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() async {
|
||||||
|
EasyDebounce.cancel('profile_like_plan_$slugA');
|
||||||
|
EasyDebounce.cancel('profile_like_plan_$slugB');
|
||||||
|
EasyDebounce.cancel('profile_favorite_$slugA');
|
||||||
|
EasyDebounce.cancel('profile_favorite_$slugB');
|
||||||
|
if (!cubit.isClosed) {
|
||||||
|
await cubit.close();
|
||||||
|
}
|
||||||
|
await sl.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
Future<void> load(List<PlanModel> plans) async {
|
||||||
|
when(plansRepository.getPlansBySlug(any)).thenAnswer((_) async => plans);
|
||||||
|
await cubit.getPlans('consultant');
|
||||||
|
expect(cubit.state, isA<PlansStateLoaded>());
|
||||||
|
}
|
||||||
|
|
||||||
|
PlansStateLoaded loaded() => cubit.state as PlansStateLoaded;
|
||||||
|
|
||||||
|
test(
|
||||||
|
'likePlan adds a like optimistically and calls the repository once',
|
||||||
|
() async {
|
||||||
|
await load([plan()]);
|
||||||
|
|
||||||
|
await cubit.likePlan(slugA);
|
||||||
|
|
||||||
|
expect(loaded().plansList.single.wasLikedByMe, isTrue);
|
||||||
|
expect(loaded().plansList.single.totalLikes, 11);
|
||||||
|
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 1200));
|
||||||
|
verify(planRepository.likePlan(slugA)).called(1);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test('likePlan removes an existing like optimistically', () async {
|
||||||
|
await load([plan(wasLikedByMe: true, totalLikes: 10)]);
|
||||||
|
|
||||||
|
await cubit.likePlan(slugA);
|
||||||
|
|
||||||
|
expect(loaded().plansList.single.wasLikedByMe, isFalse);
|
||||||
|
expect(loaded().plansList.single.totalLikes, 9);
|
||||||
|
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 1200));
|
||||||
|
verify(planRepository.likePlan(slugA)).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'likePlan rolls back the optimistic change when the repository fails',
|
||||||
|
() async {
|
||||||
|
when(planRepository.likePlan(any)).thenThrow(Exception('network'));
|
||||||
|
await load([plan()]);
|
||||||
|
|
||||||
|
await cubit.likePlan(slugA);
|
||||||
|
expect(loaded().plansList.single.wasLikedByMe, isTrue);
|
||||||
|
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 1200));
|
||||||
|
|
||||||
|
expect(loaded().plansList.single.wasLikedByMe, isFalse);
|
||||||
|
expect(loaded().plansList.single.totalLikes, 10);
|
||||||
|
verify(planRepository.likePlan(slugA)).called(1);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'likePlan does nothing when the slug is not in the loaded list',
|
||||||
|
() async {
|
||||||
|
await load([plan()]);
|
||||||
|
final before = loaded().plansList;
|
||||||
|
|
||||||
|
await cubit.likePlan('missing-plan');
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 1200));
|
||||||
|
|
||||||
|
expect(loaded().plansList, before);
|
||||||
|
verifyNever(planRepository.likePlan(any));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test('likePlan does nothing when state is not loaded', () async {
|
||||||
|
await cubit.likePlan(slugA);
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 1200));
|
||||||
|
|
||||||
|
expect(cubit.state, isNot(isA<PlansStateLoaded>()));
|
||||||
|
verifyNever(planRepository.likePlan(any));
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'likePlan debounces repeated taps on the same slug into one request',
|
||||||
|
() async {
|
||||||
|
await load([plan()]);
|
||||||
|
|
||||||
|
await cubit.likePlan(slugA);
|
||||||
|
await cubit.likePlan(slugA);
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 1200));
|
||||||
|
|
||||||
|
verify(planRepository.likePlan(slugA)).called(1);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test('likePlan keeps a separate debounce per slug', () async {
|
||||||
|
await load([plan(slug: slugA), plan(slug: slugB)]);
|
||||||
|
|
||||||
|
await cubit.likePlan(slugA);
|
||||||
|
await cubit.likePlan(slugB);
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 1200));
|
||||||
|
|
||||||
|
verify(planRepository.likePlan(slugA)).called(1);
|
||||||
|
verify(planRepository.likePlan(slugB)).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'addPlanToFavorite sets favorite optimistically and calls the repository',
|
||||||
|
() async {
|
||||||
|
await load([plan()]);
|
||||||
|
|
||||||
|
await cubit.addPlanToFavorite(slugA);
|
||||||
|
|
||||||
|
expect(loaded().plansList.single.isFavorite, isTrue);
|
||||||
|
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 1200));
|
||||||
|
verify(planRepository.addToFavorite(slugA)).called(1);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test('addPlanToFavorite rolls back when the repository fails', () async {
|
||||||
|
when(planRepository.addToFavorite(any)).thenThrow(Exception('network'));
|
||||||
|
await load([plan()]);
|
||||||
|
|
||||||
|
await cubit.addPlanToFavorite(slugA);
|
||||||
|
expect(loaded().plansList.single.isFavorite, isTrue);
|
||||||
|
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 1200));
|
||||||
|
|
||||||
|
expect(loaded().plansList.single.isFavorite, isFalse);
|
||||||
|
verify(planRepository.addToFavorite(slugA)).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'removePlanFromFavorite clears favorite optimistically and calls the repository',
|
||||||
|
() async {
|
||||||
|
await load([plan(isFavorite: true)]);
|
||||||
|
|
||||||
|
await cubit.removePlanFromFavorite(slugA);
|
||||||
|
|
||||||
|
expect(loaded().plansList.single.isFavorite, isFalse);
|
||||||
|
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 1200));
|
||||||
|
verify(planRepository.removeFromFavorite(slugA)).called(1);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'favorite actions do nothing when the slug is not in the loaded list',
|
||||||
|
() async {
|
||||||
|
await load([plan()]);
|
||||||
|
final before = loaded().plansList;
|
||||||
|
|
||||||
|
await cubit.addPlanToFavorite('missing-plan');
|
||||||
|
await cubit.removePlanFromFavorite('missing-plan');
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 1200));
|
||||||
|
|
||||||
|
expect(loaded().plansList, before);
|
||||||
|
verifyNever(planRepository.addToFavorite(any));
|
||||||
|
verifyNever(planRepository.removeFromFavorite(any));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test('close cancels a pending like request', () async {
|
||||||
|
await load([plan()]);
|
||||||
|
|
||||||
|
await cubit.likePlan(slugA);
|
||||||
|
await cubit.close();
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 1200));
|
||||||
|
|
||||||
|
verifyNever(planRepository.likePlan(any));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a debounced failure after close does not emit or throw', () async {
|
||||||
|
when(planRepository.likePlan(any)).thenAnswer((_) async {
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 50));
|
||||||
|
throw Exception('network');
|
||||||
|
});
|
||||||
|
await load([plan()]);
|
||||||
|
|
||||||
|
await cubit.likePlan(slugA);
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 300));
|
||||||
|
await cubit.close();
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 300));
|
||||||
|
|
||||||
|
expect(cubit.isClosed, isTrue);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'a like that fails after close neither emits after close nor leaks a zone error',
|
||||||
|
() async {
|
||||||
|
await load([plan()]);
|
||||||
|
|
||||||
|
final zoneErrors = <Object>[];
|
||||||
|
|
||||||
|
await runZonedGuarded(() async {
|
||||||
|
final pending = Completer<void>();
|
||||||
|
when(planRepository.likePlan(any)).thenAnswer((_) => pending.future);
|
||||||
|
|
||||||
|
await cubit.likePlan(slugA);
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 250));
|
||||||
|
verify(planRepository.likePlan(slugA)).called(1);
|
||||||
|
await cubit.close();
|
||||||
|
pending.completeError(Exception('network'));
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||||
|
}, (error, stackTrace) {
|
||||||
|
zoneErrors.add(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(cubit.isClosed, isTrue);
|
||||||
|
expect(
|
||||||
|
zoneErrors.whereType<StateError>().where(
|
||||||
|
(error) => error.message.contains('Cannot emit new states after calling close'),
|
||||||
|
),
|
||||||
|
isEmpty,
|
||||||
|
);
|
||||||
|
expect(zoneErrors, isEmpty, reason: 'errors in zone: $zoneErrors');
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'addPlanToFavorite rolls back and shows an error toast when the repository fails',
|
||||||
|
() async {
|
||||||
|
when(planRepository.addToFavorite(any)).thenThrow(Exception('network'));
|
||||||
|
await load([plan()]);
|
||||||
|
|
||||||
|
await cubit.addPlanToFavorite(slugA);
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 1200));
|
||||||
|
|
||||||
|
expect(loaded().plansList.single.isFavorite, isFalse);
|
||||||
|
|
||||||
|
final showToastCalls = toastCalls.where((call) => call.method == 'showToast').toList();
|
||||||
|
expect(showToastCalls, isNotEmpty);
|
||||||
|
final arguments = showToastCalls.single.arguments as Map;
|
||||||
|
expect(arguments['msg'], contains('Произошла ошибка'));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test('likePlan reports the failure through ErrorReporter', () async {
|
||||||
|
final error = Exception('network');
|
||||||
|
when(planRepository.likePlan(any)).thenThrow(error);
|
||||||
|
await load([plan()]);
|
||||||
|
|
||||||
|
await cubit.likePlan(slugA);
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 1200));
|
||||||
|
|
||||||
|
expect(reporter.errors, isNotEmpty);
|
||||||
|
expect(reporter.lastError, same(error));
|
||||||
|
expect(reporter.lastOrigin, 'PlansCubit');
|
||||||
|
expect(reporter.lastOrigin, isNotEmpty);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
import 'package:easy_debounce/easy_debounce.dart';
|
||||||
|
import 'package:eatvio_app/features/diets/repositories/diet_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
|
||||||
|
import 'package:eatvio_app/features/plans/repositories/plan_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/plans/repositories/plans_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/presentation/bloc/plans_cubit/plans_cubit.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/presentation/bloc/plans_cubit/plans_state.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:mockito/annotations.dart';
|
||||||
|
import 'package:mockito/mockito.dart';
|
||||||
|
import 'package:rxdart/rxdart.dart';
|
||||||
|
|
||||||
|
import '../../../../../fixtures/fixture_reader.dart';
|
||||||
|
import 'profile_plans_cubit_slug_sync_test.mocks.dart';
|
||||||
|
|
||||||
|
@GenerateNiceMocks([MockSpec<PlansRepository>(), MockSpec<PlanRepository>()])
|
||||||
|
void main() {
|
||||||
|
group('profile PlansCubit — slug-based stream sync', () {
|
||||||
|
late MockPlansRepository plansRepository;
|
||||||
|
late MockPlanRepository planRepository;
|
||||||
|
late BehaviorSubject<LikesState> likeState;
|
||||||
|
late BehaviorSubject<FavoriteState> favoriteState;
|
||||||
|
late BehaviorSubject<CommentsState> commentsState;
|
||||||
|
late PlansCubit cubit;
|
||||||
|
|
||||||
|
PlanModel plan({required String slug, int totalLikes = 10}) {
|
||||||
|
return PlanModel.fromJson(
|
||||||
|
FixtureReader.readAsMap('plans/plan_response.json'),
|
||||||
|
).copyWith(
|
||||||
|
slug: slug,
|
||||||
|
state: 'active',
|
||||||
|
wasLikedByMe: false,
|
||||||
|
isFavorite: false,
|
||||||
|
totalLikes: totalLikes,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
setUp(() async {
|
||||||
|
plansRepository = MockPlansRepository();
|
||||||
|
planRepository = MockPlanRepository();
|
||||||
|
likeState = BehaviorSubject<LikesState>();
|
||||||
|
favoriteState = BehaviorSubject<FavoriteState>();
|
||||||
|
commentsState = BehaviorSubject<CommentsState>();
|
||||||
|
|
||||||
|
when(planRepository.planLikeState).thenAnswer((_) => likeState);
|
||||||
|
when(planRepository.planFavoriteState).thenAnswer((_) => favoriteState);
|
||||||
|
when(planRepository.planCommentsState).thenAnswer((_) => commentsState);
|
||||||
|
|
||||||
|
cubit = PlansCubit(
|
||||||
|
plansRepository: plansRepository,
|
||||||
|
planRepository: planRepository,
|
||||||
|
);
|
||||||
|
|
||||||
|
when(
|
||||||
|
plansRepository.getPlansBySlug(any),
|
||||||
|
).thenAnswer((_) async => [plan(slug: 'plan-a'), plan(slug: 'plan-b')]);
|
||||||
|
await cubit.getPlans('consultant');
|
||||||
|
expect(cubit.state, isA<PlansStateLoaded>());
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() async {
|
||||||
|
EasyDebounce.cancel('profile_like_plan_plan-a');
|
||||||
|
EasyDebounce.cancel('profile_like_plan_plan-b');
|
||||||
|
if (!cubit.isClosed) {
|
||||||
|
await cubit.close();
|
||||||
|
}
|
||||||
|
await likeState.close();
|
||||||
|
await favoriteState.close();
|
||||||
|
await commentsState.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
PlansStateLoaded loaded() => cubit.state as PlansStateLoaded;
|
||||||
|
|
||||||
|
test('a like event with a slug updates only the matching plan', () async {
|
||||||
|
likeState.add(
|
||||||
|
const LikesState(
|
||||||
|
slug: 'plan-b',
|
||||||
|
totalLikes: 42,
|
||||||
|
wasLikedByMe: true,
|
||||||
|
index: 0,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||||
|
|
||||||
|
expect(loaded().plansList[0].wasLikedByMe, isFalse);
|
||||||
|
expect(loaded().plansList[0].totalLikes, 10);
|
||||||
|
expect(loaded().plansList[1].wasLikedByMe, isTrue);
|
||||||
|
expect(loaded().plansList[1].totalLikes, 42);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a like event with an unknown slug is a no-op', () async {
|
||||||
|
final before = loaded().plansList;
|
||||||
|
|
||||||
|
likeState.add(
|
||||||
|
const LikesState(
|
||||||
|
slug: 'unknown-plan',
|
||||||
|
totalLikes: 42,
|
||||||
|
wasLikedByMe: true,
|
||||||
|
index: 0,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||||
|
|
||||||
|
expect(loaded().plansList, before);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a favorite event with a slug updates only the matching plan', () async {
|
||||||
|
favoriteState.add(
|
||||||
|
const FavoriteState(slug: 'plan-b', isFavorite: true, index: 0),
|
||||||
|
);
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||||
|
|
||||||
|
expect(loaded().plansList[0].isFavorite, isFalse);
|
||||||
|
expect(loaded().plansList[1].isFavorite, isTrue);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a comments event with a slug updates only the matching plan', () async {
|
||||||
|
commentsState.add(
|
||||||
|
const CommentsState(slug: 'plan-b', totalComments: 7, index: 0),
|
||||||
|
);
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||||
|
|
||||||
|
expect(loaded().plansList[0].totalComments, isNot(7));
|
||||||
|
expect(loaded().plansList[1].totalComments, 7);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
import 'package:eatvio_app/features/chat/repositories/chat_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/consultant/become_consultant/models/consultant_cert_photo_model.dart';
|
||||||
|
import 'package:eatvio_app/features/consultant/become_consultant/models/consultation_request_model.dart';
|
||||||
|
import 'package:eatvio_app/features/consultant/become_consultant/repositories/consultant_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_state.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:mockito/annotations.dart';
|
||||||
|
|
||||||
|
import '../../../../../fixtures/feed_fixtures.dart';
|
||||||
|
import 'profile_cubit_update_feed_regression_test.mocks.dart';
|
||||||
|
|
||||||
|
@GenerateNiceMocks([
|
||||||
|
MockSpec<ProfileRepository>(),
|
||||||
|
MockSpec<ChatRepository>(),
|
||||||
|
MockSpec<ConsultantRepository>(),
|
||||||
|
])
|
||||||
|
void main() {
|
||||||
|
group('ProfileCubit.updateFeedBlogPostList — regression #700', () {
|
||||||
|
late ProfileCubit cubit;
|
||||||
|
|
||||||
|
const profile = ProfileModel(
|
||||||
|
id: 1,
|
||||||
|
name: 'Consultant',
|
||||||
|
email: 'c@e.com',
|
||||||
|
phoneConfirmationState: 'confirmed',
|
||||||
|
slug: 'consultant',
|
||||||
|
isPublicProfile: true,
|
||||||
|
isBlockedByMe: false,
|
||||||
|
isBlockedByAuthor: false,
|
||||||
|
isBlockedByUser: false,
|
||||||
|
isEntitySubscribedByMe: false,
|
||||||
|
profilePhotoUrl: '',
|
||||||
|
roles: ['consultant'],
|
||||||
|
badges: [],
|
||||||
|
subscriptions: [],
|
||||||
|
subscribers: [],
|
||||||
|
);
|
||||||
|
|
||||||
|
const details = ProfileDetailsModel(
|
||||||
|
firstName: 'Test',
|
||||||
|
lastName: 'User',
|
||||||
|
birthdate: '1990-01-01',
|
||||||
|
gender: 'male',
|
||||||
|
country: 'Russia',
|
||||||
|
city: 'Moscow',
|
||||||
|
lang: 'ru',
|
||||||
|
weight: 70.0,
|
||||||
|
height: 175,
|
||||||
|
chestCircumference: 100,
|
||||||
|
waistCircumference: 80,
|
||||||
|
hipCircumference: 90,
|
||||||
|
bloodPressureUp: 120,
|
||||||
|
bloodPressureDown: 80,
|
||||||
|
hasHypo: false,
|
||||||
|
hasHyper: false,
|
||||||
|
aboutAlergy: '',
|
||||||
|
aboutTakingPils: '',
|
||||||
|
aboutSportHobbies: '',
|
||||||
|
favoriteFoods: '',
|
||||||
|
unfavoriteFoods: '',
|
||||||
|
additionalInfo: '',
|
||||||
|
isMoodFillable: true,
|
||||||
|
isBedtimeFillable: true,
|
||||||
|
activityCoefficient: 1.5,
|
||||||
|
);
|
||||||
|
|
||||||
|
const consultantInfo = ConsultationRequestModel(
|
||||||
|
ratingPlace: 3,
|
||||||
|
educationModel: EducationModel(
|
||||||
|
hasMedicalEducation: 1,
|
||||||
|
completedCourses: null,
|
||||||
|
requestState: ModerationStatus.approved,
|
||||||
|
),
|
||||||
|
photos: [],
|
||||||
|
);
|
||||||
|
|
||||||
|
const certPhotos = [
|
||||||
|
ConsultantCertPhotoModel(
|
||||||
|
id: 7,
|
||||||
|
group: ConsultantCertPhotoModel.visibleGroup,
|
||||||
|
originalName: 'cert.jpg',
|
||||||
|
path: 'cert.jpg',
|
||||||
|
size: 100,
|
||||||
|
url: 'https://example.com/cert.jpg',
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
cubit = ProfileCubit(
|
||||||
|
profileRepository: MockProfileRepository(),
|
||||||
|
chatRepository: MockChatRepository(),
|
||||||
|
consultantRepository: MockConsultantRepository(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() async {
|
||||||
|
if (!cubit.isClosed) {
|
||||||
|
await cubit.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('preserves consultantInfo, certPhotos and isMyProfile on like emit', () {
|
||||||
|
final post = FeedFixtures.feedBlogPostModel().copyWith(
|
||||||
|
wasLikedByMe: false,
|
||||||
|
totalLikes: 10,
|
||||||
|
);
|
||||||
|
cubit.emit(
|
||||||
|
ProfileState.loaded(
|
||||||
|
profile: profile,
|
||||||
|
profileDetails: details,
|
||||||
|
blogPosts: [post],
|
||||||
|
isMyProfile: true,
|
||||||
|
certPhotos: certPhotos,
|
||||||
|
consultantInfo: consultantInfo,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
cubit.updateFeedBlogPostList(post, true);
|
||||||
|
|
||||||
|
final state = cubit.state as ProfileStateLoaded;
|
||||||
|
expect(state.isMyProfile, isTrue);
|
||||||
|
expect(state.consultantInfo, consultantInfo);
|
||||||
|
expect(state.certPhotos, certPhotos);
|
||||||
|
expect(state.profile, profile);
|
||||||
|
expect(state.profileDetails, details);
|
||||||
|
expect(state.blogPosts.single.wasLikedByMe, isTrue);
|
||||||
|
expect(state.blogPosts.single.totalLikes, 11);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,211 @@
|
|||||||
|
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/features/chat/repositories/chat_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/consultant/become_consultant/models/consultation_request_model.dart';
|
||||||
|
import 'package:eatvio_app/features/consultant/become_consultant/repositories/consultant_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/insights/repositories/insights_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/presentation/bloc/plans_cubit/plans_cubit.dart'
|
||||||
|
as profile_plans;
|
||||||
|
import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/presentation/pages/profile_screen.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/plans/repositories/plan_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/plans/repositories/plans_repository.dart';
|
||||||
|
import 'package:eatvio_app/generated/l10n.dart';
|
||||||
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:mockito/annotations.dart';
|
||||||
|
import 'package:mockito/mockito.dart';
|
||||||
|
import 'package:network_image_mock/network_image_mock.dart';
|
||||||
|
|
||||||
|
import '../../../../fixtures/doubles/insights_doubles.dart';
|
||||||
|
import 'profile_screen_consultant_null_links_test.mocks.dart';
|
||||||
|
|
||||||
|
@GenerateNiceMocks([
|
||||||
|
MockSpec<ProfileRepository>(),
|
||||||
|
MockSpec<ChatRepository>(),
|
||||||
|
MockSpec<ConsultantRepository>(),
|
||||||
|
MockSpec<PlansRepository>(),
|
||||||
|
MockSpec<PlanRepository>(),
|
||||||
|
])
|
||||||
|
void main() {
|
||||||
|
group('ProfileScreen — consultant without social links', () {
|
||||||
|
late MockProfileRepository profileRepository;
|
||||||
|
late MockChatRepository chatRepository;
|
||||||
|
late MockConsultantRepository consultantRepository;
|
||||||
|
late MockPlansRepository plansRepository;
|
||||||
|
late MockPlanRepository planRepository;
|
||||||
|
|
||||||
|
setUpAll(() async {
|
||||||
|
dotenv.loadFromString(
|
||||||
|
envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
setUp(() async {
|
||||||
|
await sl.reset();
|
||||||
|
sl.registerLazySingleton<AppConfig>(
|
||||||
|
() =>
|
||||||
|
AppConfig(buildType: AppBuildType.tests)
|
||||||
|
..setBaseUrl('http://localhost'),
|
||||||
|
);
|
||||||
|
|
||||||
|
profileRepository = MockProfileRepository();
|
||||||
|
chatRepository = MockChatRepository();
|
||||||
|
consultantRepository = MockConsultantRepository();
|
||||||
|
plansRepository = MockPlansRepository();
|
||||||
|
planRepository = MockPlanRepository();
|
||||||
|
|
||||||
|
when(
|
||||||
|
planRepository.planLikeState,
|
||||||
|
).thenAnswer((_) => const Stream.empty());
|
||||||
|
when(
|
||||||
|
planRepository.planFavoriteState,
|
||||||
|
).thenAnswer((_) => const Stream.empty());
|
||||||
|
when(
|
||||||
|
planRepository.planCommentsState,
|
||||||
|
).thenAnswer((_) => const Stream.empty());
|
||||||
|
|
||||||
|
sl.registerLazySingleton<ProfileRepository>(() => profileRepository);
|
||||||
|
sl.registerLazySingleton<InsightsRepository>(
|
||||||
|
() => FakeInsightsRepository(),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<ChatRepository>(() => chatRepository);
|
||||||
|
sl.registerLazySingleton<ConsultantRepository>(
|
||||||
|
() => consultantRepository,
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<PlansRepository>(() => plansRepository);
|
||||||
|
sl.registerLazySingleton<PlanRepository>(() => planRepository);
|
||||||
|
|
||||||
|
sl.registerFactory<ProfileCubit>(
|
||||||
|
() => ProfileCubit(
|
||||||
|
profileRepository: sl(),
|
||||||
|
chatRepository: sl(),
|
||||||
|
consultantRepository: sl(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
sl.registerFactory<profile_plans.PlansCubit>(
|
||||||
|
() => profile_plans.PlansCubit(
|
||||||
|
plansRepository: sl(),
|
||||||
|
planRepository: sl(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
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: Scaffold(body: child),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ProfileModel profileOf(String slug, {List<String> roles = const []}) {
|
||||||
|
return ProfileModel(
|
||||||
|
id: 1,
|
||||||
|
name: 'Test User',
|
||||||
|
email: 'test@example.com',
|
||||||
|
phoneConfirmationState: 'confirmed',
|
||||||
|
slug: slug,
|
||||||
|
isPublicProfile: true,
|
||||||
|
isBlockedByMe: false,
|
||||||
|
isBlockedByAuthor: false,
|
||||||
|
isBlockedByUser: false,
|
||||||
|
isEntitySubscribedByMe: false,
|
||||||
|
profilePhotoUrl: '',
|
||||||
|
roles: roles,
|
||||||
|
badges: const [],
|
||||||
|
subscriptions: const [],
|
||||||
|
subscribers: const [],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const details = ProfileDetailsModel(
|
||||||
|
firstName: 'Test',
|
||||||
|
lastName: 'User',
|
||||||
|
birthdate: '1990-01-01',
|
||||||
|
gender: 'male',
|
||||||
|
country: 'Russia',
|
||||||
|
city: 'Moscow',
|
||||||
|
lang: 'ru',
|
||||||
|
weight: 70.0,
|
||||||
|
height: 175,
|
||||||
|
chestCircumference: 100,
|
||||||
|
waistCircumference: 80,
|
||||||
|
hipCircumference: 90,
|
||||||
|
bloodPressureUp: 120,
|
||||||
|
bloodPressureDown: 80,
|
||||||
|
hasHypo: false,
|
||||||
|
hasHyper: false,
|
||||||
|
aboutAlergy: '',
|
||||||
|
aboutTakingPils: '',
|
||||||
|
aboutSportHobbies: '',
|
||||||
|
favoriteFoods: '',
|
||||||
|
unfavoriteFoods: '',
|
||||||
|
additionalInfo: '',
|
||||||
|
isMoodFillable: true,
|
||||||
|
isBedtimeFillable: true,
|
||||||
|
activityCoefficient: 1.5,
|
||||||
|
);
|
||||||
|
|
||||||
|
const consultantInfo = ConsultationRequestModel(
|
||||||
|
ratingPlace: 5,
|
||||||
|
educationModel: EducationModel(
|
||||||
|
hasMedicalEducation: 0,
|
||||||
|
completedCourses: null,
|
||||||
|
vkLink: null,
|
||||||
|
instaLink: null,
|
||||||
|
fbLink: null,
|
||||||
|
tgLink: null,
|
||||||
|
personalSiteLink: null,
|
||||||
|
requestState: ModerationStatus.approved,
|
||||||
|
),
|
||||||
|
photos: [],
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'a consultant with null social links renders without an ErrorWidget',
|
||||||
|
(tester) async {
|
||||||
|
when(profileRepository.getProfileBySlug(any)).thenAnswer(
|
||||||
|
(_) async => profileOf('other-consultant', roles: ['consultant']),
|
||||||
|
);
|
||||||
|
when(
|
||||||
|
profileRepository.getMyProfile(),
|
||||||
|
).thenAnswer((_) async => profileOf('me'));
|
||||||
|
when(
|
||||||
|
profileRepository.getProfileDetailsBySlug(any),
|
||||||
|
).thenAnswer((_) async => details);
|
||||||
|
when(
|
||||||
|
profileRepository.getBlogPostsByAuthorSlug(slug: anyNamed('slug')),
|
||||||
|
).thenAnswer((_) async => []);
|
||||||
|
when(
|
||||||
|
consultantRepository.getConsultantRequestStatus(any),
|
||||||
|
).thenAnswer((_) async => consultantInfo);
|
||||||
|
when(plansRepository.getPlansBySlug(any)).thenAnswer((_) async => []);
|
||||||
|
|
||||||
|
await mockNetworkImagesFor(() async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
wrap(const ProfileScreen(slug: 'other-consultant')),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
expect(find.byType(ErrorWidget), findsNothing);
|
||||||
|
expect(find.byType(ProfileScreen), findsOneWidget);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,272 @@
|
|||||||
|
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/widgets/bookmark_button.dart';
|
||||||
|
import 'package:eatvio_app/features/chat/repositories/chat_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/consultant/become_consultant/models/consultation_request_model.dart';
|
||||||
|
import 'package:eatvio_app/features/consultant/become_consultant/repositories/consultant_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
|
||||||
|
import 'package:eatvio_app/features/insights/repositories/insights_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/presentation/bloc/plans_cubit/plans_cubit.dart'
|
||||||
|
as profile_plans;
|
||||||
|
import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/presentation/pages/profile_screen.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/plans/repositories/plan_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/plans/repositories/plans_repository.dart';
|
||||||
|
import 'package:eatvio_app/generated/l10n.dart';
|
||||||
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
|
import 'package:flutter_portal/flutter_portal.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:mockito/annotations.dart';
|
||||||
|
import 'package:mockito/mockito.dart';
|
||||||
|
import 'package:network_image_mock/network_image_mock.dart';
|
||||||
|
|
||||||
|
import '../../../../fixtures/doubles/insights_doubles.dart';
|
||||||
|
import '../../../../fixtures/fixture_reader.dart';
|
||||||
|
import 'profile_screen_plan_like_test.mocks.dart';
|
||||||
|
|
||||||
|
@GenerateNiceMocks([
|
||||||
|
MockSpec<ProfileRepository>(),
|
||||||
|
MockSpec<ChatRepository>(),
|
||||||
|
MockSpec<ConsultantRepository>(),
|
||||||
|
MockSpec<PlansRepository>(),
|
||||||
|
MockSpec<PlanRepository>(),
|
||||||
|
])
|
||||||
|
void main() {
|
||||||
|
group('ProfileScreen — план консультанта', () {
|
||||||
|
late MockProfileRepository profileRepository;
|
||||||
|
late MockChatRepository chatRepository;
|
||||||
|
late MockConsultantRepository consultantRepository;
|
||||||
|
late MockPlansRepository plansRepository;
|
||||||
|
late MockPlanRepository planRepository;
|
||||||
|
|
||||||
|
setUpAll(() async {
|
||||||
|
dotenv.loadFromString(
|
||||||
|
envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
setUp(() async {
|
||||||
|
await sl.reset();
|
||||||
|
sl.registerLazySingleton<AppConfig>(
|
||||||
|
() =>
|
||||||
|
AppConfig(buildType: AppBuildType.tests)
|
||||||
|
..setBaseUrl('http://localhost'),
|
||||||
|
);
|
||||||
|
|
||||||
|
profileRepository = MockProfileRepository();
|
||||||
|
chatRepository = MockChatRepository();
|
||||||
|
consultantRepository = MockConsultantRepository();
|
||||||
|
plansRepository = MockPlansRepository();
|
||||||
|
planRepository = MockPlanRepository();
|
||||||
|
|
||||||
|
when(
|
||||||
|
planRepository.planLikeState,
|
||||||
|
).thenAnswer((_) => const Stream.empty());
|
||||||
|
when(
|
||||||
|
planRepository.planFavoriteState,
|
||||||
|
).thenAnswer((_) => const Stream.empty());
|
||||||
|
when(
|
||||||
|
planRepository.planCommentsState,
|
||||||
|
).thenAnswer((_) => const Stream.empty());
|
||||||
|
when(planRepository.likePlan(any)).thenAnswer((_) async {});
|
||||||
|
when(planRepository.addToFavorite(any)).thenAnswer((_) async {});
|
||||||
|
when(planRepository.removeFromFavorite(any)).thenAnswer((_) async {});
|
||||||
|
|
||||||
|
sl.registerLazySingleton<ProfileRepository>(() => profileRepository);
|
||||||
|
sl.registerLazySingleton<InsightsRepository>(
|
||||||
|
() => FakeInsightsRepository(),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<ChatRepository>(() => chatRepository);
|
||||||
|
sl.registerLazySingleton<ConsultantRepository>(
|
||||||
|
() => consultantRepository,
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<PlansRepository>(() => plansRepository);
|
||||||
|
sl.registerLazySingleton<PlanRepository>(() => planRepository);
|
||||||
|
|
||||||
|
sl.registerFactory<ProfileCubit>(
|
||||||
|
() => ProfileCubit(
|
||||||
|
profileRepository: sl(),
|
||||||
|
chatRepository: sl(),
|
||||||
|
consultantRepository: sl(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
sl.registerFactory<profile_plans.PlansCubit>(
|
||||||
|
() => profile_plans.PlansCubit(
|
||||||
|
plansRepository: sl(),
|
||||||
|
planRepository: sl(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() async {
|
||||||
|
await sl.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
Widget wrap(Widget child) {
|
||||||
|
return Portal(
|
||||||
|
child: MaterialApp(
|
||||||
|
theme: ThemeHelper().themeData(),
|
||||||
|
localizationsDelegates: const [
|
||||||
|
S.delegate,
|
||||||
|
...GlobalMaterialLocalizations.delegates,
|
||||||
|
],
|
||||||
|
supportedLocales: const [Locale('ru')],
|
||||||
|
home: Scaffold(body: child),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ProfileModel profileOf(String slug, {List<String> roles = const []}) {
|
||||||
|
return ProfileModel(
|
||||||
|
id: 1,
|
||||||
|
name: 'Test User',
|
||||||
|
email: 'test@example.com',
|
||||||
|
phoneConfirmationState: 'confirmed',
|
||||||
|
slug: slug,
|
||||||
|
isPublicProfile: true,
|
||||||
|
isBlockedByMe: false,
|
||||||
|
isBlockedByAuthor: false,
|
||||||
|
isBlockedByUser: false,
|
||||||
|
isEntitySubscribedByMe: false,
|
||||||
|
profilePhotoUrl: '',
|
||||||
|
roles: roles,
|
||||||
|
badges: const [],
|
||||||
|
subscriptions: const [],
|
||||||
|
subscribers: const [],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const details = ProfileDetailsModel(
|
||||||
|
firstName: 'Test',
|
||||||
|
lastName: 'User',
|
||||||
|
birthdate: '1990-01-01',
|
||||||
|
gender: 'male',
|
||||||
|
country: 'Russia',
|
||||||
|
city: 'Moscow',
|
||||||
|
lang: 'ru',
|
||||||
|
weight: 70.0,
|
||||||
|
height: 175,
|
||||||
|
chestCircumference: 100,
|
||||||
|
waistCircumference: 80,
|
||||||
|
hipCircumference: 90,
|
||||||
|
bloodPressureUp: 120,
|
||||||
|
bloodPressureDown: 80,
|
||||||
|
hasHypo: false,
|
||||||
|
hasHyper: false,
|
||||||
|
aboutAlergy: '',
|
||||||
|
aboutTakingPils: '',
|
||||||
|
aboutSportHobbies: '',
|
||||||
|
favoriteFoods: '',
|
||||||
|
unfavoriteFoods: '',
|
||||||
|
additionalInfo: '',
|
||||||
|
isMoodFillable: true,
|
||||||
|
isBedtimeFillable: true,
|
||||||
|
activityCoefficient: 1.5,
|
||||||
|
);
|
||||||
|
|
||||||
|
const consultantInfo = ConsultationRequestModel(
|
||||||
|
ratingPlace: 5,
|
||||||
|
educationModel: EducationModel(
|
||||||
|
hasMedicalEducation: 0,
|
||||||
|
completedCourses: null,
|
||||||
|
vkLink: '',
|
||||||
|
instaLink: '',
|
||||||
|
fbLink: '',
|
||||||
|
tgLink: '',
|
||||||
|
personalSiteLink: '',
|
||||||
|
requestState: ModerationStatus.approved,
|
||||||
|
),
|
||||||
|
photos: [],
|
||||||
|
);
|
||||||
|
|
||||||
|
PlanModel activePlan() {
|
||||||
|
return PlanModel.fromJson(
|
||||||
|
FixtureReader.readAsMap('plans/plan_response.json'),
|
||||||
|
).copyWith(
|
||||||
|
state: 'active',
|
||||||
|
wasLikedByMe: false,
|
||||||
|
isFavorite: false,
|
||||||
|
totalLikes: 10,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> pumpConsultantProfile(WidgetTester tester) async {
|
||||||
|
when(profileRepository.getProfileBySlug(any)).thenAnswer(
|
||||||
|
(_) async => profileOf('other-consultant', roles: ['consultant']),
|
||||||
|
);
|
||||||
|
when(
|
||||||
|
profileRepository.getMyProfile(),
|
||||||
|
).thenAnswer((_) async => profileOf('me'));
|
||||||
|
when(
|
||||||
|
profileRepository.getProfileDetailsBySlug(any),
|
||||||
|
).thenAnswer((_) async => details);
|
||||||
|
when(
|
||||||
|
profileRepository.getBlogPostsByAuthorSlug(slug: anyNamed('slug')),
|
||||||
|
).thenAnswer((_) async => []);
|
||||||
|
when(
|
||||||
|
consultantRepository.getConsultantRequestStatus(any),
|
||||||
|
).thenAnswer((_) async => consultantInfo);
|
||||||
|
when(
|
||||||
|
plansRepository.getPlansBySlug(any),
|
||||||
|
).thenAnswer((_) async => [activePlan()]);
|
||||||
|
|
||||||
|
await mockNetworkImagesFor(() async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
wrap(const ProfileScreen(slug: 'other-consultant')),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
// ExpandablePageView measures its height in a post-frame callback,
|
||||||
|
// so the plan card appears only after an extra frame.
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump(const Duration(milliseconds: 100));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'tapping like on a consultant plan in someone else profile updates like state',
|
||||||
|
(tester) async {
|
||||||
|
await pumpConsultantProfile(tester);
|
||||||
|
|
||||||
|
final likeButton = find.byIcon(Icons.favorite_border_rounded);
|
||||||
|
expect(likeButton, findsOneWidget);
|
||||||
|
await tester.ensureVisible(likeButton);
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
await tester.tap(likeButton);
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump(const Duration(milliseconds: 300));
|
||||||
|
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
expect(find.byIcon(Icons.favorite_rounded), findsOneWidget);
|
||||||
|
expect(find.text('11'), findsOneWidget);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'tapping bookmark on a consultant plan in someone else profile updates favorite state',
|
||||||
|
(tester) async {
|
||||||
|
await pumpConsultantProfile(tester);
|
||||||
|
|
||||||
|
final bookmark = find.descendant(
|
||||||
|
of: find.byType(BookmarkButton),
|
||||||
|
matching: find.byIcon(Icons.bookmark_border_rounded),
|
||||||
|
);
|
||||||
|
expect(bookmark, findsOneWidget);
|
||||||
|
await tester.ensureVisible(bookmark);
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
await tester.tap(bookmark);
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump(const Duration(milliseconds: 300));
|
||||||
|
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
expect(find.byIcon(Icons.bookmark), findsOneWidget);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ import 'package:eatvio_app/features/profile/presentation/bloc/plans_cubit/plans_
|
|||||||
import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart';
|
import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart';
|
||||||
import 'package:eatvio_app/features/profile/presentation/pages/profile_screen.dart';
|
import 'package:eatvio_app/features/profile/presentation/pages/profile_screen.dart';
|
||||||
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/plans/repositories/plan_repository.dart';
|
||||||
import 'package:eatvio_app/features/plans/repositories/plans_repository.dart';
|
import 'package:eatvio_app/features/plans/repositories/plans_repository.dart';
|
||||||
import 'package:eatvio_app/generated/l10n.dart';
|
import 'package:eatvio_app/generated/l10n.dart';
|
||||||
import 'package:material_ui/material_ui.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
@@ -29,6 +30,7 @@ import 'profile_screen_smoke_test.mocks.dart';
|
|||||||
MockSpec<ChatRepository>(),
|
MockSpec<ChatRepository>(),
|
||||||
MockSpec<ConsultantRepository>(),
|
MockSpec<ConsultantRepository>(),
|
||||||
MockSpec<PlansRepository>(),
|
MockSpec<PlansRepository>(),
|
||||||
|
MockSpec<PlanRepository>(),
|
||||||
])
|
])
|
||||||
void main() {
|
void main() {
|
||||||
group('ProfileScreen smoke', () {
|
group('ProfileScreen smoke', () {
|
||||||
@@ -36,6 +38,7 @@ void main() {
|
|||||||
late MockChatRepository chatRepository;
|
late MockChatRepository chatRepository;
|
||||||
late MockConsultantRepository consultantRepository;
|
late MockConsultantRepository consultantRepository;
|
||||||
late MockPlansRepository plansRepository;
|
late MockPlansRepository plansRepository;
|
||||||
|
late MockPlanRepository planRepository;
|
||||||
|
|
||||||
setUpAll(() async {
|
setUpAll(() async {
|
||||||
dotenv.loadFromString(
|
dotenv.loadFromString(
|
||||||
@@ -55,6 +58,11 @@ void main() {
|
|||||||
chatRepository = MockChatRepository();
|
chatRepository = MockChatRepository();
|
||||||
consultantRepository = MockConsultantRepository();
|
consultantRepository = MockConsultantRepository();
|
||||||
plansRepository = MockPlansRepository();
|
plansRepository = MockPlansRepository();
|
||||||
|
planRepository = MockPlanRepository();
|
||||||
|
|
||||||
|
when(planRepository.planLikeState).thenAnswer((_) => const Stream.empty());
|
||||||
|
when(planRepository.planFavoriteState).thenAnswer((_) => const Stream.empty());
|
||||||
|
when(planRepository.planCommentsState).thenAnswer((_) => const Stream.empty());
|
||||||
|
|
||||||
sl.registerLazySingleton<ProfileRepository>(() => profileRepository);
|
sl.registerLazySingleton<ProfileRepository>(() => profileRepository);
|
||||||
sl.registerLazySingleton<InsightsRepository>(
|
sl.registerLazySingleton<InsightsRepository>(
|
||||||
@@ -65,6 +73,7 @@ void main() {
|
|||||||
() => consultantRepository,
|
() => consultantRepository,
|
||||||
);
|
);
|
||||||
sl.registerLazySingleton<PlansRepository>(() => plansRepository);
|
sl.registerLazySingleton<PlansRepository>(() => plansRepository);
|
||||||
|
sl.registerLazySingleton<PlanRepository>(() => planRepository);
|
||||||
|
|
||||||
sl.registerFactory<ProfileCubit>(
|
sl.registerFactory<ProfileCubit>(
|
||||||
() => ProfileCubit(
|
() => ProfileCubit(
|
||||||
@@ -74,7 +83,10 @@ void main() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
sl.registerFactory<profile_plans.PlansCubit>(
|
sl.registerFactory<profile_plans.PlansCubit>(
|
||||||
() => profile_plans.PlansCubit(plansRepository: sl()),
|
() => profile_plans.PlansCubit(
|
||||||
|
plansRepository: sl(),
|
||||||
|
planRepository: sl(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,256 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
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/features/chat/repositories/chat_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/consultant/become_consultant/repositories/consultant_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/feed/models/feed_blog_post_model.dart';
|
||||||
|
import 'package:eatvio_app/features/feed/presentation/bloc/feed_cubit/feed_cubit.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_state.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/presentation/widgets/profile_blog_post_widget.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/repositories/profile_repository.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';
|
||||||
|
import 'package:flutter_portal/flutter_portal.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:mockito/annotations.dart';
|
||||||
|
import 'package:mockito/mockito.dart';
|
||||||
|
import 'package:network_image_mock/network_image_mock.dart';
|
||||||
|
|
||||||
|
import '../../../../fixtures/feed_fixtures.dart';
|
||||||
|
import 'profile_blog_post_widget_like_test.mocks.dart';
|
||||||
|
|
||||||
|
@GenerateNiceMocks([
|
||||||
|
MockSpec<ProfileCubit>(),
|
||||||
|
MockSpec<FeedCubit>(),
|
||||||
|
MockSpec<ProfileRepository>(),
|
||||||
|
MockSpec<ChatRepository>(),
|
||||||
|
MockSpec<ConsultantRepository>(),
|
||||||
|
])
|
||||||
|
void main() {
|
||||||
|
group('ProfileBlogPostWidget — like', () {
|
||||||
|
setUpAll(() async {
|
||||||
|
dotenv.loadFromString(
|
||||||
|
envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
setUp(() async {
|
||||||
|
await sl.reset();
|
||||||
|
sl.registerLazySingleton<AppConfig>(
|
||||||
|
() =>
|
||||||
|
AppConfig(buildType: AppBuildType.tests)
|
||||||
|
..setBaseUrl('http://localhost'),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() async {
|
||||||
|
await sl.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
const profile = ProfileModel(
|
||||||
|
id: 1,
|
||||||
|
name: 'User',
|
||||||
|
email: 'u@e.com',
|
||||||
|
phoneConfirmationState: 'confirmed',
|
||||||
|
slug: 'user',
|
||||||
|
isPublicProfile: true,
|
||||||
|
isBlockedByMe: false,
|
||||||
|
isBlockedByAuthor: false,
|
||||||
|
isBlockedByUser: false,
|
||||||
|
isEntitySubscribedByMe: false,
|
||||||
|
profilePhotoUrl: '',
|
||||||
|
roles: [],
|
||||||
|
badges: [],
|
||||||
|
subscriptions: [],
|
||||||
|
subscribers: [],
|
||||||
|
);
|
||||||
|
|
||||||
|
const details = ProfileDetailsModel(
|
||||||
|
firstName: 'Test',
|
||||||
|
lastName: 'User',
|
||||||
|
birthdate: '1990-01-01',
|
||||||
|
gender: 'male',
|
||||||
|
country: 'Russia',
|
||||||
|
city: 'Moscow',
|
||||||
|
lang: 'ru',
|
||||||
|
weight: 70.0,
|
||||||
|
height: 175,
|
||||||
|
chestCircumference: 100,
|
||||||
|
waistCircumference: 80,
|
||||||
|
hipCircumference: 90,
|
||||||
|
bloodPressureUp: 120,
|
||||||
|
bloodPressureDown: 80,
|
||||||
|
hasHypo: false,
|
||||||
|
hasHyper: false,
|
||||||
|
aboutAlergy: '',
|
||||||
|
aboutTakingPils: '',
|
||||||
|
aboutSportHobbies: '',
|
||||||
|
favoriteFoods: '',
|
||||||
|
unfavoriteFoods: '',
|
||||||
|
additionalInfo: '',
|
||||||
|
isMoodFillable: true,
|
||||||
|
isBedtimeFillable: true,
|
||||||
|
activityCoefficient: 1.5,
|
||||||
|
);
|
||||||
|
|
||||||
|
ProfileState loadedState() {
|
||||||
|
return ProfileState.loaded(
|
||||||
|
profile: profile,
|
||||||
|
profileDetails: details,
|
||||||
|
blogPosts: [
|
||||||
|
FeedFixtures.feedBlogPostModel().copyWith(
|
||||||
|
wasLikedByMe: false,
|
||||||
|
totalLikes: 10,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
isMyProfile: true,
|
||||||
|
certPhotos: const [],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget wrap({
|
||||||
|
required ProfileCubit profileCubit,
|
||||||
|
required FeedCubit feedCubit,
|
||||||
|
}) {
|
||||||
|
return Portal(
|
||||||
|
child: MaterialApp(
|
||||||
|
theme: ThemeHelper().themeData(),
|
||||||
|
localizationsDelegates: const [
|
||||||
|
S.delegate,
|
||||||
|
...GlobalMaterialLocalizations.delegates,
|
||||||
|
],
|
||||||
|
supportedLocales: const [Locale('ru')],
|
||||||
|
home: Scaffold(
|
||||||
|
body: MediaQuery(
|
||||||
|
data: const MediaQueryData(size: Size(800, 1600)),
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: BlocProvider<FeedCubit>.value(
|
||||||
|
value: feedCubit,
|
||||||
|
child: ProfileBlogPostWidget(
|
||||||
|
index: 0,
|
||||||
|
profileCubit: profileCubit,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'passes the new like value to updateFeedBlogPostList before the request completes',
|
||||||
|
(tester) async {
|
||||||
|
final profileCubit = _RecordingProfileCubit(
|
||||||
|
profileRepository: MockProfileRepository(),
|
||||||
|
chatRepository: MockChatRepository(),
|
||||||
|
consultantRepository: MockConsultantRepository(),
|
||||||
|
);
|
||||||
|
addTearDown(profileCubit.close);
|
||||||
|
profileCubit.emit(loadedState());
|
||||||
|
final expectedPost =
|
||||||
|
(profileCubit.state as ProfileStateLoaded).blogPosts.single;
|
||||||
|
|
||||||
|
final feedCubit = MockFeedCubit();
|
||||||
|
final likeCompleter = Completer<void>();
|
||||||
|
when(feedCubit.likePost(any)).thenAnswer((_) => likeCompleter.future);
|
||||||
|
|
||||||
|
await mockNetworkImagesFor(() async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
wrap(profileCubit: profileCubit, feedCubit: feedCubit),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
final likeButton = find.byIcon(Icons.favorite_border_rounded);
|
||||||
|
await tester.ensureVisible(likeButton);
|
||||||
|
await tester.pump();
|
||||||
|
await tester.tap(likeButton);
|
||||||
|
// A frame while the HTTP request is still in flight: the rebuild resets
|
||||||
|
// the mutable isLiked field to post.wasLikedByMe (false).
|
||||||
|
await tester.pump();
|
||||||
|
});
|
||||||
|
|
||||||
|
// The widget must propagate the NEW value synchronously, before the
|
||||||
|
// request completes. A broken implementation that reads the mutable
|
||||||
|
// isLiked field after the await has not called this at all yet.
|
||||||
|
expect(profileCubit.likeUpdates, hasLength(1));
|
||||||
|
expect(profileCubit.likeUpdates.single.post.id, expectedPost.id);
|
||||||
|
expect(profileCubit.likeUpdates.single.wasLikedByMe, isTrue);
|
||||||
|
|
||||||
|
likeCompleter.complete();
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
// Issue #582, P1: exactly once, with the NEW value.
|
||||||
|
expect(profileCubit.likeUpdates, hasLength(1));
|
||||||
|
expect(profileCubit.likeUpdates.single.wasLikedByMe, isTrue);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'liking a post stores the new like value and keeps the heart and counter after rebuild',
|
||||||
|
(tester) async {
|
||||||
|
final feedCubit = MockFeedCubit();
|
||||||
|
final likeCompleter = Completer<void>();
|
||||||
|
when(feedCubit.likePost(any)).thenAnswer((_) => likeCompleter.future);
|
||||||
|
|
||||||
|
final profileCubit = ProfileCubit(
|
||||||
|
profileRepository: MockProfileRepository(),
|
||||||
|
chatRepository: MockChatRepository(),
|
||||||
|
consultantRepository: MockConsultantRepository(),
|
||||||
|
);
|
||||||
|
addTearDown(profileCubit.close);
|
||||||
|
profileCubit.emit(loadedState());
|
||||||
|
|
||||||
|
await mockNetworkImagesFor(() async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
wrap(profileCubit: profileCubit, feedCubit: feedCubit),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
final likeButton = find.byIcon(Icons.favorite_border_rounded);
|
||||||
|
await tester.ensureVisible(likeButton);
|
||||||
|
await tester.pump();
|
||||||
|
await tester.tap(likeButton);
|
||||||
|
// A frame while the HTTP request is still in flight: the build resets
|
||||||
|
// isLiked/totalLikes from the post unless the new value was stored.
|
||||||
|
await tester.pump();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(find.byIcon(Icons.favorite_rounded), findsOneWidget);
|
||||||
|
expect(find.text('11'), findsOneWidget);
|
||||||
|
|
||||||
|
likeCompleter.complete();
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
final state = profileCubit.state as ProfileStateLoaded;
|
||||||
|
expect(state.blogPosts.single.wasLikedByMe, isTrue);
|
||||||
|
expect(state.blogPosts.single.totalLikes, 11);
|
||||||
|
expect(find.byIcon(Icons.favorite_rounded), findsOneWidget);
|
||||||
|
expect(find.text('11'), findsOneWidget);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RecordingProfileCubit extends ProfileCubit {
|
||||||
|
_RecordingProfileCubit({
|
||||||
|
required super.profileRepository,
|
||||||
|
required super.chatRepository,
|
||||||
|
required super.consultantRepository,
|
||||||
|
});
|
||||||
|
|
||||||
|
final List<({FeedBlogPostModel post, bool wasLikedByMe})> likeUpdates = [];
|
||||||
|
|
||||||
|
@override
|
||||||
|
void updateFeedBlogPostList(FeedBlogPostModel post, bool wasLikedByMe) {
|
||||||
|
likeUpdates.add((post: post, wasLikedByMe: wasLikedByMe));
|
||||||
|
super.updateFeedBlogPostList(post, wasLikedByMe);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -141,12 +141,46 @@ void main() {
|
|||||||
|
|
||||||
await settingsCubit!.init();
|
await settingsCubit!.init();
|
||||||
await Future.delayed(const Duration(milliseconds: 100));
|
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));
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
|
|
||||||
|
expect(result, true);
|
||||||
verify(mockSettingsRepository.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).called(1);
|
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 {
|
test('updateProfileSettings - обновляет настройки профиля', () async {
|
||||||
settingsCubit = SettingsCubit(
|
settingsCubit = SettingsCubit(
|
||||||
profileRepository: mockProfileRepository,
|
profileRepository: mockProfileRepository,
|
||||||
@@ -173,12 +207,46 @@ void main() {
|
|||||||
|
|
||||||
await settingsCubit!.init();
|
await settingsCubit!.init();
|
||||||
await Future.delayed(const Duration(milliseconds: 100));
|
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));
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
|
|
||||||
|
expect(result, true);
|
||||||
verify(mockSettingsRepository.updateProfileSettings(profileSettingsModel: anyNamed('profileSettingsModel'))).called(1);
|
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 {
|
test('deleteAccount - удаляет аккаунт', () async {
|
||||||
settingsCubit = SettingsCubit(
|
settingsCubit = SettingsCubit(
|
||||||
profileRepository: mockProfileRepository,
|
profileRepository: mockProfileRepository,
|
||||||
|
|||||||
@@ -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/features/settings/presentation/pages/general_info_screen.dart';
|
||||||
import 'package:eatvio_app/generated/l10n.dart';
|
import 'package:eatvio_app/generated/l10n.dart';
|
||||||
import 'package:material_ui/material_ui.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
@@ -25,6 +26,8 @@ import 'general_info_screen_test.mocks.dart';
|
|||||||
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
|
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
|
||||||
void main() {
|
void main() {
|
||||||
group('GeneralInfoScreen smoke', () {
|
group('GeneralInfoScreen smoke', () {
|
||||||
|
final toastCalls = <MethodCall>[];
|
||||||
|
|
||||||
setUpAll(() async {
|
setUpAll(() async {
|
||||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||||
});
|
});
|
||||||
@@ -32,6 +35,21 @@ void main() {
|
|||||||
setUp(() async {
|
setUp(() async {
|
||||||
await sl.reset();
|
await sl.reset();
|
||||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
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(
|
const mockProfile = ProfileModel(
|
||||||
@@ -95,7 +113,20 @@ void main() {
|
|||||||
supportedLocales: const [Locale('ru')],
|
supportedLocales: const [Locale('ru')],
|
||||||
routerConfig: GoRouter(
|
routerConfig: GoRouter(
|
||||||
initialLocation: '/',
|
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.state).thenReturn(state);
|
||||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
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);
|
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
|
||||||
|
|
||||||
@@ -122,8 +153,8 @@ void main() {
|
|||||||
child: wrap(GeneralInfoScreen(settingsEntity: settingsEntity)),
|
child: wrap(GeneralInfoScreen(settingsEntity: settingsEntity)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
await tester.pump();
|
await tester.tap(find.text('open screen'));
|
||||||
await tester.pump(const Duration(milliseconds: 200));
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(find.byType(GeneralInfoScreen), findsOneWidget);
|
expect(find.byType(GeneralInfoScreen), findsOneWidget);
|
||||||
});
|
});
|
||||||
@@ -136,13 +167,13 @@ void main() {
|
|||||||
profile: mockProfile,
|
profile: mockProfile,
|
||||||
hasActiveConsultation: false,
|
hasActiveConsultation: false,
|
||||||
);
|
);
|
||||||
final saveCompleter = Completer<void>();
|
final saveCompleter = Completer<bool>();
|
||||||
|
|
||||||
when(cubit.state).thenReturn(state);
|
when(cubit.state).thenReturn(state);
|
||||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||||
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) => saveCompleter.future);
|
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);
|
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
|
||||||
|
|
||||||
@@ -152,7 +183,8 @@ void main() {
|
|||||||
child: wrap(GeneralInfoScreen(settingsEntity: settingsEntity)),
|
child: wrap(GeneralInfoScreen(settingsEntity: settingsEntity)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
await tester.pump();
|
await tester.tap(find.text('open screen'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(find.text('Сохранить'), findsOneWidget);
|
expect(find.text('Сохранить'), findsOneWidget);
|
||||||
expect(find.byType(Loader), findsNothing);
|
expect(find.byType(Loader), findsNothing);
|
||||||
@@ -167,12 +199,88 @@ void main() {
|
|||||||
final loaderSize = tester.getSize(find.byType(Loader));
|
final loaderSize = tester.getSize(find.byType(Loader));
|
||||||
expect(loaderSize.height, lessThan(60));
|
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();
|
||||||
await tester.pump(const Duration(milliseconds: 50));
|
await tester.pump(const Duration(milliseconds: 50));
|
||||||
|
|
||||||
expect(find.text('Сохранить'), findsOneWidget);
|
final toastMessages = toastCalls.where((call) => call.method == 'showToast').map((call) => call.arguments['msg']);
|
||||||
expect(find.byType(Loader), findsNothing);
|
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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/features/settings/presentation/pages/other_info_screen.dart';
|
||||||
import 'package:eatvio_app/generated/l10n.dart';
|
import 'package:eatvio_app/generated/l10n.dart';
|
||||||
import 'package:material_ui/material_ui.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
@@ -22,6 +23,8 @@ import 'other_info_screen_test.mocks.dart';
|
|||||||
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
|
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
|
||||||
void main() {
|
void main() {
|
||||||
group('OtherInfoScreen smoke', () {
|
group('OtherInfoScreen smoke', () {
|
||||||
|
final toastCalls = <MethodCall>[];
|
||||||
|
|
||||||
setUpAll(() async {
|
setUpAll(() async {
|
||||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||||
});
|
});
|
||||||
@@ -29,6 +32,21 @@ void main() {
|
|||||||
setUp(() async {
|
setUp(() async {
|
||||||
await sl.reset();
|
await sl.reset();
|
||||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
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(
|
const mockProfile = ProfileModel(
|
||||||
@@ -92,7 +110,20 @@ void main() {
|
|||||||
supportedLocales: const [Locale('ru')],
|
supportedLocales: const [Locale('ru')],
|
||||||
routerConfig: GoRouter(
|
routerConfig: GoRouter(
|
||||||
initialLocation: '/',
|
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.state).thenReturn(state);
|
||||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||||
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async {
|
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
|
||||||
return Future<void>.value();
|
|
||||||
});
|
|
||||||
|
|
||||||
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
|
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
|
||||||
|
|
||||||
@@ -121,10 +150,82 @@ void main() {
|
|||||||
child: wrap(OtherInfoScreen(settingsEntity: settingsEntity)),
|
child: wrap(OtherInfoScreen(settingsEntity: settingsEntity)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
await tester.pump();
|
await tester.tap(find.text('open screen'));
|
||||||
await tester.pump(const Duration(milliseconds: 100));
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(find.byType(OtherInfoScreen), findsOneWidget);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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_cubit.dart';
|
||||||
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.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/features/settings/presentation/pages/physical_activity_screen.dart';
|
||||||
|
import 'package:eatvio_app/generated/l10n.dart';
|
||||||
import 'package:material_ui/material_ui.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
@@ -21,6 +23,8 @@ import 'physical_activity_screen_test.mocks.dart';
|
|||||||
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
|
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
|
||||||
void main() {
|
void main() {
|
||||||
group('PhysicalActivityScreen smoke', () {
|
group('PhysicalActivityScreen smoke', () {
|
||||||
|
final toastCalls = <MethodCall>[];
|
||||||
|
|
||||||
setUpAll(() async {
|
setUpAll(() async {
|
||||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||||
});
|
});
|
||||||
@@ -28,6 +32,21 @@ void main() {
|
|||||||
setUp(() async {
|
setUp(() async {
|
||||||
await sl.reset();
|
await sl.reset();
|
||||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
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(
|
const mockProfile = ProfileModel(
|
||||||
@@ -87,9 +106,24 @@ void main() {
|
|||||||
Widget wrap(Widget child) {
|
Widget wrap(Widget child) {
|
||||||
return MaterialApp.router(
|
return MaterialApp.router(
|
||||||
theme: ThemeHelper().themeData(),
|
theme: ThemeHelper().themeData(),
|
||||||
|
localizationsDelegates: const [S.delegate, ...GlobalMaterialLocalizations.delegates],
|
||||||
|
supportedLocales: const [Locale('ru')],
|
||||||
routerConfig: GoRouter(
|
routerConfig: GoRouter(
|
||||||
initialLocation: '/',
|
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.state).thenReturn(state);
|
||||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
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);
|
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
|
||||||
|
|
||||||
@@ -116,10 +150,82 @@ void main() {
|
|||||||
child: wrap(PhysicalActivityScreen(settingsEntity: settingsEntity)),
|
child: wrap(PhysicalActivityScreen(settingsEntity: settingsEntity)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
await tester.pump();
|
await tester.tap(find.text('open screen'));
|
||||||
await tester.pump(const Duration(milliseconds: 200));
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(find.byType(PhysicalActivityScreen), findsOneWidget);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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/features/settings/presentation/pages/physical_form_screen.dart';
|
||||||
import 'package:eatvio_app/generated/l10n.dart';
|
import 'package:eatvio_app/generated/l10n.dart';
|
||||||
import 'package:material_ui/material_ui.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
@@ -22,6 +23,8 @@ import 'physical_form_screen_test.mocks.dart';
|
|||||||
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
|
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
|
||||||
void main() {
|
void main() {
|
||||||
group('PhysicalFormScreen smoke', () {
|
group('PhysicalFormScreen smoke', () {
|
||||||
|
final toastCalls = <MethodCall>[];
|
||||||
|
|
||||||
setUpAll(() async {
|
setUpAll(() async {
|
||||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||||
});
|
});
|
||||||
@@ -29,6 +32,21 @@ void main() {
|
|||||||
setUp(() async {
|
setUp(() async {
|
||||||
await sl.reset();
|
await sl.reset();
|
||||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
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(
|
const mockProfile = ProfileModel(
|
||||||
@@ -92,7 +110,20 @@ void main() {
|
|||||||
supportedLocales: const [Locale('ru')],
|
supportedLocales: const [Locale('ru')],
|
||||||
routerConfig: GoRouter(
|
routerConfig: GoRouter(
|
||||||
initialLocation: '/',
|
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.state).thenReturn(state);
|
||||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
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);
|
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
|
||||||
|
|
||||||
@@ -119,10 +150,82 @@ void main() {
|
|||||||
child: wrap(PhysicalFormScreen(settingsEntity: settingsEntity)),
|
child: wrap(PhysicalFormScreen(settingsEntity: settingsEntity)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
await tester.pump();
|
await tester.tap(find.text('open screen'));
|
||||||
await tester.pump(const Duration(milliseconds: 100));
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(find.byType(PhysicalFormScreen), findsOneWidget);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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/features/settings/presentation/pages/pressure_screen.dart';
|
||||||
import 'package:eatvio_app/generated/l10n.dart';
|
import 'package:eatvio_app/generated/l10n.dart';
|
||||||
import 'package:material_ui/material_ui.dart';
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
@@ -22,6 +23,8 @@ import 'pressure_screen_test.mocks.dart';
|
|||||||
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
|
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
|
||||||
void main() {
|
void main() {
|
||||||
group('PressureScreen smoke', () {
|
group('PressureScreen smoke', () {
|
||||||
|
final toastCalls = <MethodCall>[];
|
||||||
|
|
||||||
setUpAll(() async {
|
setUpAll(() async {
|
||||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||||
});
|
});
|
||||||
@@ -29,6 +32,21 @@ void main() {
|
|||||||
setUp(() async {
|
setUp(() async {
|
||||||
await sl.reset();
|
await sl.reset();
|
||||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
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(
|
const mockProfile = ProfileModel(
|
||||||
@@ -92,7 +110,20 @@ void main() {
|
|||||||
supportedLocales: const [Locale('ru')],
|
supportedLocales: const [Locale('ru')],
|
||||||
routerConfig: GoRouter(
|
routerConfig: GoRouter(
|
||||||
initialLocation: '/',
|
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.state).thenReturn(state);
|
||||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
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);
|
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
|
||||||
|
|
||||||
@@ -119,10 +150,82 @@ void main() {
|
|||||||
child: wrap(PressureScreen(settingsEntity: settingsEntity)),
|
child: wrap(PressureScreen(settingsEntity: settingsEntity)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
await tester.pump();
|
await tester.tap(find.text('open screen'));
|
||||||
await tester.pump(const Duration(milliseconds: 100));
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(find.byType(PressureScreen), findsOneWidget);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user