test(tests): add extensive widget tests for MarkdownEditor and CommentsActionsBottomSheet, improving test coverage and functionality validation

This commit is contained in:
mso7nueh
2025-12-11 21:19:41 +03:00
parent d1753e99f8
commit c378c7fc16
44 changed files with 1783 additions and 2 deletions

View File

@@ -123,6 +123,200 @@ void main() {
// Состояние должно быть error из-за ошибки загрузки профиля
expect(cubit!.state, isA<ProfileAvatarStateError>());
});
test('getMyProfile - обработка ошибки при получении деталей профиля', () async {
cubit = ProfileAvatarCubit(profileRepository: mockRepository);
const testProfile = ProfileModel(
id: 1,
slug: 'test-user',
name: 'Test User',
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: [],
);
when(mockRepository.getMyProfile())
.thenAnswer((_) async => testProfile);
when(mockRepository.getMyProfileDetails())
.thenThrow(Exception('Ошибка загрузки деталей'));
await cubit!.getMyProfile();
await Future.delayed(const Duration(milliseconds: 100));
// Если детали не загрузились, выбрасывается исключение и состояние становится error
expect(cubit!.state, isA<ProfileAvatarStateError>());
});
test('getMyProfile - обработка ошибки при получении профиля', () async {
cubit = ProfileAvatarCubit(profileRepository: mockRepository);
when(mockRepository.getMyProfile())
.thenThrow(Exception('Ошибка загрузки профиля'));
await cubit!.getMyProfile();
// Состояние должно быть error
expect(cubit!.state, isA<ProfileAvatarStateError>());
final errorState = cubit!.state as ProfileAvatarStateError;
expect(errorState.errorMessage, contains('Ошибка загрузки профиля'));
});
test('getMyProfile - успешная загрузка с женским полом', () async {
cubit = ProfileAvatarCubit(profileRepository: mockRepository);
const testProfile = ProfileModel(
id: 1,
slug: 'test-user',
name: 'Test User',
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: [],
);
const testProfileDetails = ProfileDetailsModel(
firstName: 'Test',
lastName: 'User',
birthdate: '1990-01-01',
gender: 'female',
country: 'Russia',
city: 'Moscow',
lang: 'ru',
weight: 60.0,
height: 165,
chestCircumference: 90,
waistCircumference: 70,
hipCircumference: 95,
bloodPressureUp: 110,
bloodPressureDown: 70,
hasHypo: false,
hasHyper: false,
aboutAlergy: 'No allergies',
aboutTakingPils: 'No pills',
aboutSportHobbies: 'Yoga',
favoriteFoods: 'Vegetables',
unfavoriteFoods: 'Meat',
additionalInfo: 'Additional info',
isMoodFillable: true,
isBedtimeFillable: true,
activityCoefficient: 1.2,
);
when(mockRepository.getMyProfile())
.thenAnswer((_) async => testProfile);
when(mockRepository.getMyProfileDetails())
.thenAnswer((_) async => testProfileDetails);
ProfileAvatarState? loadedState;
final subscription = cubit!.stream.listen((state) {
if (state is ProfileAvatarStateLoaded) {
loadedState = state;
}
});
try {
await cubit!.getMyProfile();
await Future.delayed(const Duration(milliseconds: 100));
} catch (e) {
// Игнорируем ошибки плагинов
} finally {
await subscription.cancel();
}
expect(loadedState, isNotNull);
});
test('getMyProfile - успешная загрузка с различными форматами даты рождения', () async {
cubit = ProfileAvatarCubit(profileRepository: mockRepository);
const testProfile = ProfileModel(
id: 1,
slug: 'test-user',
name: 'Test User',
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: [],
);
// Тест с датой рождения в будущем (для проверки расчета возраста)
const testProfileDetails = ProfileDetailsModel(
firstName: 'Test',
lastName: 'User',
birthdate: '2000-06-15',
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: 'No allergies',
aboutTakingPils: 'No pills',
aboutSportHobbies: 'Running',
favoriteFoods: 'Fruits',
unfavoriteFoods: 'Fast food',
additionalInfo: 'Additional info',
isMoodFillable: true,
isBedtimeFillable: true,
activityCoefficient: 1.5,
);
when(mockRepository.getMyProfile())
.thenAnswer((_) async => testProfile);
when(mockRepository.getMyProfileDetails())
.thenAnswer((_) async => testProfileDetails);
ProfileAvatarState? loadedState;
final subscription = cubit!.stream.listen((state) {
if (state is ProfileAvatarStateLoaded) {
loadedState = state;
}
});
try {
await cubit!.getMyProfile();
await Future.delayed(const Duration(milliseconds: 100));
} catch (e) {
// Игнорируем ошибки плагинов
} finally {
await subscription.cancel();
}
expect(loadedState, isNotNull);
});
});
}