forked from eatvio/eatvio_app
fix: align diary diet row and hide terminal cancel
- show only the personal diet name in the diary and keep the plan day chip - hide consultation cancellation for terminal and non-cancellable states - enable the refund form only for paid, started and in-progress plans - cover diary rows and order info cancel visibility with tests
This commit is contained in:
@@ -4,7 +4,6 @@ import 'package:eatvio_app/core/theme/theme_helper.dart';
|
|||||||
import 'package:eatvio_app/core/widgets/custom_divider.dart';
|
import 'package:eatvio_app/core/widgets/custom_divider.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:flutter/material.dart';
|
import 'package:flutter/material.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';
|
||||||
@@ -19,9 +18,7 @@ class ChosenDietWidget extends StatelessWidget {
|
|||||||
if (state is DiaryStateLoaded) {
|
if (state is DiaryStateLoaded) {
|
||||||
if (state.diary.typeOfDiary.hasChosenDiet) {
|
if (state.diary.typeOfDiary.hasChosenDiet) {
|
||||||
return ChosenDietWidgetContent(
|
return ChosenDietWidgetContent(
|
||||||
currentDietDay: state.diary.dayOfChosenDiet ?? 0,
|
|
||||||
dietName: state.diary.diet?.name ?? '',
|
dietName: state.diary.diet?.name ?? '',
|
||||||
dietDuration: state.diary.diet?.duration ?? 0,
|
|
||||||
dietId: state.diary.diet?.id ?? 0,
|
dietId: state.diary.diet?.id ?? 0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -33,9 +30,7 @@ class ChosenDietWidget extends StatelessWidget {
|
|||||||
const CustomDivider(),
|
const CustomDivider(),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
ChosenDietWidgetContent(
|
ChosenDietWidgetContent(
|
||||||
currentDietDay: state.diary.dayOfChosenDiet ?? 0,
|
|
||||||
dietName: state.diary.diet?.name ?? '',
|
dietName: state.diary.diet?.name ?? '',
|
||||||
dietDuration: state.diary.diet?.duration ?? 0,
|
|
||||||
dietId: state.diary.diet?.id ?? 0,
|
dietId: state.diary.diet?.id ?? 0,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -50,15 +45,11 @@ class ChosenDietWidget extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ChosenDietWidgetContent extends StatelessWidget {
|
class ChosenDietWidgetContent extends StatelessWidget {
|
||||||
const ChosenDietWidgetContent({super.key, required this.currentDietDay, required this.dietName, required this.dietDuration, required this.dietId});
|
const ChosenDietWidgetContent({super.key, required this.dietName, required this.dietId});
|
||||||
final int currentDietDay;
|
|
||||||
final String dietName;
|
final String dietName;
|
||||||
final int dietDuration;
|
|
||||||
final int dietId;
|
final int dietId;
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final size = MediaQuery.sizeOf(context);
|
|
||||||
final s = S.of(context);
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
GoRouter.of(context).push(RouteConstants.aboutDietScreen, extra: {'id': dietId, 'navigateToComments': false});
|
GoRouter.of(context).push(RouteConstants.aboutDietScreen, extra: {'id': dietId, 'navigateToComments': false});
|
||||||
@@ -67,19 +58,12 @@ class ChosenDietWidgetContent extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
SizedBox(
|
Expanded(
|
||||||
width: size.width * 0.4,
|
|
||||||
child: Text(
|
child: Text(
|
||||||
dietName,
|
dietName,
|
||||||
style: TextStyles.textLMedium.copyWith(color: appTheme.black, decoration: TextDecoration.underline),
|
style: TextStyles.textLMedium.copyWith(color: appTheme.black, decoration: TextDecoration.underline),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const Spacer(),
|
|
||||||
Container(
|
|
||||||
decoration: BoxDecoration(color: appTheme.dividerColor, borderRadius: BorderRadius.circular(12)),
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 12),
|
|
||||||
child: Text('${s.day} $currentDietDay из $dietDuration', style: TextStyles.textMSemibold.copyWith(color: appTheme.gray)),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ class _InfoByOrderScreenContentState extends State<InfoByOrderScreenContent> {
|
|||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
PlanState(state: plan.chosenPlanState, hasPersonalDiet: chosenOption?.hasPersonalDiet ?? false),
|
PlanState(state: plan.chosenPlanState, hasPersonalDiet: chosenOption?.hasPersonalDiet ?? false),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
if (widget.successfulPayment == null)
|
if (widget.successfulPayment == null && plan.chosenPlanState.canShowCancelAction)
|
||||||
CustomOutlinedButton(
|
CustomOutlinedButton(
|
||||||
text: s.cancelConsultation,
|
text: s.cancelConsultation,
|
||||||
height: 52,
|
height: 52,
|
||||||
@@ -173,7 +173,7 @@ class _InfoByOrderScreenContentState extends State<InfoByOrderScreenContent> {
|
|||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => CancelPlanBottomSheet(enableForm: plan.chosenPlanState.isStateAfterPaidState(), planId: plan.id),
|
builder: (context) => CancelPlanBottomSheet(enableForm: plan.chosenPlanState.isCancelAfterPaidState, planId: plan.id),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -62,6 +62,32 @@ enum ChosenPlanStateEnum {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool get canShowCancelAction {
|
||||||
|
switch (this) {
|
||||||
|
case ChosenPlanStateEnum.stateInited:
|
||||||
|
case ChosenPlanStateEnum.stateInCoordination:
|
||||||
|
case ChosenPlanStateEnum.stateStartDateHasBeenSet:
|
||||||
|
case ChosenPlanStateEnum.statePendingPayment:
|
||||||
|
case ChosenPlanStateEnum.statePaid:
|
||||||
|
case ChosenPlanStateEnum.stateStarted:
|
||||||
|
case ChosenPlanStateEnum.stateInProgress:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool get isCancelAfterPaidState {
|
||||||
|
switch (this) {
|
||||||
|
case ChosenPlanStateEnum.statePaid:
|
||||||
|
case ChosenPlanStateEnum.stateStarted:
|
||||||
|
case ChosenPlanStateEnum.stateInProgress:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static List<ChosenPlanStateEnum> getActiveStates() {
|
static List<ChosenPlanStateEnum> getActiveStates() {
|
||||||
return [
|
return [
|
||||||
ChosenPlanStateEnum.statePaid,
|
ChosenPlanStateEnum.statePaid,
|
||||||
|
|||||||
@@ -27,9 +27,7 @@ void main() {
|
|||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
createTestWidget(
|
createTestWidget(
|
||||||
const ChosenDietWidgetContent(
|
const ChosenDietWidgetContent(
|
||||||
currentDietDay: 5,
|
|
||||||
dietName: 'Test Diet',
|
dietName: 'Test Diet',
|
||||||
dietDuration: 14,
|
|
||||||
dietId: 1,
|
dietId: 1,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -38,15 +36,14 @@ void main() {
|
|||||||
|
|
||||||
expect(find.byType(ChosenDietWidgetContent), findsOneWidget);
|
expect(find.byType(ChosenDietWidgetContent), findsOneWidget);
|
||||||
expect(find.text('Test Diet'), findsOneWidget);
|
expect(find.text('Test Diet'), findsOneWidget);
|
||||||
|
expect(find.textContaining('из 14'), findsNothing);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('displays current day and duration', (tester) async {
|
testWidgets('does not display current day and duration', (tester) async {
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
createTestWidget(
|
createTestWidget(
|
||||||
const ChosenDietWidgetContent(
|
const ChosenDietWidgetContent(
|
||||||
currentDietDay: 7,
|
|
||||||
dietName: 'Test Diet',
|
dietName: 'Test Diet',
|
||||||
dietDuration: 21,
|
|
||||||
dietId: 1,
|
dietId: 1,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -54,15 +51,14 @@ void main() {
|
|||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(find.byType(ChosenDietWidgetContent), findsOneWidget);
|
expect(find.byType(ChosenDietWidgetContent), findsOneWidget);
|
||||||
|
expect(find.textContaining('из 21'), findsNothing);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('displays diet name with underline', (tester) async {
|
testWidgets('displays diet name with underline', (tester) async {
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
createTestWidget(
|
createTestWidget(
|
||||||
const ChosenDietWidgetContent(
|
const ChosenDietWidgetContent(
|
||||||
currentDietDay: 1,
|
|
||||||
dietName: 'My Diet',
|
dietName: 'My Diet',
|
||||||
dietDuration: 7,
|
|
||||||
dietId: 1,
|
dietId: 1,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -70,6 +66,7 @@ void main() {
|
|||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(find.text('My Diet'), findsOneWidget);
|
expect(find.text('My Diet'), findsOneWidget);
|
||||||
|
expect(find.textContaining('из 7'), findsNothing);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,6 +100,17 @@ void main() {
|
|||||||
await tester.pumpWidget(wrap(const ChosenDietWidget(), cubit));
|
await tester.pumpWidget(wrap(const ChosenDietWidget(), cubit));
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(find.text('Diet'), findsOneWidget);
|
expect(find.text('Diet'), findsOneWidget);
|
||||||
|
expect(find.textContaining('из 7'), findsNothing);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('ChosenDietWidget hides diet day while plan keeps its day', (tester) async {
|
||||||
|
final cubit = FakeDiaryCubit(loadedState(hasDiet: true, hasPlan: true));
|
||||||
|
await tester.pumpWidget(wrap(const Column(children: [ChosenPlanWidget(), ChosenDietWidget()]), cubit));
|
||||||
|
await tester.pump();
|
||||||
|
expect(find.text('Plan'), findsOneWidget);
|
||||||
|
expect(find.textContaining('из 30'), findsOneWidget);
|
||||||
|
expect(find.text('Diet'), findsOneWidget);
|
||||||
|
expect(find.textContaining('из 7'), findsNothing);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('AddProductButtonWidget renders for loaded state', (tester) async {
|
testWidgets('AddProductButtonWidget renders for loaded state', (tester) async {
|
||||||
|
|||||||
@@ -243,12 +243,12 @@ void main() {
|
|||||||
expect(find.byType(InfoByOrderScreen), findsOneWidget);
|
expect(find.byType(InfoByOrderScreen), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
ChosenPlanModel donePlan() {
|
ChosenPlanModel donePlan({ChosenPlanStateEnum state = ChosenPlanStateEnum.stateDone}) {
|
||||||
return ChosenPlanModel(
|
return ChosenPlanModel(
|
||||||
id: 1,
|
id: 1,
|
||||||
optionType: 'options1',
|
optionType: 'options1',
|
||||||
startDate: DateTime(2024, 1, 1),
|
startDate: DateTime(2024, 1, 1),
|
||||||
chosenPlanState: ChosenPlanStateEnum.stateDone,
|
chosenPlanState: state,
|
||||||
chatId: 'chat-1',
|
chatId: 'chat-1',
|
||||||
consultantId: 1,
|
consultantId: 1,
|
||||||
plan: const PlanModel(
|
plan: const PlanModel(
|
||||||
@@ -320,6 +320,7 @@ void main() {
|
|||||||
|
|
||||||
expect(find.byType(CollectChargeBanner), findsOneWidget);
|
expect(find.byType(CollectChargeBanner), findsOneWidget);
|
||||||
expect(find.text('Получить выплату'), findsOneWidget);
|
expect(find.text('Получить выплату'), findsOneWidget);
|
||||||
|
expect(find.text('Отменить консультацию'), findsNothing);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -337,6 +338,22 @@ void main() {
|
|||||||
|
|
||||||
expect(find.byType(CollectChargeBanner), findsNothing);
|
expect(find.byType(CollectChargeBanner), findsNothing);
|
||||||
expect(find.text('Получить выплату'), findsNothing);
|
expect(find.text('Получить выплату'), findsNothing);
|
||||||
|
expect(find.text('Отменить консультацию'), findsNothing);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('shows cancel action for cancellable post-paid plan', (
|
||||||
|
WidgetTester tester,
|
||||||
|
) async {
|
||||||
|
when(
|
||||||
|
mockChatRepository.getChosenPlan(id: anyNamed('id')),
|
||||||
|
).thenAnswer((_) async => donePlan(state: ChosenPlanStateEnum.stateStarted));
|
||||||
|
|
||||||
|
await mockNetworkImagesFor(() async {
|
||||||
|
await tester.pumpWidget(createTestWidget(planId: 1));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(find.text('Отменить консультацию'), findsOneWidget);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,47 @@ void main() {
|
|||||||
expect(ChosenPlanStateEnum.stateConfirmedByConsultant.isStateAfterPaidState(), isTrue);
|
expect(ChosenPlanStateEnum.stateConfirmedByConsultant.isStateAfterPaidState(), isTrue);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('canShowCancelAction returns true for cancellable states', () {
|
||||||
|
expect(ChosenPlanStateEnum.stateInited.canShowCancelAction, isTrue);
|
||||||
|
expect(ChosenPlanStateEnum.stateInCoordination.canShowCancelAction, isTrue);
|
||||||
|
expect(ChosenPlanStateEnum.stateStartDateHasBeenSet.canShowCancelAction, isTrue);
|
||||||
|
expect(ChosenPlanStateEnum.statePendingPayment.canShowCancelAction, isTrue);
|
||||||
|
expect(ChosenPlanStateEnum.statePaid.canShowCancelAction, isTrue);
|
||||||
|
expect(ChosenPlanStateEnum.stateStarted.canShowCancelAction, isTrue);
|
||||||
|
expect(ChosenPlanStateEnum.stateInProgress.canShowCancelAction, isTrue);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('canShowCancelAction returns false for non-cancellable states', () {
|
||||||
|
expect(ChosenPlanStateEnum.personalDietSet.canShowCancelAction, isFalse);
|
||||||
|
expect(ChosenPlanStateEnum.stateLastDayStarted.canShowCancelAction, isFalse);
|
||||||
|
expect(ChosenPlanStateEnum.stateLastDayFinished.canShowCancelAction, isFalse);
|
||||||
|
expect(ChosenPlanStateEnum.stateComplained.canShowCancelAction, isFalse);
|
||||||
|
expect(ChosenPlanStateEnum.stateDone.canShowCancelAction, isFalse);
|
||||||
|
expect(ChosenPlanStateEnum.stateChargeWasCollected.canShowCancelAction, isFalse);
|
||||||
|
expect(ChosenPlanStateEnum.stateCanceledByTheInitiator.canShowCancelAction, isFalse);
|
||||||
|
expect(ChosenPlanStateEnum.statePaymentFailed.canShowCancelAction, isFalse);
|
||||||
|
expect(ChosenPlanStateEnum.stateConfirmedByConsultant.canShowCancelAction, isFalse);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('isCancelAfterPaidState returns true only for post-paid cancellable states', () {
|
||||||
|
expect(ChosenPlanStateEnum.statePaid.isCancelAfterPaidState, isTrue);
|
||||||
|
expect(ChosenPlanStateEnum.stateStarted.isCancelAfterPaidState, isTrue);
|
||||||
|
expect(ChosenPlanStateEnum.stateInProgress.isCancelAfterPaidState, isTrue);
|
||||||
|
expect(ChosenPlanStateEnum.stateInited.isCancelAfterPaidState, isFalse);
|
||||||
|
expect(ChosenPlanStateEnum.stateInCoordination.isCancelAfterPaidState, isFalse);
|
||||||
|
expect(ChosenPlanStateEnum.stateStartDateHasBeenSet.isCancelAfterPaidState, isFalse);
|
||||||
|
expect(ChosenPlanStateEnum.statePendingPayment.isCancelAfterPaidState, isFalse);
|
||||||
|
expect(ChosenPlanStateEnum.statePaymentFailed.isCancelAfterPaidState, isFalse);
|
||||||
|
expect(ChosenPlanStateEnum.stateConfirmedByConsultant.isCancelAfterPaidState, isFalse);
|
||||||
|
expect(ChosenPlanStateEnum.personalDietSet.isCancelAfterPaidState, isFalse);
|
||||||
|
expect(ChosenPlanStateEnum.stateLastDayStarted.isCancelAfterPaidState, isFalse);
|
||||||
|
expect(ChosenPlanStateEnum.stateLastDayFinished.isCancelAfterPaidState, isFalse);
|
||||||
|
expect(ChosenPlanStateEnum.stateComplained.isCancelAfterPaidState, isFalse);
|
||||||
|
expect(ChosenPlanStateEnum.stateDone.isCancelAfterPaidState, isFalse);
|
||||||
|
expect(ChosenPlanStateEnum.stateChargeWasCollected.isCancelAfterPaidState, isFalse);
|
||||||
|
expect(ChosenPlanStateEnum.stateCanceledByTheInitiator.isCancelAfterPaidState, isFalse);
|
||||||
|
});
|
||||||
|
|
||||||
test('getActiveStates returns correct states', () {
|
test('getActiveStates returns correct states', () {
|
||||||
final activeStates = ChosenPlanStateEnum.getActiveStates();
|
final activeStates = ChosenPlanStateEnum.getActiveStates();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user