feat(tests): updated tests coverage to 66.5%

This commit is contained in:
misha
2026-01-14 18:47:11 +03:00
parent 497ff19cfa
commit 13ccf56df0
102 changed files with 10146 additions and 379 deletions

View File

@@ -0,0 +1,76 @@
import 'package:eatvio_app/features/plans/enums/chosen_plan_state_enum.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('ChosenPlanStateEnum', () {
test('has all expected values', () {
expect(ChosenPlanStateEnum.values.length, 15);
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateInited));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateStartDateHasBeenSet));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateInCoordination));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateStarted));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateInProgress));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.statePendingPayment));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateConfirmedByConsultant));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.statePaid));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateCanceledByTheInitiator));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateLastDayStarted));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateLastDayFinished));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateComplained));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateDone));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.personalDietSet));
expect(ChosenPlanStateEnum.values, contains(ChosenPlanStateEnum.stateChargeWasCollected));
});
test('getShowableChatBadgeStates returns correct states', () {
final states = ChosenPlanStateEnum.getShowableChatBadgeStates();
expect(states.length, 9);
expect(states, contains(ChosenPlanStateEnum.stateInCoordination));
expect(states, contains(ChosenPlanStateEnum.stateStartDateHasBeenSet));
expect(states, contains(ChosenPlanStateEnum.statePendingPayment));
expect(states, contains(ChosenPlanStateEnum.statePaid));
expect(states, contains(ChosenPlanStateEnum.stateLastDayStarted));
expect(states, contains(ChosenPlanStateEnum.stateLastDayFinished));
expect(states, contains(ChosenPlanStateEnum.stateDone));
expect(states, contains(ChosenPlanStateEnum.stateInProgress));
expect(states, contains(ChosenPlanStateEnum.personalDietSet));
});
test('isStateAfterPaidState returns false for states before paid', () {
expect(ChosenPlanStateEnum.stateCanceledByTheInitiator.isStateAfterPaidState(), isFalse);
expect(ChosenPlanStateEnum.stateInited.isStateAfterPaidState(), isFalse);
expect(ChosenPlanStateEnum.stateInCoordination.isStateAfterPaidState(), isFalse);
expect(ChosenPlanStateEnum.stateStartDateHasBeenSet.isStateAfterPaidState(), isFalse);
expect(ChosenPlanStateEnum.statePendingPayment.isStateAfterPaidState(), isFalse);
});
test('isStateAfterPaidState returns true for states after paid', () {
expect(ChosenPlanStateEnum.statePaid.isStateAfterPaidState(), isTrue);
expect(ChosenPlanStateEnum.stateStarted.isStateAfterPaidState(), isTrue);
expect(ChosenPlanStateEnum.stateInProgress.isStateAfterPaidState(), isTrue);
expect(ChosenPlanStateEnum.stateLastDayStarted.isStateAfterPaidState(), isTrue);
expect(ChosenPlanStateEnum.stateLastDayFinished.isStateAfterPaidState(), isTrue);
expect(ChosenPlanStateEnum.stateComplained.isStateAfterPaidState(), isTrue);
expect(ChosenPlanStateEnum.stateDone.isStateAfterPaidState(), isTrue);
expect(ChosenPlanStateEnum.personalDietSet.isStateAfterPaidState(), isTrue);
expect(ChosenPlanStateEnum.stateChargeWasCollected.isStateAfterPaidState(), isTrue);
expect(ChosenPlanStateEnum.stateConfirmedByConsultant.isStateAfterPaidState(), isTrue);
});
test('getActiveStates returns correct states', () {
final activeStates = ChosenPlanStateEnum.getActiveStates();
expect(activeStates.length, 8);
expect(activeStates, contains(ChosenPlanStateEnum.statePaid));
expect(activeStates, contains(ChosenPlanStateEnum.stateStarted));
expect(activeStates, contains(ChosenPlanStateEnum.stateInProgress));
expect(activeStates, contains(ChosenPlanStateEnum.stateLastDayStarted));
expect(activeStates, contains(ChosenPlanStateEnum.stateLastDayFinished));
expect(activeStates, contains(ChosenPlanStateEnum.stateComplained));
expect(activeStates, contains(ChosenPlanStateEnum.stateDone));
expect(activeStates, contains(ChosenPlanStateEnum.personalDietSet));
});
});
}

View File

@@ -93,6 +93,53 @@ void main() {
expect(chosenPlan.chosenPlanState, ChosenPlanStateEnum.stateInited);
expect(chosenPlan.chatId, 'chat-1');
});
test('toJson serializes ChosenPlanModel correctly', () {
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,
maxPriceOfOptions: 2000,
wasLikedByMe: false,
);
final chosenPlan = ChosenPlanModel(
id: 1,
optionType: 'options1',
startDate: DateTime(2024, 1, 1),
chosenPlanState: ChosenPlanStateEnum.stateInited,
chatId: 'chat-1',
consultantId: 1,
plan: plan,
);
final json = chosenPlan.toJson();
expect(json['id'], 1);
expect(json['option_type'], 'options1');
expect(json['chat_id'], 'chat-1');
expect(json['consultant_id'], 1);
expect(json.containsKey('plan'), isTrue);
});
});
group('parseChosenPlan', () {

View File

@@ -52,6 +52,25 @@ void main() {
expect(state.planModel, plan);
expect(state.chosenOptionIndex, 1);
});
test('copyWith creates new instance with updated values', () {
const original = AboutPlanState(
isLoading: false,
error: null,
planModel: null,
chosenOptionIndex: 0,
);
final updated = original.copyWith(
isLoading: true,
chosenOptionIndex: 2,
);
expect(updated.isLoading, isTrue);
expect(updated.chosenOptionIndex, 2);
expect(updated.error, original.error);
expect(updated.planModel, original.planModel);
});
});
}