feat(UGPC): issue-777

This commit is contained in:
misha
2026-10-12 08:50:33 +03:00
parent f8e06b6d7a
commit cb312037b2
15 changed files with 442 additions and 36 deletions

View File

@@ -4,6 +4,9 @@ import 'package:eatvio_app/core/enums/complained_content.dart';
import 'package:eatvio_app/core/locator_service.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/core/widgets/custom_popup.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/recipes_model.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter/material.dart';
@@ -185,6 +188,68 @@ void main() {
expect(find.text('Удалить'), findsOneWidget);
});
testWidgets('CustomPopup for author recipe shows edit when recipe is provided', (tester) async {
await tester.pumpWidget(
wrap(
CustomPopup(
isAuthor: true,
complainedContentType: ComplainedContent.recipe,
path: 'recipes/slug',
slug: 'slug',
recipe: _recipe(),
userSlug: 'author',
),
),
);
await tester.tap(find.byIcon(Icons.more_horiz_rounded));
await tester.pumpAndSettle();
expect(find.text('Редактировать'), findsOneWidget);
expect(find.text('Удалить'), findsOneWidget);
});
testWidgets('CustomPopup for author diet shows edit when diet is provided', (tester) async {
await tester.pumpWidget(
wrap(
CustomPopup(
isAuthor: true,
complainedContentType: ComplainedContent.diet,
path: 'diets/slug',
id: 1,
diet: _diet(),
userSlug: 'author',
),
),
);
await tester.tap(find.byIcon(Icons.more_horiz_rounded));
await tester.pumpAndSettle();
expect(find.text('Редактировать'), findsOneWidget);
});
testWidgets('CustomPopup for author plan shows edit when plan is provided', (tester) async {
await tester.pumpWidget(
wrap(
CustomPopup(
isAuthor: true,
complainedContentType: ComplainedContent.plan,
path: 'plans/slug',
slug: 'slug',
plan: _plan(),
userSlug: 'author',
),
),
);
await tester.tap(find.byIcon(Icons.more_horiz_rounded));
await tester.pumpAndSettle();
expect(find.text('Редактировать'), findsOneWidget);
expect(find.text('Удалить'), findsOneWidget);
});
testWidgets('CustomPopup for non-author without complained type still renders static actions', (tester) async {
await tester.pumpWidget(
wrap(
@@ -206,5 +271,72 @@ void main() {
expect(find.text('Пожаловаться'), findsOneWidget);
expect(find.text('Заблокировать автора'), findsOneWidget);
});
}
Recipe _recipe() {
return const Recipe(
id: 1,
image: 'image.jpg',
state: 'active',
cookingTime: 30,
activeCookingTime: 15,
ingredients: null,
description: 'Описание',
steps: null,
videoUrl: null,
title: 'Рецепт',
type: 'main',
slug: 'recipe-slug',
commentsCount: 0,
wasLikedByMe: false,
isFavorite: false,
calories: 100,
likesCount: 0,
viewsCount: 0,
tags: [],
author: Author(authorSlug: 'author', authorName: 'Author', authorProfileIcon: 'icon.jpg', authorIsMe: true),
);
}
Diet _diet() {
return const Diet(
id: 1,
slug: 'diet-slug',
name: 'Диета',
image: 'image.jpg',
duration: 7,
state: DietState.active,
type: DietType(),
details: 'Описание',
dailySchedule: {},
author: Author(authorSlug: 'author', authorName: 'Author', authorProfileIcon: 'icon.jpg', authorIsMe: true),
totalLikes: 0,
totalViews: 0,
totalComments: 0,
wasLikedByMe: false,
isFavorite: false,
dailyNutrition: [],
);
}
PlanModel _plan() {
return const PlanModel(
id: 1,
slug: 'plan-slug',
name: 'План',
image: 'image.jpg',
duration: 7,
state: 'active',
type: PlanType(fit: true, slim: false, behavior: false, wellness: false),
details: 'Описание',
packetsCount: 1,
author: Author(authorSlug: 'author', authorName: 'Author', authorProfileIcon: 'icon.jpg', authorIsMe: true),
totalLikes: 0,
totalViews: 0,
totalComments: 0,
isFavorite: false,
minPriceOfOptions: 1200,
maxPriceOfOptions: 1200,
wasLikedByMe: false,
);
}

View File

@@ -1,5 +1,7 @@
import 'package:eatvio_app/features/create_plan/presentation/cubit/create_plan_cubit.dart';
import 'package:eatvio_app/features/create_plan/repositories/create_plan_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:flutter_image_compress/flutter_image_compress.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
@@ -703,6 +705,51 @@ void main() {
expect(cubit.state.planCreated, false);
});
test('loadExisting заполняет форму и обновляет существующий план', () async {
const plan = PlanModel(
id: 7,
slug: 'test-plan',
name: 'Test Plan',
image: 'cover.jpg',
duration: 14,
state: 'active',
type: PlanType(fit: true, slim: true, behavior: false, wellness: false),
details: 'Описание плана',
packetsCount: 1,
packet1Options: PacketOptions(
items: ['Консультации'],
price: 1500,
short: 'Базовый',
description: 'Описание опции',
hasPersonalDiet: false,
),
author: Author(authorSlug: 'author', authorName: 'Author', authorProfileIcon: 'icon.jpg', authorIsMe: true),
totalLikes: 0,
totalViews: 0,
totalComments: 0,
isFavorite: false,
minPriceOfOptions: 1500,
maxPriceOfOptions: 1500,
wasLikedByMe: false,
);
when(repository.updatePublishedPlan(slug: anyNamed('slug'), model: anyNamed('model'))).thenAnswer((_) async {});
cubit.loadExisting(plan);
expect(cubit.sourcePlan?.slug, 'test-plan');
expect(cubit.state.planData.name, 'Test Plan');
expect(cubit.state.planData.duration, 14);
expect(cubit.state.durationIndex, 1);
expect(cubit.state.planData.type, [true, true, false, false]);
expect(cubit.validateImage(), true);
await cubit.publishPlan();
verify(repository.updatePublishedPlan(slug: 'test-plan', model: anyNamed('model'))).called(1);
verifyNever(repository.createPlan(model: anyNamed('model')));
expect(cubit.state.planCreated, true);
});
test('setPlanType - валидирует тип когда хотя бы один выбран', () {
cubit.setPlanType([true, false, false, false]);
expect(cubit.state.validationState.typeHasError, false);

View File

@@ -47,5 +47,10 @@ class _NoopCreatePlanService implements CreatePlanService {
Future<void> createPlan({required FormData formData}) {
throw UnimplementedError('Not used in fixture tests');
}
@override
Future<void> updatePublishedPlan({required String slug, required FormData formData}) {
throw UnimplementedError('Not used in fixture tests');
}
}