forked from eatvio/eatvio_app
feat(dependencies): add rxdart package and improve string extension methods for better handling of empty strings and gender parsing
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
import 'package:eatvio_app/features/consultant_rating/models/rating_model.dart';
|
||||
import 'package:eatvio_app/features/consultant_rating/models/statistics_model.dart';
|
||||
import 'package:eatvio_app/features/consultant_rating/presentation/cubit/consultant_rating_cubit.dart';
|
||||
import 'package:eatvio_app/features/consultant_rating/repositories/consultant_rating_repository.dart';
|
||||
import 'package:eatvio_app/features/feed/models/feed_consultant_model.dart';
|
||||
import 'package:eatvio_app/features/feed/repositories/feed_repository.dart';
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.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 'consultant_rating_cubit_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([
|
||||
MockSpec<ConsultantRatingRepository>(),
|
||||
MockSpec<FeedRepository>(),
|
||||
MockSpec<ProfileRepository>(),
|
||||
])
|
||||
void main() {
|
||||
group('ConsultantRatingCubit', () {
|
||||
ConsultantRatingCubit? cubit;
|
||||
late MockConsultantRatingRepository mockRepository;
|
||||
late MockFeedRepository mockFeedRepository;
|
||||
late MockProfileRepository mockProfileRepository;
|
||||
|
||||
setUp(() {
|
||||
mockRepository = MockConsultantRatingRepository();
|
||||
mockFeedRepository = MockFeedRepository();
|
||||
mockProfileRepository = MockProfileRepository();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
if (cubit != null && !cubit!.isClosed) {
|
||||
await cubit!.close();
|
||||
cubit = null;
|
||||
}
|
||||
});
|
||||
|
||||
test('начальное состояние - пустое', () {
|
||||
cubit = ConsultantRatingCubit(
|
||||
repository: mockRepository,
|
||||
feedRepository: mockFeedRepository,
|
||||
profileRepository: mockProfileRepository,
|
||||
);
|
||||
|
||||
expect(cubit!.state.isStatisticsLoading, isFalse);
|
||||
expect(cubit!.state.isRatingLoading, isFalse);
|
||||
expect(cubit!.state.statistics, isNull);
|
||||
expect(cubit!.state.ratings, isEmpty);
|
||||
});
|
||||
|
||||
test('getConsultantStatistics - успешная загрузка статистики', () async {
|
||||
cubit = ConsultantRatingCubit(
|
||||
repository: mockRepository,
|
||||
feedRepository: mockFeedRepository,
|
||||
profileRepository: mockProfileRepository,
|
||||
);
|
||||
|
||||
final testStatistics = StatisticsModel(
|
||||
countReferal: 10,
|
||||
blogPostsCount: 5,
|
||||
recipesCount: 20,
|
||||
dietsCount: 3,
|
||||
consultationsCount: 15,
|
||||
);
|
||||
|
||||
const testProfile = ProfileModel(
|
||||
id: 1,
|
||||
slug: 'test-user',
|
||||
name: 'Test User',
|
||||
email: 'test@example.com',
|
||||
phoneConfirmationState: 'confirmed',
|
||||
isPublicProfile: true,
|
||||
isBlockedByMe: false,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
profilePhotoUrl: 'https://example.com/icon.jpg',
|
||||
roles: [],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
|
||||
const testConsultants = [
|
||||
FeedConsultantModel(
|
||||
slug: 'test-user',
|
||||
name: 'Test User',
|
||||
description: 'Test description',
|
||||
totalScores: 450,
|
||||
photo: 'https://example.com/icon.jpg',
|
||||
badges: [],
|
||||
),
|
||||
];
|
||||
|
||||
when(mockRepository.getConsultantStatistics(date: anyNamed('date')))
|
||||
.thenAnswer((_) async => testStatistics);
|
||||
when(mockProfileRepository.getMyProfile())
|
||||
.thenAnswer((_) async => testProfile);
|
||||
when(mockFeedRepository.getConsultants('Test User'))
|
||||
.thenAnswer((_) async => testConsultants);
|
||||
|
||||
await cubit!.getConsultantStatistics();
|
||||
|
||||
expect(cubit!.state.statistics, isNotNull);
|
||||
expect(cubit!.state.absoluteRating, 450);
|
||||
expect(cubit!.state.isStatisticsLoading, isFalse);
|
||||
});
|
||||
|
||||
test('getScoreLogs - успешная загрузка логов оценок', () async {
|
||||
cubit = ConsultantRatingCubit(
|
||||
repository: mockRepository,
|
||||
feedRepository: mockFeedRepository,
|
||||
profileRepository: mockProfileRepository,
|
||||
);
|
||||
|
||||
final testRatings = [
|
||||
RatingModel(
|
||||
type: RatingEnum.addedRecipe,
|
||||
amount: 5,
|
||||
date: DateTime.now(),
|
||||
),
|
||||
];
|
||||
|
||||
when(mockRepository.getScoreLogs(date: anyNamed('date')))
|
||||
.thenAnswer((_) async => testRatings);
|
||||
|
||||
await cubit!.getScoreLogs();
|
||||
|
||||
expect(cubit!.state.ratings.length, 1);
|
||||
expect(cubit!.state.isRatingLoading, isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user