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');
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import 'package:eatvio_app/features/settings/entities/settings_entity.dart';
|
||||
import 'package:eatvio_app/features/settings/presentation/pages/change_password_screen.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_cubit.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import '../../../../fixtures/settings_fixtures.dart';
|
||||
import '../bloc/settings_cubit_test.mocks.dart';
|
||||
|
||||
void main() {
|
||||
group('ChangePasswordScreen', () {
|
||||
late SettingsCubit settingsCubit;
|
||||
late MockProfileRepository mockProfileRepository;
|
||||
late MockSettingsRepository mockSettingsRepository;
|
||||
late MockConsultantRepository mockConsultantRepository;
|
||||
late MockConsultationsRepository mockConsultationsRepository;
|
||||
|
||||
setUp(() {
|
||||
mockProfileRepository = MockProfileRepository();
|
||||
mockSettingsRepository = MockSettingsRepository();
|
||||
mockConsultantRepository = MockConsultantRepository();
|
||||
mockConsultationsRepository = MockConsultationsRepository();
|
||||
settingsCubit = SettingsCubit(
|
||||
profileRepository: mockProfileRepository,
|
||||
settingsRepository: mockSettingsRepository,
|
||||
consultantRepository: mockConsultantRepository,
|
||||
consultationsRepository: mockConsultationsRepository,
|
||||
);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
settingsCubit.close();
|
||||
});
|
||||
|
||||
testWidgets('отображает экран смены пароля', (tester) async {
|
||||
final settingsEntity = SettingsEntity(
|
||||
profileSettingsModel: SettingsFixtures.profileSettingsModel(),
|
||||
profileDetailsModel: SettingsFixtures.profileDetailsModel(),
|
||||
settingsCubit: settingsCubit,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: S.delegate.supportedLocales,
|
||||
home: ChangePasswordScreen(settingsEntity: settingsEntity),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(ChangePasswordScreen), findsOneWidget);
|
||||
expect(find.text('Смена пароля'), findsOneWidget);
|
||||
expect(find.text('Coming soon...'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('имеет AppBar с заголовком', (tester) async {
|
||||
final settingsEntity = SettingsEntity(
|
||||
profileSettingsModel: SettingsFixtures.profileSettingsModel(),
|
||||
profileDetailsModel: SettingsFixtures.profileDetailsModel(),
|
||||
settingsCubit: settingsCubit,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: S.delegate.supportedLocales,
|
||||
home: ChangePasswordScreen(settingsEntity: settingsEntity),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(AppBar), findsOneWidget);
|
||||
expect(find.text('Смена пароля'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user