feat(setting): added profile data apdating for sttings screen, added validation for general info form

This commit is contained in:
misha
2026-04-14 09:28:02 +03:00
parent 631ceb2b7a
commit 684415ef5b
7 changed files with 291 additions and 189 deletions

View File

@@ -1,32 +1,64 @@
import 'package:eatvio_app/features/menu/presentation/bloc/menu_cubit/menu_state.dart';
import 'package:eatvio_app/features/profile/models/profile_model.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('MenuState', () {
test('creates MenuState instance', () {
final state = MenuState();
test('creates MenuState initial state', () {
const state = MenuState.initial();
expect(state, isNotNull);
expect(state, isA<MenuState>());
expect(state, isA<MenuStateInitial>());
});
test('creates multiple MenuState instances', () {
final state1 = MenuState();
final state2 = MenuState();
expect(state1, isNotNull);
expect(state2, isNotNull);
expect(state1, isA<MenuState>());
expect(state2, isA<MenuState>());
test('creates MenuState loading state', () {
const state = MenuState.loading();
expect(state, isNotNull);
expect(state, isA<MenuStateLoading>());
});
test('MenuState instances are not equal by default', () {
final state1 = MenuState();
final state2 = MenuState();
test('creates MenuState error state', () {
const state = MenuState.error();
expect(state, isNotNull);
expect(state, isA<MenuStateError>());
});
// MenuState is a regular class without overridden == operator,
// so instances are compared by reference
expect(state1 == state2, isFalse);
expect(state1, isNot(same(state2)));
test('creates MenuState loaded state', () {
const profile = ProfileModel(
id: 1,
name: 'Test',
email: 'test@example.com',
phoneConfirmationState: 'confirmed',
isPublicProfile: true,
isBlockedByMe: false,
isBlockedByAuthor: false,
isBlockedByUser: false,
isEntitySubscribedByMe: false,
profilePhotoUrl: 'https://example.com/icon.jpg',
roles: [],
badges: [],
subscriptions: [],
subscribers: [],
slug: 'test-user',
);
const state = MenuState.loaded(profileModel: profile);
expect(state, isNotNull);
expect(state, isA<MenuStateLoaded>());
expect((state as MenuStateLoaded).profileModel, isNotNull);
expect((state).profileModel.id, 1);
expect((state).profileModel.name, 'Test');
expect((state).profileModel.email, 'test@example.com');
expect((state).profileModel.phoneConfirmationState, 'confirmed');
expect((state).profileModel.isPublicProfile, true);
expect((state).profileModel.isBlockedByMe, false);
expect((state).profileModel.isBlockedByAuthor, false);
expect((state).profileModel.isBlockedByUser, false);
expect((state).profileModel.isEntitySubscribedByMe, false);
expect((state).profileModel.profilePhotoUrl, 'https://example.com/icon.jpg');
expect((state).profileModel.roles, []);
expect((state).profileModel.badges, []);
expect((state).profileModel.subscriptions, []);
expect((state).profileModel.subscribers, []);
expect((state).profileModel.slug, 'test-user');
});
});
}

View File

@@ -141,11 +141,12 @@ void main() {
final cubit = MenuCubit(repository);
when(repository.getPassKey(routeName: anyNamed('routeName'), routeParams: anyNamed('routeParams'))).thenAnswer((_) async => 'test-passkey');
when(repository.getMyProfile()).thenAnswer((_) async => mockUserProfile);
sl.registerLazySingleton<ProfileRepository>(() => repository);
sl.registerLazySingleton<MenuCubit>(() => cubit);
await tester.pumpWidget(wrap(const MenuScreen(profileModel: mockUserProfile)));
await tester.pumpWidget(wrap(const MenuScreen()));
await tester.pumpAndSettle();
expect(find.text('Меню'), findsOneWidget);
@@ -157,11 +158,12 @@ void main() {
final cubit = MenuCubit(repository);
when(repository.getPassKey(routeName: anyNamed('routeName'), routeParams: anyNamed('routeParams'))).thenAnswer((_) async => 'test-passkey');
when(repository.getMyProfile()).thenAnswer((_) async => mockConsultantProfile);
sl.registerLazySingleton<ProfileRepository>(() => repository);
sl.registerLazySingleton<MenuCubit>(() => cubit);
await tester.pumpWidget(wrap(const MenuScreen(profileModel: mockConsultantProfile)));
await tester.pumpWidget(wrap(const MenuScreen()));
await tester.pumpAndSettle();
expect(find.text('Меню'), findsOneWidget);