forked from eatvio/eatvio_app
test(tests): add comprehensive unit tests for various models and repositories, enhancing test coverage and ensuring correct functionality
This commit is contained in:
@@ -0,0 +1,166 @@
|
||||
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart';
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'package:eatvio_app/features/settings/models/profile_settings_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('SettingsState', () {
|
||||
test('создает базовый SettingsState', () {
|
||||
const state = SettingsState();
|
||||
|
||||
expect(state, isA<SettingsState>());
|
||||
});
|
||||
});
|
||||
|
||||
group('SettingsStateLoading', () {
|
||||
test('создает SettingsStateLoading', () {
|
||||
const state = SettingsState.loading();
|
||||
|
||||
expect(state, isA<SettingsStateLoading>());
|
||||
});
|
||||
});
|
||||
|
||||
group('SettingsStateLoaded', () {
|
||||
test('создает SettingsStateLoaded с правильными значениями', () {
|
||||
const profileSettings = ProfileSettingsModel(
|
||||
newUpdatesNotifications: true,
|
||||
diaryReminderNotifications: true,
|
||||
isMoodFillable: true,
|
||||
isBedtimeFillable: true,
|
||||
isPublicProfile: true,
|
||||
);
|
||||
|
||||
const profileDetails = 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 profile = ProfileModel(
|
||||
id: 1,
|
||||
name: 'Test User',
|
||||
email: 'test@example.com',
|
||||
phoneConfirmationState: 'confirmed',
|
||||
slug: 'test-user',
|
||||
isPublicProfile: true,
|
||||
isBlockedByMe: false,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
profilePhotoUrl: '',
|
||||
roles: [],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
|
||||
const state = SettingsState.loaded(profileSettings: profileSettings, profileDetails: profileDetails, profile: profile, hasActiveConsultation: false);
|
||||
|
||||
expect(state, isA<SettingsStateLoaded>());
|
||||
const loadedState = state as SettingsStateLoaded;
|
||||
expect(loadedState.profileSettings, profileSettings);
|
||||
expect(loadedState.profileDetails, profileDetails);
|
||||
expect(loadedState.profile, profile);
|
||||
expect(loadedState.hasActiveConsultation, false);
|
||||
});
|
||||
|
||||
test('создает SettingsStateLoaded с consultationRequestModel', () {
|
||||
const profileSettings = ProfileSettingsModel(
|
||||
newUpdatesNotifications: true,
|
||||
diaryReminderNotifications: true,
|
||||
isMoodFillable: true,
|
||||
isBedtimeFillable: true,
|
||||
isPublicProfile: true,
|
||||
);
|
||||
|
||||
const profileDetails = 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 profile = ProfileModel(
|
||||
id: 1,
|
||||
name: 'Test User',
|
||||
email: 'test@example.com',
|
||||
phoneConfirmationState: 'confirmed',
|
||||
slug: 'test-user',
|
||||
isPublicProfile: true,
|
||||
isBlockedByMe: false,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
profilePhotoUrl: '',
|
||||
roles: [],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
|
||||
const state = SettingsState.loaded(
|
||||
profileSettings: profileSettings,
|
||||
profileDetails: profileDetails,
|
||||
profile: profile,
|
||||
consultationRequestModel: null,
|
||||
hasActiveConsultation: true,
|
||||
);
|
||||
|
||||
const loadedState = state as SettingsStateLoaded;
|
||||
expect(loadedState.hasActiveConsultation, true);
|
||||
});
|
||||
});
|
||||
|
||||
group('SettingsStateError', () {
|
||||
test('создает SettingsStateError с сообщением об ошибке', () {
|
||||
const state = SettingsState.error(errorMessage: 'Test error');
|
||||
|
||||
expect(state, isA<SettingsStateError>());
|
||||
const errorState = state as SettingsStateError;
|
||||
expect(errorState.errorMessage, 'Test error');
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user