forked from eatvio/eatvio_app
feat(push_notifications): issue-660, fix: issue-908
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user