feat(tests): menu, settings, remove icov, remove generated files from % tests

This commit is contained in:
mso7nueh
2025-11-27 08:18:23 +03:00
parent 2e57cd9519
commit 7df32dabd2
25 changed files with 1271 additions and 30783 deletions

View File

@@ -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);
});
});
}

View File

@@ -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);
});
});
}