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,168 @@
|
||||
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/plans/presentation/cubit/about_plan_cubit.dart';
|
||||
import 'package:eatvio_app/features/plans/presentation/cubit/about_plan_state.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 'about_plan_cubit_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<PlanRepository>()])
|
||||
void main() {
|
||||
group('AboutPlanCubit', () {
|
||||
AboutPlanCubit? aboutPlanCubit;
|
||||
late MockPlanRepository mockPlanRepository;
|
||||
|
||||
setUp(() {
|
||||
mockPlanRepository = MockPlanRepository();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
if (aboutPlanCubit != null && !aboutPlanCubit!.isClosed) {
|
||||
await aboutPlanCubit!.close();
|
||||
aboutPlanCubit = null;
|
||||
}
|
||||
});
|
||||
|
||||
test('начальное состояние - initial', () {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
|
||||
expect(aboutPlanCubit!.state, isA<AboutPlanState>());
|
||||
expect(aboutPlanCubit!.state.isLoading, isFalse);
|
||||
expect(aboutPlanCubit!.state.planModel, isNull);
|
||||
});
|
||||
|
||||
test('getPlan - успешная загрузка плана', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(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,
|
||||
);
|
||||
|
||||
when(mockPlanRepository.getPlan('test-plan'))
|
||||
.thenAnswer((_) async => testPlan);
|
||||
|
||||
await aboutPlanCubit!.getPlan('test-plan');
|
||||
|
||||
expect(aboutPlanCubit!.state.planModel, isNotNull);
|
||||
expect(aboutPlanCubit!.state.planModel!.id, 1);
|
||||
expect(aboutPlanCubit!.state.error, isNull);
|
||||
});
|
||||
|
||||
test('getPlanWithLoading - устанавливает loading состояние', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(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,
|
||||
);
|
||||
|
||||
when(mockPlanRepository.getPlan('test-plan'))
|
||||
.thenAnswer((_) async => testPlan);
|
||||
|
||||
await aboutPlanCubit!.getPlanWithLoading('test-plan');
|
||||
|
||||
expect(aboutPlanCubit!.state.planModel, isNotNull);
|
||||
expect(aboutPlanCubit!.state.isLoading, isFalse);
|
||||
});
|
||||
|
||||
test('choseOption - изменяет выбранную опцию', () {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
|
||||
aboutPlanCubit!.choseOption(2);
|
||||
|
||||
expect(aboutPlanCubit!.state.chosenOptionIndex, 2);
|
||||
});
|
||||
|
||||
test('likePlan - лайк плана', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(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,
|
||||
);
|
||||
|
||||
when(mockPlanRepository.getPlan('test-plan'))
|
||||
.thenAnswer((_) async => testPlan);
|
||||
when(mockPlanRepository.likePlan('test-plan'))
|
||||
.thenAnswer((_) async => {});
|
||||
|
||||
await aboutPlanCubit!.getPlan('test-plan');
|
||||
await aboutPlanCubit!.likePlan(index: null, slug: 'test-plan');
|
||||
|
||||
await Future.delayed(const Duration(milliseconds: 1200));
|
||||
expect(aboutPlanCubit!.state.planModel!.wasLikedByMe, isTrue);
|
||||
expect(aboutPlanCubit!.state.planModel!.totalLikes, 11);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
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/plans/presentation/cubit/about_plan_state.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('AboutPlanState', () {
|
||||
test('initial создает начальное состояние', () {
|
||||
final state = AboutPlanState.initial();
|
||||
|
||||
expect(state.isLoading, isFalse);
|
||||
expect(state.error, isNull);
|
||||
expect(state.planModel, isNull);
|
||||
expect(state.chosenOptionIndex, 0);
|
||||
});
|
||||
|
||||
test('создает AboutPlanState с планом', () {
|
||||
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 = AboutPlanState(
|
||||
isLoading: false,
|
||||
error: null,
|
||||
planModel: plan,
|
||||
chosenOptionIndex: 1,
|
||||
);
|
||||
|
||||
expect(state.planModel, plan);
|
||||
expect(state.chosenOptionIndex, 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user