Merge remote-tracking branch 'upstream_main' into HEAD

# Conflicts:
#	lib/generated/intl/messages_en.dart
#	lib/generated/intl/messages_ru.dart
This commit is contained in:
2026-11-23 22:48:19 +03:00
67 changed files with 3777 additions and 2899 deletions

View File

@@ -141,12 +141,46 @@ void main() {
await settingsCubit!.init();
await Future.delayed(const Duration(milliseconds: 100));
await settingsCubit!.updateProfileDetails(profileDetailsModel: SettingsFixtures.profileDetailsModel());
final result = await settingsCubit!.updateProfileDetails(profileDetailsModel: SettingsFixtures.profileDetailsModel());
await Future.delayed(const Duration(milliseconds: 100));
expect(result, true);
verify(mockSettingsRepository.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).called(1);
});
test('updateProfileDetails - возвращает false при ошибке и перезагружает состояние', () async {
settingsCubit = SettingsCubit(
profileRepository: mockProfileRepository,
settingsRepository: mockSettingsRepository,
consultantRepository: mockConsultantRepository,
consultationsRepository: mockConsultationsRepository,
sessionLifecycleService: fakeSession,
);
when(mockProfileRepository.getMyProfile())
.thenAnswer((_) async => SettingsFixtures.profileModel());
when(mockConsultantRepository.getMyRequestStatus(any))
.thenThrow(Exception('Not found'));
when(mockConsultationsRepository.getUserPurchases(any, any))
.thenAnswer((_) async => []);
when(mockSettingsRepository.getOAuthAccounts())
.thenAnswer((_) async => SettingsFixtures.oauthAccountsResponseModel());
when(mockSettingsRepository.getProfileSettings())
.thenAnswer((_) async => SettingsFixtures.profileSettingsModel());
when(mockProfileRepository.getMyProfileDetails())
.thenAnswer((_) async => SettingsFixtures.profileDetailsModel());
when(mockSettingsRepository.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel')))
.thenThrow(Exception('Ошибка сохранения'));
await settingsCubit!.init();
await Future.delayed(const Duration(milliseconds: 100));
final result = await settingsCubit!.updateProfileDetails(profileDetailsModel: SettingsFixtures.profileDetailsModel());
await Future.delayed(const Duration(milliseconds: 100));
expect(result, false);
expect(settingsCubit!.state, isA<SettingsStateLoaded>());
});
test('updateProfileSettings - обновляет настройки профиля', () async {
settingsCubit = SettingsCubit(
profileRepository: mockProfileRepository,
@@ -173,12 +207,46 @@ void main() {
await settingsCubit!.init();
await Future.delayed(const Duration(milliseconds: 100));
await settingsCubit!.updateProfileSettings(profileSettingsModel: SettingsFixtures.profileSettingsModel());
final result = await settingsCubit!.updateProfileSettings(profileSettingsModel: SettingsFixtures.profileSettingsModel());
await Future.delayed(const Duration(milliseconds: 100));
expect(result, true);
verify(mockSettingsRepository.updateProfileSettings(profileSettingsModel: anyNamed('profileSettingsModel'))).called(1);
});
test('updateProfileSettings - возвращает false при ошибке и перезагружает состояние', () async {
settingsCubit = SettingsCubit(
profileRepository: mockProfileRepository,
settingsRepository: mockSettingsRepository,
consultantRepository: mockConsultantRepository,
consultationsRepository: mockConsultationsRepository,
sessionLifecycleService: fakeSession,
);
when(mockProfileRepository.getMyProfile())
.thenAnswer((_) async => SettingsFixtures.profileModel());
when(mockConsultantRepository.getMyRequestStatus(any))
.thenThrow(Exception('Not found'));
when(mockConsultationsRepository.getUserPurchases(any, any))
.thenAnswer((_) async => []);
when(mockSettingsRepository.getOAuthAccounts())
.thenAnswer((_) async => SettingsFixtures.oauthAccountsResponseModel());
when(mockSettingsRepository.getProfileSettings())
.thenAnswer((_) async => SettingsFixtures.profileSettingsModel());
when(mockProfileRepository.getMyProfileDetails())
.thenAnswer((_) async => SettingsFixtures.profileDetailsModel());
when(mockSettingsRepository.updateProfileSettings(profileSettingsModel: anyNamed('profileSettingsModel')))
.thenThrow(Exception('Ошибка сохранения'));
await settingsCubit!.init();
await Future.delayed(const Duration(milliseconds: 100));
final result = await settingsCubit!.updateProfileSettings(profileSettingsModel: SettingsFixtures.profileSettingsModel());
await Future.delayed(const Duration(milliseconds: 100));
expect(result, false);
expect(settingsCubit!.state, isA<SettingsStateLoaded>());
});
test('deleteAccount - удаляет аккаунт', () async {
settingsCubit = SettingsCubit(
profileRepository: mockProfileRepository,

View File

@@ -13,6 +13,7 @@ import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/se
import 'package:eatvio_app/features/settings/presentation/pages/general_info_screen.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -25,6 +26,8 @@ import 'general_info_screen_test.mocks.dart';
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
void main() {
group('GeneralInfoScreen smoke', () {
final toastCalls = <MethodCall>[];
setUpAll(() async {
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
});
@@ -32,6 +35,21 @@ void main() {
setUp(() async {
await sl.reset();
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
toastCalls.clear();
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
(MethodCall methodCall) async {
toastCalls.add(methodCall);
return null;
},
);
});
tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
null,
);
});
const mockProfile = ProfileModel(
@@ -95,7 +113,20 @@ void main() {
supportedLocales: const [Locale('ru')],
routerConfig: GoRouter(
initialLocation: '/',
routes: [GoRoute(path: '/', builder: (context, state) => child)],
routes: [
GoRoute(
path: '/',
builder: (context, state) => Scaffold(
body: Center(
child: TextButton(
onPressed: () => context.push('/screen'),
child: const Text('open screen'),
),
),
),
),
GoRoute(path: '/screen', builder: (context, state) => child),
],
),
);
}
@@ -112,7 +143,7 @@ void main() {
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
@@ -122,8 +153,8 @@ void main() {
child: wrap(GeneralInfoScreen(settingsEntity: settingsEntity)),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 200));
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
expect(find.byType(GeneralInfoScreen), findsOneWidget);
});
@@ -136,13 +167,13 @@ void main() {
profile: mockProfile,
hasActiveConsultation: false,
);
final saveCompleter = Completer<void>();
final saveCompleter = Completer<bool>();
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) => saveCompleter.future);
when(cubit.updateProfileSettings(profileSettingsModel: anyNamed('profileSettingsModel'))).thenAnswer((_) async {});
when(cubit.updateProfileSettings(profileSettingsModel: anyNamed('profileSettingsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
@@ -152,7 +183,8 @@ void main() {
child: wrap(GeneralInfoScreen(settingsEntity: settingsEntity)),
),
);
await tester.pump();
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
expect(find.text('Сохранить'), findsOneWidget);
expect(find.byType(Loader), findsNothing);
@@ -167,12 +199,88 @@ void main() {
final loaderSize = tester.getSize(find.byType(Loader));
expect(loaderSize.height, lessThan(60));
saveCompleter.complete();
saveCompleter.complete(true);
await tester.pump();
await tester.pumpAndSettle();
expect(find.byType(GeneralInfoScreen), findsNothing);
expect(find.text('open screen'), findsOneWidget);
await tester.pump(const Duration(seconds: 2));
});
testWidgets('показывает уведомление после успешного сохранения', (tester) async {
final cubit = MockSettingsCubit();
const state = SettingsState.loaded(
profileSettings: mockProfileSettings,
profileDetails: mockProfileDetails,
profile: mockProfile,
hasActiveConsultation: false,
);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
when(cubit.updateProfileSettings(profileSettingsModel: anyNamed('profileSettingsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
await tester.pumpWidget(
BlocProvider<SettingsCubit>.value(
value: cubit,
child: wrap(GeneralInfoScreen(settingsEntity: settingsEntity)),
),
);
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
await tester.tap(find.text('Сохранить'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
expect(find.text('Сохранить'), findsOneWidget);
expect(find.byType(Loader), findsNothing);
final toastMessages = toastCalls.where((call) => call.method == 'showToast').map((call) => call.arguments['msg']);
expect(toastMessages, contains('Данные успешно сохранены'));
await tester.pumpAndSettle();
expect(find.byType(GeneralInfoScreen), findsNothing);
expect(find.text('open screen'), findsOneWidget);
await tester.pump(const Duration(seconds: 2));
});
testWidgets('не показывает уведомление, если сохранение не удалось', (tester) async {
final cubit = MockSettingsCubit();
const state = SettingsState.loaded(
profileSettings: mockProfileSettings,
profileDetails: mockProfileDetails,
profile: mockProfile,
hasActiveConsultation: false,
);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => false);
when(cubit.updateProfileSettings(profileSettingsModel: anyNamed('profileSettingsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
await tester.pumpWidget(
BlocProvider<SettingsCubit>.value(
value: cubit,
child: wrap(GeneralInfoScreen(settingsEntity: settingsEntity)),
),
);
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
await tester.tap(find.text('Сохранить'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
expect(toastCalls.where((call) => call.method == 'showToast'), isEmpty);
expect(find.byType(GeneralInfoScreen), findsOneWidget);
});
});
}

View File

@@ -10,6 +10,7 @@ import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/se
import 'package:eatvio_app/features/settings/presentation/pages/other_info_screen.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -22,6 +23,8 @@ import 'other_info_screen_test.mocks.dart';
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
void main() {
group('OtherInfoScreen smoke', () {
final toastCalls = <MethodCall>[];
setUpAll(() async {
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
});
@@ -29,6 +32,21 @@ void main() {
setUp(() async {
await sl.reset();
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
toastCalls.clear();
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
(MethodCall methodCall) async {
toastCalls.add(methodCall);
return null;
},
);
});
tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
null,
);
});
const mockProfile = ProfileModel(
@@ -92,7 +110,20 @@ void main() {
supportedLocales: const [Locale('ru')],
routerConfig: GoRouter(
initialLocation: '/',
routes: [GoRoute(path: '/', builder: (context, state) => child)],
routes: [
GoRoute(
path: '/',
builder: (context, state) => Scaffold(
body: Center(
child: TextButton(
onPressed: () => context.push('/screen'),
child: const Text('open screen'),
),
),
),
),
GoRoute(path: '/screen', builder: (context, state) => child),
],
),
);
}
@@ -109,9 +140,7 @@ void main() {
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async {
return Future<void>.value();
});
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
@@ -121,10 +150,82 @@ void main() {
child: wrap(OtherInfoScreen(settingsEntity: settingsEntity)),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
expect(find.byType(OtherInfoScreen), findsOneWidget);
});
testWidgets('показывает уведомление и возвращается к настройкам после успешного сохранения', (tester) async {
final cubit = MockSettingsCubit();
const state = SettingsState.loaded(
profileSettings: mockProfileSettings,
profileDetails: mockProfileDetails,
profile: mockProfile,
hasActiveConsultation: false,
);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
await tester.pumpWidget(
BlocProvider<SettingsCubit>.value(
value: cubit,
child: wrap(OtherInfoScreen(settingsEntity: settingsEntity)),
),
);
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
await tester.tap(find.text('Сохранить'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
final toastMessages = toastCalls.where((call) => call.method == 'showToast').map((call) => call.arguments['msg']);
expect(toastMessages, contains('Данные успешно сохранены'));
await tester.pumpAndSettle();
expect(find.byType(OtherInfoScreen), findsNothing);
expect(find.text('open screen'), findsOneWidget);
await tester.pump(const Duration(seconds: 2));
});
testWidgets('не показывает уведомление и остаётся на экране при ошибке сохранения', (tester) async {
final cubit = MockSettingsCubit();
const state = SettingsState.loaded(
profileSettings: mockProfileSettings,
profileDetails: mockProfileDetails,
profile: mockProfile,
hasActiveConsultation: false,
);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => false);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
await tester.pumpWidget(
BlocProvider<SettingsCubit>.value(
value: cubit,
child: wrap(OtherInfoScreen(settingsEntity: settingsEntity)),
),
);
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
await tester.tap(find.text('Сохранить'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
expect(toastCalls.where((call) => call.method == 'showToast'), isEmpty);
expect(find.byType(OtherInfoScreen), findsOneWidget);
});
});
}

View File

@@ -8,7 +8,9 @@ import 'package:eatvio_app/features/settings/models/profile_settings_model.dart'
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_cubit.dart';
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart';
import 'package:eatvio_app/features/settings/presentation/pages/physical_activity_screen.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -21,6 +23,8 @@ import 'physical_activity_screen_test.mocks.dart';
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
void main() {
group('PhysicalActivityScreen smoke', () {
final toastCalls = <MethodCall>[];
setUpAll(() async {
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
});
@@ -28,6 +32,21 @@ void main() {
setUp(() async {
await sl.reset();
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
toastCalls.clear();
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
(MethodCall methodCall) async {
toastCalls.add(methodCall);
return null;
},
);
});
tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
null,
);
});
const mockProfile = ProfileModel(
@@ -87,9 +106,24 @@ void main() {
Widget wrap(Widget child) {
return MaterialApp.router(
theme: ThemeHelper().themeData(),
localizationsDelegates: const [S.delegate, ...GlobalMaterialLocalizations.delegates],
supportedLocales: const [Locale('ru')],
routerConfig: GoRouter(
initialLocation: '/',
routes: [GoRoute(path: '/', builder: (context, state) => child)],
routes: [
GoRoute(
path: '/',
builder: (context, state) => Scaffold(
body: Center(
child: TextButton(
onPressed: () => context.push('/screen'),
child: const Text('open screen'),
),
),
),
),
GoRoute(path: '/screen', builder: (context, state) => child),
],
),
);
}
@@ -106,7 +140,7 @@ void main() {
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
@@ -116,10 +150,82 @@ void main() {
child: wrap(PhysicalActivityScreen(settingsEntity: settingsEntity)),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 200));
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
expect(find.byType(PhysicalActivityScreen), findsOneWidget);
});
testWidgets('показывает уведомление и возвращается к настройкам после успешного сохранения', (tester) async {
final cubit = MockSettingsCubit();
const state = SettingsState.loaded(
profileSettings: mockProfileSettings,
profileDetails: mockProfileDetails,
profile: mockProfile,
hasActiveConsultation: false,
);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
await tester.pumpWidget(
BlocProvider<SettingsCubit>.value(
value: cubit,
child: wrap(PhysicalActivityScreen(settingsEntity: settingsEntity)),
),
);
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
await tester.tap(find.text('Сохранить'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
final toastMessages = toastCalls.where((call) => call.method == 'showToast').map((call) => call.arguments['msg']);
expect(toastMessages, contains('Данные успешно сохранены'));
await tester.pumpAndSettle();
expect(find.byType(PhysicalActivityScreen), findsNothing);
expect(find.text('open screen'), findsOneWidget);
await tester.pump(const Duration(seconds: 2));
});
testWidgets('не показывает уведомление и остаётся на экране при ошибке сохранения', (tester) async {
final cubit = MockSettingsCubit();
const state = SettingsState.loaded(
profileSettings: mockProfileSettings,
profileDetails: mockProfileDetails,
profile: mockProfile,
hasActiveConsultation: false,
);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => false);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
await tester.pumpWidget(
BlocProvider<SettingsCubit>.value(
value: cubit,
child: wrap(PhysicalActivityScreen(settingsEntity: settingsEntity)),
),
);
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
await tester.tap(find.text('Сохранить'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
expect(toastCalls.where((call) => call.method == 'showToast'), isEmpty);
expect(find.byType(PhysicalActivityScreen), findsOneWidget);
});
});
}

View File

@@ -10,6 +10,7 @@ import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/se
import 'package:eatvio_app/features/settings/presentation/pages/physical_form_screen.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -22,6 +23,8 @@ import 'physical_form_screen_test.mocks.dart';
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
void main() {
group('PhysicalFormScreen smoke', () {
final toastCalls = <MethodCall>[];
setUpAll(() async {
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
});
@@ -29,6 +32,21 @@ void main() {
setUp(() async {
await sl.reset();
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
toastCalls.clear();
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
(MethodCall methodCall) async {
toastCalls.add(methodCall);
return null;
},
);
});
tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
null,
);
});
const mockProfile = ProfileModel(
@@ -92,7 +110,20 @@ void main() {
supportedLocales: const [Locale('ru')],
routerConfig: GoRouter(
initialLocation: '/',
routes: [GoRoute(path: '/', builder: (context, state) => child)],
routes: [
GoRoute(
path: '/',
builder: (context, state) => Scaffold(
body: Center(
child: TextButton(
onPressed: () => context.push('/screen'),
child: const Text('open screen'),
),
),
),
),
GoRoute(path: '/screen', builder: (context, state) => child),
],
),
);
}
@@ -109,7 +140,7 @@ void main() {
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
@@ -119,10 +150,82 @@ void main() {
child: wrap(PhysicalFormScreen(settingsEntity: settingsEntity)),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
expect(find.byType(PhysicalFormScreen), findsOneWidget);
});
testWidgets('показывает уведомление и возвращается к настройкам после успешного сохранения', (tester) async {
final cubit = MockSettingsCubit();
const state = SettingsState.loaded(
profileSettings: mockProfileSettings,
profileDetails: mockProfileDetails,
profile: mockProfile,
hasActiveConsultation: false,
);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
await tester.pumpWidget(
BlocProvider<SettingsCubit>.value(
value: cubit,
child: wrap(PhysicalFormScreen(settingsEntity: settingsEntity)),
),
);
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
await tester.tap(find.text('Сохранить'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
final toastMessages = toastCalls.where((call) => call.method == 'showToast').map((call) => call.arguments['msg']);
expect(toastMessages, contains('Данные успешно сохранены'));
await tester.pumpAndSettle();
expect(find.byType(PhysicalFormScreen), findsNothing);
expect(find.text('open screen'), findsOneWidget);
await tester.pump(const Duration(seconds: 2));
});
testWidgets('не показывает уведомление и остаётся на экране при ошибке сохранения', (tester) async {
final cubit = MockSettingsCubit();
const state = SettingsState.loaded(
profileSettings: mockProfileSettings,
profileDetails: mockProfileDetails,
profile: mockProfile,
hasActiveConsultation: false,
);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => false);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
await tester.pumpWidget(
BlocProvider<SettingsCubit>.value(
value: cubit,
child: wrap(PhysicalFormScreen(settingsEntity: settingsEntity)),
),
);
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
await tester.tap(find.text('Сохранить'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
expect(toastCalls.where((call) => call.method == 'showToast'), isEmpty);
expect(find.byType(PhysicalFormScreen), findsOneWidget);
});
});
}

View File

@@ -10,6 +10,7 @@ import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/se
import 'package:eatvio_app/features/settings/presentation/pages/pressure_screen.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -22,6 +23,8 @@ import 'pressure_screen_test.mocks.dart';
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
void main() {
group('PressureScreen smoke', () {
final toastCalls = <MethodCall>[];
setUpAll(() async {
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
});
@@ -29,6 +32,21 @@ void main() {
setUp(() async {
await sl.reset();
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
toastCalls.clear();
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
(MethodCall methodCall) async {
toastCalls.add(methodCall);
return null;
},
);
});
tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('PonnamKarthik/fluttertoast'),
null,
);
});
const mockProfile = ProfileModel(
@@ -92,7 +110,20 @@ void main() {
supportedLocales: const [Locale('ru')],
routerConfig: GoRouter(
initialLocation: '/',
routes: [GoRoute(path: '/', builder: (context, state) => child)],
routes: [
GoRoute(
path: '/',
builder: (context, state) => Scaffold(
body: Center(
child: TextButton(
onPressed: () => context.push('/screen'),
child: const Text('open screen'),
),
),
),
),
GoRoute(path: '/screen', builder: (context, state) => child),
],
),
);
}
@@ -109,7 +140,7 @@ void main() {
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
@@ -119,10 +150,82 @@ void main() {
child: wrap(PressureScreen(settingsEntity: settingsEntity)),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
expect(find.byType(PressureScreen), findsOneWidget);
});
testWidgets('показывает уведомление и возвращается к настройкам после успешного сохранения', (tester) async {
final cubit = MockSettingsCubit();
const state = SettingsState.loaded(
profileSettings: mockProfileSettings,
profileDetails: mockProfileDetails,
profile: mockProfile,
hasActiveConsultation: false,
);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => true);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
await tester.pumpWidget(
BlocProvider<SettingsCubit>.value(
value: cubit,
child: wrap(PressureScreen(settingsEntity: settingsEntity)),
),
);
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
await tester.tap(find.text('Сохранить'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
final toastMessages = toastCalls.where((call) => call.method == 'showToast').map((call) => call.arguments['msg']);
expect(toastMessages, contains('Данные успешно сохранены'));
await tester.pumpAndSettle();
expect(find.byType(PressureScreen), findsNothing);
expect(find.text('open screen'), findsOneWidget);
await tester.pump(const Duration(seconds: 2));
});
testWidgets('не показывает уведомление и остаётся на экране при ошибке сохранения', (tester) async {
final cubit = MockSettingsCubit();
const state = SettingsState.loaded(
profileSettings: mockProfileSettings,
profileDetails: mockProfileDetails,
profile: mockProfile,
hasActiveConsultation: false,
);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateProfileDetails(profileDetailsModel: anyNamed('profileDetailsModel'))).thenAnswer((_) async => false);
final settingsEntity = SettingsEntity(profileSettingsModel: mockProfileSettings, profileDetailsModel: mockProfileDetails, settingsCubit: cubit);
await tester.pumpWidget(
BlocProvider<SettingsCubit>.value(
value: cubit,
child: wrap(PressureScreen(settingsEntity: settingsEntity)),
),
);
await tester.tap(find.text('open screen'));
await tester.pumpAndSettle();
await tester.tap(find.text('Сохранить'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
expect(toastCalls.where((call) => call.method == 'showToast'), isEmpty);
expect(find.byType(PressureScreen), findsOneWidget);
});
});
}