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,158 @@
|
||||
import 'package:eatvio_app/core/models/pagination_model.dart';
|
||||
import 'package:eatvio_app/features/diets/repositories/diet_repository.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/plans_cubit/plans_cubit.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/plans_cubit/plans_state.dart';
|
||||
import 'package:eatvio_app/features/feed/repositories/feed_repository.dart';
|
||||
import 'package:eatvio_app/features/plans/repositories/plan_repository.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
import 'plans_cubit_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([
|
||||
MockSpec<FeedRepository>(),
|
||||
MockSpec<PlanRepository>(),
|
||||
])
|
||||
void main() {
|
||||
group('PlansCubit', () {
|
||||
PlansCubit? plansCubit;
|
||||
late MockFeedRepository mockFeedRepository;
|
||||
late MockPlanRepository mockPlanRepository;
|
||||
|
||||
setUp(() {
|
||||
mockFeedRepository = MockFeedRepository();
|
||||
mockPlanRepository = MockPlanRepository();
|
||||
|
||||
// Мокируем streams для подписок
|
||||
when(mockPlanRepository.planLikeState).thenAnswer((_) => BehaviorSubject<LikesState>());
|
||||
when(mockPlanRepository.planFavoriteState).thenAnswer((_) => BehaviorSubject<FavoriteState>());
|
||||
when(mockPlanRepository.planCommentsState).thenAnswer((_) => BehaviorSubject<CommentsState>());
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
if (plansCubit != null && !plansCubit!.isClosed) {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
await plansCubit!.close();
|
||||
plansCubit = null;
|
||||
}
|
||||
});
|
||||
|
||||
test('начальное состояние - initial', () {
|
||||
plansCubit = PlansCubit(
|
||||
feedRepository: mockFeedRepository,
|
||||
planRepository: mockPlanRepository,
|
||||
);
|
||||
|
||||
expect(plansCubit!.state, isA<PlansState>());
|
||||
expect(plansCubit!.state.isLoading, isTrue);
|
||||
expect(plansCubit!.state.plans, isEmpty);
|
||||
expect(plansCubit!.state.errorMessage, isNull);
|
||||
});
|
||||
|
||||
test('changeDurationFilter - изменяет фильтр продолжительности', () {
|
||||
plansCubit = PlansCubit(
|
||||
feedRepository: mockFeedRepository,
|
||||
planRepository: mockPlanRepository,
|
||||
);
|
||||
|
||||
plansCubit!.changeDurationFilter(1);
|
||||
|
||||
expect(plansCubit!.state.filterState.durationIndex, 1);
|
||||
});
|
||||
|
||||
test('changeTypeFilter - изменяет тип фильтра', () {
|
||||
plansCubit = PlansCubit(
|
||||
feedRepository: mockFeedRepository,
|
||||
planRepository: mockPlanRepository,
|
||||
);
|
||||
|
||||
plansCubit!.changeTypeFilter(1);
|
||||
|
||||
expect(plansCubit!.state.filterState.typeIndex, 1);
|
||||
});
|
||||
|
||||
test('changePriceFilter - изменяет фильтр цены', () {
|
||||
plansCubit = PlansCubit(
|
||||
feedRepository: mockFeedRepository,
|
||||
planRepository: mockPlanRepository,
|
||||
);
|
||||
|
||||
plansCubit!.changePriceFilter(100, 500);
|
||||
|
||||
expect(plansCubit!.state.filterState.priceFilter, (100, 500));
|
||||
});
|
||||
|
||||
test('loadPlans - успешная загрузка планов', () async {
|
||||
plansCubit = PlansCubit(
|
||||
feedRepository: mockFeedRepository,
|
||||
planRepository: mockPlanRepository,
|
||||
);
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
slug: 'test-plan',
|
||||
name: 'Test Plan',
|
||||
image: 'https://example.com/image.jpg',
|
||||
duration: 7,
|
||||
state: 'active',
|
||||
type: PlanType(fit: true, slim: false, behavior: false, wellness: false),
|
||||
details: 'Test description',
|
||||
packetsCount: 3,
|
||||
minPriceOfOptions: 1000.0,
|
||||
maxPriceOfOptions: 2000.0,
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author Name',
|
||||
authorProfileIcon: 'https://example.com/icon.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: null,
|
||||
authorPlaceInRating: null,
|
||||
),
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
wasLikedByMe: false,
|
||||
isFavorite: false,
|
||||
);
|
||||
|
||||
const plansPagination = PlanPaginationModel(
|
||||
data: [testPlan],
|
||||
links: Links(
|
||||
first: 'https://example.com?page=1',
|
||||
last: 'https://example.com?page=1',
|
||||
prev: null,
|
||||
next: null,
|
||||
),
|
||||
meta: Meta(
|
||||
currentPage: 1,
|
||||
from: 1,
|
||||
lastPage: 1,
|
||||
links: [],
|
||||
perPage: 10,
|
||||
to: 1,
|
||||
total: 1,
|
||||
),
|
||||
);
|
||||
|
||||
when(mockFeedRepository.getPlans(
|
||||
query: anyNamed('query'),
|
||||
types: anyNamed('types'),
|
||||
duration: anyNamed('duration'),
|
||||
minPrice: anyNamed('minPrice'),
|
||||
maxPrice: anyNamed('maxPrice'),
|
||||
)).thenAnswer((_) async => plansPagination);
|
||||
|
||||
await plansCubit!.loadPlans();
|
||||
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
expect(plansCubit!.state.plans.length, 1);
|
||||
expect(plansCubit!.state.plans.first.id, 1);
|
||||
expect(plansCubit!.state.errorMessage, isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/plans_cubit/plans_state.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('PlansState', () {
|
||||
test('initial создает начальное состояние', () {
|
||||
final state = PlansState.initial();
|
||||
|
||||
expect(state.isLoading, isTrue);
|
||||
expect(state.plans, isEmpty);
|
||||
expect(state.errorMessage, isNull);
|
||||
expect(state.minPlanPrice, 0);
|
||||
expect(state.maxPlanPrice, 0);
|
||||
});
|
||||
|
||||
test('создает PlansState с данными', () {
|
||||
const plan = PlanModel(
|
||||
id: 1,
|
||||
slug: 'test-plan',
|
||||
name: 'Test Plan',
|
||||
image: 'https://example.com/image.jpg',
|
||||
duration: 7,
|
||||
state: 'active',
|
||||
type: PlanType(fit: true, slim: false, behavior: false, wellness: false),
|
||||
details: 'Test details',
|
||||
packetsCount: 3,
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author Name',
|
||||
authorProfileIcon: 'https://example.com/icon.jpg',
|
||||
authorIsMe: false,
|
||||
isEntitySubscribedByMe: null,
|
||||
authorPlaceInRating: null,
|
||||
),
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
isFavorite: false,
|
||||
minPriceOfOptions: 1000.0,
|
||||
maxPriceOfOptions: 2000.0,
|
||||
wasLikedByMe: false,
|
||||
);
|
||||
|
||||
const state = PlansState(
|
||||
isLoading: false,
|
||||
plans: [plan],
|
||||
errorMessage: null,
|
||||
filterState: PlansFilterState(
|
||||
priceFilter: (1000, 2000),
|
||||
durationIndex: 1,
|
||||
typeIndex: 1,
|
||||
),
|
||||
minPlanPrice: 1000,
|
||||
maxPlanPrice: 2000,
|
||||
);
|
||||
|
||||
expect(state.plans.length, 1);
|
||||
expect(state.isLoading, isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user