forked from eatvio/eatvio_app
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:
311
test/core/error_reporting/api_response_reporting_test.dart
Normal file
311
test/core/error_reporting/api_response_reporting_test.dart
Normal file
@@ -0,0 +1,311 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/core/app_initializer.dart';
|
||||
import 'package:eatvio_app/core/di/app_config_registration.dart';
|
||||
import 'package:eatvio_app/core/di/external_registrations.dart';
|
||||
import 'package:eatvio_app/core/di/repository_registrations.dart';
|
||||
import 'package:eatvio_app/core/di/service_registrations.dart';
|
||||
import 'package:eatvio_app/core/error_reporting/error_report_policy.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/prefs_keys.dart';
|
||||
import 'package:eatvio_app/core/routing/other_routes.dart';
|
||||
import 'package:eatvio_app/core/routing/route_constants.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/features/notifications/models/notification_model.dart';
|
||||
import 'package:eatvio_app/features/notifications/service/notifications_service.dart';
|
||||
import 'package:eatvio_app/features/payment/repositories/payment_repository.dart';
|
||||
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||
import 'package:eatvio_app/features/recipe/presentation/cubit/about_recipe_cubit.dart';
|
||||
import 'package:eatvio_app/features/recipe/presentation/cubit/about_recipe_state.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
late _MemoryTransport transport;
|
||||
late List<SentryEvent> events;
|
||||
|
||||
setUp(() async {
|
||||
transport = _MemoryTransport();
|
||||
events = [];
|
||||
await Sentry.init((options) {
|
||||
options.dsn = 'https://test@example.invalid/1';
|
||||
options.transport = transport;
|
||||
options.sendClientReports = false;
|
||||
// Проверяем дедупликацию в приложении независимо от кеша SDK.
|
||||
options.enableDeduplication = false;
|
||||
options.beforeSend = (event, hint) {
|
||||
final prepared = ErrorReportPolicy.prepareSentryEvent(event, hint);
|
||||
if (prepared != null) events.add(prepared);
|
||||
return prepared;
|
||||
};
|
||||
});
|
||||
|
||||
dotenv.loadFromString(
|
||||
envString: 'DEV_BASE_URL=https://api.example.invalid',
|
||||
);
|
||||
SharedPreferences.setMockInitialValues({
|
||||
PrefsKeys.welcomeScreenWasShowed.name: true,
|
||||
'token': 'synthetic-token',
|
||||
});
|
||||
AppConfigRegistration.registerAppConfig(buildType: AppBuildType.tests);
|
||||
ExternalRegistrations.registerAll();
|
||||
ServiceRegistrations.registerAll();
|
||||
RepositoryRegistrations.registerAll();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
TokenStorage.clearCache();
|
||||
await sl.reset();
|
||||
await Sentry.close();
|
||||
});
|
||||
|
||||
test(
|
||||
'reports a missing recipe field once and keeps the original stack',
|
||||
() async {
|
||||
sl<Dio>().httpClientAdapter = _ResponseAdapter(200, '{}');
|
||||
final cubit = AboutRecipeCubit(
|
||||
recipeRepository: sl(),
|
||||
profileRepository: sl(),
|
||||
);
|
||||
addTearDown(cubit.close);
|
||||
|
||||
await cubit.initRecipe('private-recipe-id');
|
||||
await transport.waitForEvent();
|
||||
|
||||
expect(cubit.state, isA<RecipeStateError>());
|
||||
expect(events.single.tags?['origin'], 'api_response');
|
||||
expect(
|
||||
events.single.exceptions!.single.stackTrace!.frames.any(
|
||||
(frame) => frame.fileName?.endsWith('recipes_model.g.dart') ?? false,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
expect(transport.sent, hasLength(1));
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'reports a malformed profile even when the welcome redirect handles it',
|
||||
() async {
|
||||
final adapter = _ResponseAdapter(200, '{}');
|
||||
sl<Dio>().httpClientAdapter = adapter;
|
||||
final route = OtherRoutes.createRoutes().whereType<GoRoute>().singleWhere(
|
||||
(route) => route.path == RouteConstants.welcomeScreen,
|
||||
);
|
||||
|
||||
expect(
|
||||
await route.redirect!(_BuildContext(), _RouterState()),
|
||||
RouteConstants.authScreen,
|
||||
);
|
||||
await transport.waitForEvent();
|
||||
|
||||
expect(adapter.requests.single.path, '/api/profile/index');
|
||||
expect(events.single.exceptions!.single.value, contains('TypeError'));
|
||||
expect(transport.sent, hasLength(1));
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'reports invalid JSON without sending its contents or HTTP breadcrumbs',
|
||||
() async {
|
||||
const secret = 'private-patient-data';
|
||||
sl<Dio>().httpClientAdapter = _ResponseAdapter(200, '{"$secret":');
|
||||
await Sentry.addBreadcrumb(
|
||||
Breadcrumb.http(
|
||||
url: Uri.parse('https://api.example.invalid/user/$secret'),
|
||||
method: 'GET',
|
||||
httpQuery: 'profile=$secret',
|
||||
),
|
||||
);
|
||||
|
||||
await expectLater(
|
||||
sl<ProfileRepository>().getMyProfile(),
|
||||
throwsA(isA<DioException>()),
|
||||
);
|
||||
await transport.waitForEvent();
|
||||
|
||||
final event = events.single;
|
||||
expect(event.exceptions!.single.value, contains('FormatException'));
|
||||
expect(event.exceptions!.single.stackTrace!.frames, isNotEmpty);
|
||||
expect(event.tags?['origin'], 'api_response');
|
||||
expect(
|
||||
event.contexts['report_extras'],
|
||||
containsPair('http_status_code', '200'),
|
||||
);
|
||||
expect(jsonEncode(event.toJson()), isNot(contains(secret)));
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'reports the wrong JSON root type before the Retrofit model parser',
|
||||
() async {
|
||||
sl<Dio>().httpClientAdapter = _ResponseAdapter(200, '[]');
|
||||
|
||||
await expectLater(
|
||||
sl<ProfileRepository>().getMyProfile(),
|
||||
throwsA(isA<DioException>()),
|
||||
);
|
||||
await transport.waitForEvent();
|
||||
|
||||
expect(events.single.exceptions!.single.value, contains('TypeError'));
|
||||
expect(
|
||||
events.single.contexts['report_extras'],
|
||||
containsPair('http_status_code', '200'),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'reports a malformed notification and keeps the replacement item',
|
||||
() async {
|
||||
sl<Dio>().httpClientAdapter = _ResponseAdapter(
|
||||
200,
|
||||
'{"data":[17],"current_page":1,"last_page":1,"per_page":20,"total":1}',
|
||||
);
|
||||
|
||||
final result = await sl<NotificationsService>().getNotifications(page: 1);
|
||||
await transport.waitForEvent();
|
||||
|
||||
expect(
|
||||
(result!['notifications'] as List).single,
|
||||
isA<UnknownNotification>(),
|
||||
);
|
||||
expect(
|
||||
events.single.contexts['report_extras'],
|
||||
containsPair('endpoint', '/api/profile/notifications'),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'reports an invalid minimum version and still skips the update screen',
|
||||
() async {
|
||||
PackageInfo.setMockInitialValues(
|
||||
appName: 'Eatvio',
|
||||
packageName: 'example.invalid',
|
||||
version: '1.0.0',
|
||||
buildNumber: '1',
|
||||
buildSignature: '',
|
||||
);
|
||||
sl<Dio>().httpClientAdapter = _ResponseAdapter(
|
||||
200,
|
||||
'{"min_version":"invalid"}',
|
||||
);
|
||||
final route = OtherRoutes.createRoutes().whereType<GoRoute>().singleWhere(
|
||||
(route) => route.path == RouteConstants.updateScreen,
|
||||
);
|
||||
|
||||
expect(
|
||||
await route.redirect!(_BuildContext(), _RouterState()),
|
||||
RouteConstants.welcomeScreen,
|
||||
);
|
||||
await transport.waitForEvent();
|
||||
|
||||
expect(
|
||||
events.single.contexts['report_extras'],
|
||||
containsPair('endpoint', '/api/app_versions'),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'reports a malformed 422 promo response after its manual parse',
|
||||
() async {
|
||||
sl<Dio>().httpClientAdapter = _ResponseAdapter(422, '{}');
|
||||
|
||||
await expectLater(
|
||||
sl<PaymentRepository>().applyPromoCode(
|
||||
planId: 42,
|
||||
promoCode: 'private',
|
||||
),
|
||||
throwsA(isA<TypeError>()),
|
||||
);
|
||||
await transport.waitForEvent();
|
||||
|
||||
expect(
|
||||
events.single.contexts['report_extras'],
|
||||
containsPair('http_status_code', '422'),
|
||||
);
|
||||
expect(transport.sent, hasLength(1));
|
||||
},
|
||||
);
|
||||
|
||||
test('keeps expected 4xx quiet and captures a regular 5xx once', () async {
|
||||
final dio = sl<Dio>();
|
||||
final cubit = AboutRecipeCubit(
|
||||
recipeRepository: sl(),
|
||||
profileRepository: sl(),
|
||||
);
|
||||
addTearDown(cubit.close);
|
||||
|
||||
dio.httpClientAdapter = _ResponseAdapter(404, '{}');
|
||||
await cubit.initRecipe('synthetic');
|
||||
expect(events, isEmpty);
|
||||
|
||||
dio.httpClientAdapter = _ResponseAdapter(500, '{}');
|
||||
await cubit.initRecipe('synthetic');
|
||||
await transport.waitForEvent();
|
||||
|
||||
expect(
|
||||
events.single.exceptions!.first.mechanism!.type,
|
||||
'SentryDioClientAdapter',
|
||||
);
|
||||
expect(transport.sent, hasLength(1));
|
||||
});
|
||||
}
|
||||
|
||||
class _ResponseAdapter implements HttpClientAdapter {
|
||||
_ResponseAdapter(this.statusCode, this.body);
|
||||
|
||||
final int statusCode;
|
||||
final String body;
|
||||
final requests = <RequestOptions>[];
|
||||
|
||||
@override
|
||||
Future<ResponseBody> fetch(
|
||||
RequestOptions options,
|
||||
Stream<Uint8List>? requestStream,
|
||||
Future<void>? cancelFuture,
|
||||
) async {
|
||||
requests.add(options);
|
||||
return ResponseBody.fromString(
|
||||
body,
|
||||
statusCode,
|
||||
headers: {
|
||||
Headers.contentTypeHeader: [Headers.jsonContentType],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void close({bool force = false}) {}
|
||||
}
|
||||
|
||||
class _MemoryTransport implements Transport {
|
||||
final sent = <SentryEnvelope>[];
|
||||
final _firstEvent = Completer<void>();
|
||||
|
||||
Future<void> waitForEvent() =>
|
||||
_firstEvent.future.timeout(const Duration(seconds: 2));
|
||||
|
||||
@override
|
||||
Future<SentryId?> send(SentryEnvelope envelope) async {
|
||||
sent.add(envelope);
|
||||
if (!_firstEvent.isCompleted) _firstEvent.complete();
|
||||
return envelope.header.eventId;
|
||||
}
|
||||
}
|
||||
|
||||
class _BuildContext extends Fake implements BuildContext {}
|
||||
|
||||
class _RouterState extends Fake implements GoRouterState {}
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user