fix: plans - like and bookmark in consultant profile (#582)

- decouple PlanWidget from feed PlansCubit via owner-provided callbacks
- add like/favorite actions to profile PlansCubit: slug lookup, optimistic
  update, rollback of the affected plan, per-slug debounce, isClosed guards
- pass slug through like/favorite/comments events; guard out-of-range index
  in feed plans handlers and deep-link about_plan sync
- capture post like intent before await in profile blog post widget
- replace null force-unwraps in profile screen, guard indexOf == -1
- tests: profile plan like/bookmark, slug sync, bounds guards, #700 regression
This commit is contained in:
2026-11-20 16:30:13 +03:00
parent 1e8c1ab2eb
commit 0df474b2b5
22 changed files with 2139 additions and 137 deletions

View File

@@ -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);
});
});
}