forked from eatvio/eatvio_app
feat(tests): menu, settings, remove icov, remove generated files from % tests
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
import 'package:eatvio_app/features/menu/presentation/blocked_user_cubit/blocked_users_cubit.dart';
|
||||
import 'package:eatvio_app/features/menu/presentation/blocked_user_cubit/blocked_users_state.dart';
|
||||
import 'package:eatvio_app/features/menu/presentation/repositories/blocked_users_repository.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import '../../../../fixtures/menu_fixtures.dart';
|
||||
import 'blocked_users_cubit_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<BlockedUsersRepository>()])
|
||||
void main() {
|
||||
group('BlockedUsersCubit', () {
|
||||
BlockedUsersCubit? blockedUsersCubit;
|
||||
late MockBlockedUsersRepository mockBlockedUsersRepository;
|
||||
|
||||
setUp(() {
|
||||
mockBlockedUsersRepository = MockBlockedUsersRepository();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
if (blockedUsersCubit != null && !blockedUsersCubit!.isClosed) {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
blockedUsersCubit!.close();
|
||||
blockedUsersCubit = null;
|
||||
}
|
||||
});
|
||||
|
||||
test('начальное состояние - BlockedUsersState', () {
|
||||
blockedUsersCubit = BlockedUsersCubit(
|
||||
blockedUsersRepository: mockBlockedUsersRepository,
|
||||
);
|
||||
expect(blockedUsersCubit!.state, const BlockedUsersState());
|
||||
});
|
||||
|
||||
test('getBlockedUsers - успешно загружает список заблокированных пользователей', () async {
|
||||
blockedUsersCubit = BlockedUsersCubit(
|
||||
blockedUsersRepository: mockBlockedUsersRepository,
|
||||
);
|
||||
final profilesList = MenuFixtures.blockedUsersList();
|
||||
|
||||
when(mockBlockedUsersRepository.getBlockedUsers())
|
||||
.thenAnswer((_) async => profilesList);
|
||||
|
||||
await blockedUsersCubit!.getBlockedUsers();
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
expect(blockedUsersCubit!.state, isA<BlockedUsersStateLoaded>());
|
||||
final loadedState = blockedUsersCubit!.state as BlockedUsersStateLoaded;
|
||||
expect(loadedState.profilesList.length, 2);
|
||||
expect(loadedState.profilesList.first.id, 1);
|
||||
verify(mockBlockedUsersRepository.getBlockedUsers()).called(1);
|
||||
});
|
||||
|
||||
test('getBlockedUsers - обрабатывает ошибку', () async {
|
||||
blockedUsersCubit = BlockedUsersCubit(
|
||||
blockedUsersRepository: mockBlockedUsersRepository,
|
||||
);
|
||||
|
||||
when(mockBlockedUsersRepository.getBlockedUsers())
|
||||
.thenThrow(Exception('Ошибка загрузки'));
|
||||
|
||||
await blockedUsersCubit!.getBlockedUsers();
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
expect(blockedUsersCubit!.state, isA<BlockedUsersStateError>());
|
||||
final errorState = blockedUsersCubit!.state as BlockedUsersStateError;
|
||||
expect(errorState.errorMessage, contains('Ошибка загрузки'));
|
||||
});
|
||||
|
||||
test('blockUser - блокирует пользователя и обновляет список', () async {
|
||||
blockedUsersCubit = BlockedUsersCubit(
|
||||
blockedUsersRepository: mockBlockedUsersRepository,
|
||||
);
|
||||
final blockedUser = MenuFixtures.blockedUser();
|
||||
final slug = blockedUser.slug;
|
||||
final profilesList = MenuFixtures.blockedUsersList();
|
||||
|
||||
when(mockBlockedUsersRepository.blockUserBySlug(slug))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
when(mockBlockedUsersRepository.getBlockedUsers())
|
||||
.thenAnswer((_) async => profilesList);
|
||||
|
||||
await blockedUsersCubit!.blockUser(slug);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
verify(mockBlockedUsersRepository.blockUserBySlug(slug)).called(1);
|
||||
verify(mockBlockedUsersRepository.getBlockedUsers()).called(1);
|
||||
});
|
||||
|
||||
test('unblockUser - разблокирует пользователя и обновляет список', () async {
|
||||
blockedUsersCubit = BlockedUsersCubit(
|
||||
blockedUsersRepository: mockBlockedUsersRepository,
|
||||
);
|
||||
final blockedUser = MenuFixtures.blockedUser();
|
||||
final slug = blockedUser.slug;
|
||||
final profilesList = MenuFixtures.blockedUsersEmptyList();
|
||||
|
||||
when(mockBlockedUsersRepository.unblockUserBySlug(slug))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
when(mockBlockedUsersRepository.getBlockedUsers())
|
||||
.thenAnswer((_) async => profilesList);
|
||||
|
||||
await blockedUsersCubit!.unblockUser(slug);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
verify(mockBlockedUsersRepository.unblockUserBySlug(slug)).called(1);
|
||||
verify(mockBlockedUsersRepository.getBlockedUsers()).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
68
test/features/menu/presentation/bloc/menu_cubit_test.dart
Normal file
68
test/features/menu/presentation/bloc/menu_cubit_test.dart
Normal file
@@ -0,0 +1,68 @@
|
||||
import 'package:eatvio_app/features/menu/presentation/bloc/menu_cubit/menu_cubit.dart';
|
||||
import 'package:eatvio_app/features/menu/presentation/bloc/menu_cubit/menu_state.dart';
|
||||
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'menu_cubit_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<ProfileRepository>()])
|
||||
void main() {
|
||||
group('MenuCubit', () {
|
||||
MenuCubit? menuCubit;
|
||||
late MockProfileRepository mockProfileRepository;
|
||||
|
||||
setUp(() {
|
||||
mockProfileRepository = MockProfileRepository();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
if (menuCubit != null && !menuCubit!.isClosed) {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
menuCubit!.close();
|
||||
menuCubit = null;
|
||||
}
|
||||
});
|
||||
|
||||
test('начальное состояние - MenuState', () {
|
||||
menuCubit = MenuCubit(mockProfileRepository);
|
||||
expect(menuCubit!.state, isA<MenuState>());
|
||||
});
|
||||
|
||||
test('makePassKey - успешно создает passKey', () async {
|
||||
menuCubit = MenuCubit(mockProfileRepository);
|
||||
const expectedPassKey = 'test-pass-key';
|
||||
|
||||
when(mockProfileRepository.getPassKey(
|
||||
routeName: 'product_nutritional_value.index',
|
||||
routeParams: {},
|
||||
)).thenAnswer((_) async => expectedPassKey);
|
||||
|
||||
final result = await menuCubit!.makePassKey();
|
||||
|
||||
expect(result, expectedPassKey);
|
||||
verify(mockProfileRepository.getPassKey(
|
||||
routeName: 'product_nutritional_value.index',
|
||||
routeParams: {},
|
||||
)).called(1);
|
||||
});
|
||||
|
||||
test('makePassKey - возвращает null при ошибке', () async {
|
||||
menuCubit = MenuCubit(mockProfileRepository);
|
||||
|
||||
when(mockProfileRepository.getPassKey(
|
||||
routeName: 'product_nutritional_value.index',
|
||||
routeParams: {},
|
||||
)).thenThrow(Exception('Ошибка получения passKey'));
|
||||
|
||||
final result = await menuCubit!.makePassKey();
|
||||
|
||||
expect(result, isNull);
|
||||
verify(mockProfileRepository.getPassKey(
|
||||
routeName: 'product_nutritional_value.index',
|
||||
routeParams: {},
|
||||
)).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
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';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import '../../../../fixtures/menu_fixtures.dart';
|
||||
import 'notification_settings_cubit_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<NotificationSettingsRepository>()])
|
||||
void main() {
|
||||
group('NotificationSettingsCubit', () {
|
||||
NotificationSettingsCubit? notificationSettingsCubit;
|
||||
late MockNotificationSettingsRepository mockNotificationSettingsRepository;
|
||||
|
||||
setUp(() {
|
||||
mockNotificationSettingsRepository = MockNotificationSettingsRepository();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
if (notificationSettingsCubit != null && !notificationSettingsCubit!.isClosed) {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
notificationSettingsCubit!.close();
|
||||
notificationSettingsCubit = null;
|
||||
}
|
||||
});
|
||||
|
||||
test('начальное состояние - loading', () {
|
||||
notificationSettingsCubit = NotificationSettingsCubit(
|
||||
notificationSettingsRepository: mockNotificationSettingsRepository,
|
||||
);
|
||||
expect(notificationSettingsCubit!.state, const NotificationSettingsStateLoading());
|
||||
});
|
||||
|
||||
test('getNotificationSettings - успешно загружает настройки уведомлений', () async {
|
||||
notificationSettingsCubit = NotificationSettingsCubit(
|
||||
notificationSettingsRepository: mockNotificationSettingsRepository,
|
||||
);
|
||||
|
||||
when(mockNotificationSettingsRepository.getNotificationSettings())
|
||||
.thenAnswer((_) async => MenuFixtures.notificationSettingsModel());
|
||||
|
||||
await notificationSettingsCubit!.getNotificationSettings();
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
expect(notificationSettingsCubit!.state, isA<NotificationSettingsStateLoaded>());
|
||||
final loadedState = notificationSettingsCubit!.state as NotificationSettingsStateLoaded;
|
||||
expect(loadedState.notificationSettings.newUpdatesNotification, true);
|
||||
verify(mockNotificationSettingsRepository.getNotificationSettings()).called(1);
|
||||
});
|
||||
|
||||
test('getNotificationSettings - обрабатывает ошибку', () async {
|
||||
notificationSettingsCubit = NotificationSettingsCubit(
|
||||
notificationSettingsRepository: mockNotificationSettingsRepository,
|
||||
);
|
||||
|
||||
when(mockNotificationSettingsRepository.getNotificationSettings())
|
||||
.thenThrow(Exception('Ошибка загрузки'));
|
||||
|
||||
await notificationSettingsCubit!.getNotificationSettings();
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
expect(notificationSettingsCubit!.state, isA<NotificationSettingsStateError>());
|
||||
final errorState = notificationSettingsCubit!.state as NotificationSettingsStateError;
|
||||
expect(errorState.errorMessage, contains('Ошибка загрузки'));
|
||||
});
|
||||
|
||||
test('updateNotificationSettings - успешно обновляет настройки', () async {
|
||||
notificationSettingsCubit = NotificationSettingsCubit(
|
||||
notificationSettingsRepository: mockNotificationSettingsRepository,
|
||||
);
|
||||
final data = {
|
||||
'new_updates_notification': false,
|
||||
'weight_measurements_notification': true,
|
||||
};
|
||||
final updatedSettings = MenuFixtures.notificationSettingsUpdatedModel();
|
||||
|
||||
when(mockNotificationSettingsRepository.updateNotificationSettings(data))
|
||||
.thenAnswer((_) async => updatedSettings);
|
||||
|
||||
await notificationSettingsCubit!.updateNotificationSettings(data);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
expect(notificationSettingsCubit!.state, isA<NotificationSettingsStateLoaded>());
|
||||
final loadedState = notificationSettingsCubit!.state as NotificationSettingsStateLoaded;
|
||||
expect(loadedState.notificationSettings.newUpdatesNotification, false);
|
||||
verify(mockNotificationSettingsRepository.updateNotificationSettings(data)).called(1);
|
||||
});
|
||||
|
||||
test('updateNotificationSettings - обрабатывает ошибку при обновлении', () async {
|
||||
notificationSettingsCubit = NotificationSettingsCubit(
|
||||
notificationSettingsRepository: mockNotificationSettingsRepository,
|
||||
);
|
||||
final data = {'new_updates_notification': false};
|
||||
|
||||
when(mockNotificationSettingsRepository.updateNotificationSettings(data))
|
||||
.thenThrow(Exception('Ошибка обновления'));
|
||||
|
||||
await notificationSettingsCubit!.updateNotificationSettings(data);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
expect(notificationSettingsCubit!.state, isA<NotificationSettingsStateError>());
|
||||
final errorState = notificationSettingsCubit!.state as NotificationSettingsStateError;
|
||||
expect(errorState.errorMessage, contains('Ошибка обновления'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import 'package:eatvio_app/features/menu/presentation/repositories/blocked_users_repository.dart';
|
||||
import 'package:eatvio_app/features/menu/services/blocked_users_service.dart';
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import '../../../fixtures/menu_fixtures.dart';
|
||||
import 'blocked_users_repository_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<BlockedUserService>()])
|
||||
void main() {
|
||||
group('BlockedUsersRepository', () {
|
||||
late BlockedUsersRepository blockedUsersRepository;
|
||||
late MockBlockedUserService mockBlockedUserService;
|
||||
|
||||
setUp(() {
|
||||
mockBlockedUserService = MockBlockedUserService();
|
||||
blockedUsersRepository = BlockedUsersRepository(
|
||||
blockedUserService: mockBlockedUserService,
|
||||
);
|
||||
});
|
||||
|
||||
test('getBlockedUsers - возвращает список заблокированных пользователей', () async {
|
||||
final blockedUsersModel = MenuFixtures.blockedUsersModel();
|
||||
|
||||
when(mockBlockedUserService.getBlockedUsers())
|
||||
.thenAnswer((_) async => blockedUsersModel);
|
||||
|
||||
final result = await blockedUsersRepository.getBlockedUsers();
|
||||
|
||||
expect(result, isA<List<ProfileModel>>());
|
||||
expect(result.length, 2);
|
||||
expect(result.first.id, 1);
|
||||
expect(result.last.id, 2);
|
||||
verify(mockBlockedUserService.getBlockedUsers()).called(1);
|
||||
});
|
||||
|
||||
test('blockUserBySlug - блокирует пользователя по slug', () async {
|
||||
final blockedUser = MenuFixtures.blockedUser();
|
||||
final slug = blockedUser.slug;
|
||||
final data = {'slug': slug};
|
||||
|
||||
when(mockBlockedUserService.blockUser(data: data))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await blockedUsersRepository.blockUserBySlug(slug);
|
||||
|
||||
verify(mockBlockedUserService.blockUser(data: data)).called(1);
|
||||
});
|
||||
|
||||
test('unblockUserBySlug - разблокирует пользователя по slug', () async {
|
||||
final blockedUser = MenuFixtures.blockedUser();
|
||||
final slug = blockedUser.slug;
|
||||
final data = {'slug': slug};
|
||||
|
||||
when(mockBlockedUserService.unblockUser(data: data))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await blockedUsersRepository.unblockUserBySlug(slug);
|
||||
|
||||
verify(mockBlockedUserService.unblockUser(data: data)).called(1);
|
||||
});
|
||||
|
||||
test('getBlockedUsers - обрабатывает пустой список', () async {
|
||||
final blockedUsersModel = MenuFixtures.blockedUsersEmptyModel();
|
||||
|
||||
when(mockBlockedUserService.getBlockedUsers())
|
||||
.thenAnswer((_) async => blockedUsersModel);
|
||||
|
||||
final result = await blockedUsersRepository.getBlockedUsers();
|
||||
|
||||
expect(result, isA<List<ProfileModel>>());
|
||||
expect(result.isEmpty, true);
|
||||
verify(mockBlockedUserService.getBlockedUsers()).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import 'package:eatvio_app/features/menu/models/notification_settings_model.dart';
|
||||
import 'package:eatvio_app/features/menu/repositories/notification_settings_repository.dart';
|
||||
import 'package:eatvio_app/features/menu/services/notification_settings_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import '../../../fixtures/menu_fixtures.dart';
|
||||
import 'notification_settings_repository_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<NotificationSettingsService>()])
|
||||
void main() {
|
||||
group('NotificationSettingsRepository', () {
|
||||
late NotificationSettingsRepository notificationSettingsRepository;
|
||||
late MockNotificationSettingsService mockNotificationSettingsService;
|
||||
|
||||
setUp(() {
|
||||
mockNotificationSettingsService = MockNotificationSettingsService();
|
||||
notificationSettingsRepository = NotificationSettingsRepository(
|
||||
mockNotificationSettingsService,
|
||||
);
|
||||
});
|
||||
|
||||
test('getNotificationSettings - возвращает настройки уведомлений', () async {
|
||||
final expectedSettings = MenuFixtures.notificationSettingsModel();
|
||||
|
||||
when(mockNotificationSettingsService.getNotificationSettings())
|
||||
.thenAnswer((_) async => expectedSettings);
|
||||
|
||||
final result = await notificationSettingsRepository.getNotificationSettings();
|
||||
|
||||
expect(result, isA<NotificationSettingsModel>());
|
||||
expect(result.newUpdatesNotification, true);
|
||||
expect(result.diaryReminderNotifications.firstReminder.enabled, true);
|
||||
verify(mockNotificationSettingsService.getNotificationSettings()).called(1);
|
||||
});
|
||||
|
||||
test('updateNotificationSettings - обновляет настройки уведомлений', () async {
|
||||
final data = {
|
||||
'new_updates_notification': false,
|
||||
'weight_measurements_notification': true,
|
||||
'is_email_notifications_enabled': true,
|
||||
'is_push_notifications_enabled': false,
|
||||
};
|
||||
final expectedSettings = MenuFixtures.notificationSettingsUpdatedModel();
|
||||
|
||||
when(mockNotificationSettingsService.updateNotificationSettings(data: data))
|
||||
.thenAnswer((_) async => expectedSettings);
|
||||
|
||||
final result = await notificationSettingsRepository.updateNotificationSettings(data);
|
||||
|
||||
expect(result, isA<NotificationSettingsModel>());
|
||||
expect(result.newUpdatesNotification, false);
|
||||
expect(result.isPushNotificationsEnabled, false);
|
||||
verify(mockNotificationSettingsService.updateNotificationSettings(data: data)).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
57
test/features/menu/services/blocked_users_service_test.dart
Normal file
57
test/features/menu/services/blocked_users_service_test.dart
Normal file
@@ -0,0 +1,57 @@
|
||||
import 'package:eatvio_app/features/menu/models/blocked_users_model.dart';
|
||||
import 'package:eatvio_app/features/menu/services/blocked_users_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import '../../../fixtures/menu_fixtures.dart';
|
||||
import 'blocked_users_service_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<BlockedUserService>()])
|
||||
void main() {
|
||||
group('BlockedUserService', () {
|
||||
late MockBlockedUserService mockBlockedUserService;
|
||||
|
||||
setUp(() {
|
||||
mockBlockedUserService = MockBlockedUserService();
|
||||
});
|
||||
|
||||
test('getBlockedUsers - возвращает список заблокированных пользователей', () async {
|
||||
final expectedBlockedUsers = MenuFixtures.blockedUsersModel();
|
||||
|
||||
when(mockBlockedUserService.getBlockedUsers())
|
||||
.thenAnswer((_) async => expectedBlockedUsers);
|
||||
|
||||
final result = await mockBlockedUserService.getBlockedUsers();
|
||||
|
||||
expect(result, isA<BlockedUsersModel>());
|
||||
expect(result.profilesList.length, 2);
|
||||
expect(result.profilesList.first.id, 1);
|
||||
verify(mockBlockedUserService.getBlockedUsers()).called(1);
|
||||
});
|
||||
|
||||
test('blockUser - блокирует пользователя', () async {
|
||||
final blockedUser = MenuFixtures.blockedUser();
|
||||
final data = {'slug': blockedUser.slug};
|
||||
|
||||
when(mockBlockedUserService.blockUser(data: data))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await mockBlockedUserService.blockUser(data: data);
|
||||
|
||||
verify(mockBlockedUserService.blockUser(data: data)).called(1);
|
||||
});
|
||||
|
||||
test('unblockUser - разблокирует пользователя', () async {
|
||||
final blockedUser = MenuFixtures.blockedUser();
|
||||
final data = {'slug': blockedUser.slug};
|
||||
|
||||
when(mockBlockedUserService.unblockUser(data: data))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
await mockBlockedUserService.unblockUser(data: data);
|
||||
|
||||
verify(mockBlockedUserService.unblockUser(data: data)).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import 'package:eatvio_app/features/menu/models/notification_settings_model.dart';
|
||||
import 'package:eatvio_app/features/menu/services/notification_settings_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import '../../../fixtures/menu_fixtures.dart';
|
||||
import 'notification_settings_service_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<NotificationSettingsService>()])
|
||||
void main() {
|
||||
group('NotificationSettingsService', () {
|
||||
late MockNotificationSettingsService mockNotificationSettingsService;
|
||||
|
||||
setUp(() {
|
||||
mockNotificationSettingsService = MockNotificationSettingsService();
|
||||
});
|
||||
|
||||
test('getNotificationSettings - возвращает настройки уведомлений', () async {
|
||||
final expectedSettings = MenuFixtures.notificationSettingsModel();
|
||||
|
||||
when(mockNotificationSettingsService.getNotificationSettings())
|
||||
.thenAnswer((_) async => expectedSettings);
|
||||
|
||||
final result = await mockNotificationSettingsService.getNotificationSettings();
|
||||
|
||||
expect(result, isA<NotificationSettingsModel>());
|
||||
expect(result.newUpdatesNotification, true);
|
||||
expect(result.isEmailNotificationsEnabled, true);
|
||||
verify(mockNotificationSettingsService.getNotificationSettings()).called(1);
|
||||
});
|
||||
|
||||
test('updateNotificationSettings - обновляет настройки уведомлений', () async {
|
||||
final data = {
|
||||
'new_updates_notification': false,
|
||||
'weight_measurements_notification': true,
|
||||
'is_email_notifications_enabled': true,
|
||||
'is_push_notifications_enabled': false,
|
||||
};
|
||||
final expectedSettings = MenuFixtures.notificationSettingsUpdatedModel();
|
||||
|
||||
when(mockNotificationSettingsService.updateNotificationSettings(data: data))
|
||||
.thenAnswer((_) async => expectedSettings);
|
||||
|
||||
final result = await mockNotificationSettingsService.updateNotificationSettings(data: data);
|
||||
|
||||
expect(result, isA<NotificationSettingsModel>());
|
||||
expect(result.newUpdatesNotification, false);
|
||||
expect(result.isPushNotificationsEnabled, false);
|
||||
verify(mockNotificationSettingsService.updateNotificationSettings(data: data)).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user