feat(push_notifications): issue-660, fix: issue-908

This commit is contained in:
misha
2026-10-14 08:16:20 +03:00
parent 98c175df44
commit dcd343e765
29 changed files with 2281 additions and 608 deletions

View File

@@ -23,7 +23,7 @@ void main() {
);
const state = NotificationSettingsStateLoaded(notificationSettings: settings);
expect(state.props, [settings]);
expect(state.props, [settings, null, null]);
expect(state.notificationSettings, settings);
});

View File

@@ -1,3 +1,4 @@
import 'package:dio/dio.dart';
import 'package:eatvio_app/features/menu/presentation/bloc/notification_settings_cubit/notification_settings_cubit.dart';
import 'package:eatvio_app/features/menu/presentation/bloc/notification_settings_cubit/notification_settings_state.dart';
import 'package:eatvio_app/features/menu/repositories/notification_settings_repository.dart';
@@ -103,6 +104,51 @@ void main() {
final errorState = notificationSettingsCubit!.state as NotificationSettingsStateError;
expect(errorState.errorMessage, contains('Ошибка обновления'));
});
test('updateNotificationSettings - validation error keeps the screen and exposes an alert', () async {
notificationSettingsCubit = NotificationSettingsCubit(
notificationSettingsRepository: mockNotificationSettingsRepository,
);
when(mockNotificationSettingsRepository.getNotificationSettings()).thenAnswer((_) async => MenuFixtures.notificationSettingsModel());
await notificationSettingsCubit!.getNotificationSettings();
const message = 'Между приемами пищи должна быть разница минимум час';
when(mockNotificationSettingsRepository.updateNotificationSettings(any)).thenThrow(
DioException(
requestOptions: RequestOptions(path: '/api/profile/update_notification_settings'),
type: DioExceptionType.badResponse,
response: Response(
requestOptions: RequestOptions(path: '/api/profile/update_notification_settings'),
statusCode: 422,
data: {
'message': message,
'errors': {
'diary_reminder_notifications.second_reminder': [message],
},
},
),
),
);
await notificationSettingsCubit!.updateNotificationSettings({
'diary_reminder_notifications': {
'second_reminder': {'enabled': true, 'local_time_hours': 9, 'local_time_mins': 30},
},
});
expect(notificationSettingsCubit!.state, isA<NotificationSettingsStateLoaded>());
final loadedState = notificationSettingsCubit!.state as NotificationSettingsStateLoaded;
expect(loadedState.alertMessage, message);
expect(loadedState.notificationSettings.newUpdatesNotification, true);
when(mockNotificationSettingsRepository.updateNotificationSettings(any)).thenThrow(Exception('сеть'));
await notificationSettingsCubit!.updateNotificationSettings({'new_updates_notification': false});
final retried = notificationSettingsCubit!.state as NotificationSettingsStateLoaded;
expect(retried.alertMessage, 'Не удалось сохранить настройки уведомлений');
expect(retried.alertId, isNot(loadedState.alertId));
expect(retried.notificationSettings, loadedState.notificationSettings);
});
});
}