forked from eatvio/eatvio_app
feat(tests): tests coverage 67.2
This commit is contained in:
@@ -220,5 +220,120 @@ void main() {
|
||||
cubit.pasteCopiedDay(0);
|
||||
expect(cubit.state.dietData.dailySchedule?[0][0], isEmpty);
|
||||
});
|
||||
|
||||
test('getDietForPreview returns null when form is invalid', () async {
|
||||
final result = await cubit.getDietForPreview();
|
||||
expect(result, null);
|
||||
});
|
||||
|
||||
test('createDiet returns validation error when form is invalid', () async {
|
||||
final result = await cubit.createDiet();
|
||||
expect(result, 'validation');
|
||||
expect(cubit.state.isDietPublishing, false);
|
||||
});
|
||||
|
||||
test('updateDiet returns error when form is invalid', () async {
|
||||
final result = await cubit.updateDiet(1);
|
||||
expect(result, 'error');
|
||||
});
|
||||
|
||||
test('updateDiet handles error when image compression fails', () async {
|
||||
cubit.setName('Test Diet');
|
||||
cubit.setDetails('Test Description');
|
||||
cubit.setDuration(0);
|
||||
cubit.setDietState(DietState.active);
|
||||
const portion = DailySchedule(
|
||||
name: 'Apple',
|
||||
portion: Portion.grams,
|
||||
quantity: 100,
|
||||
dailyNutrition: DailyNutrition(energy: 52.0, proteins: 0.3, fats: 0.2, carbohydrates: 14.0),
|
||||
productNutritionalValueId: '1',
|
||||
);
|
||||
cubit.addPortion(dayIndex: 0, mealIndex: 0, portion: portion);
|
||||
// Set image with non-existent file to trigger error in compression
|
||||
final image = XFile('non_existent_image.jpg');
|
||||
cubit.setImage(image);
|
||||
|
||||
final result = await cubit.updateDiet(1);
|
||||
|
||||
// Should return 'error' due to image compression failure
|
||||
expect(result, 'error');
|
||||
});
|
||||
|
||||
test('createDiet validates name length', () async {
|
||||
cubit.setName('Te'); // Less than 3 characters
|
||||
cubit.setDetails('Test Description');
|
||||
cubit.setDuration(0);
|
||||
cubit.setDietState(DietState.active);
|
||||
const portion = DailySchedule(
|
||||
name: 'Apple',
|
||||
portion: Portion.grams,
|
||||
quantity: 100,
|
||||
dailyNutrition: DailyNutrition(energy: 52.0, proteins: 0.3, fats: 0.2, carbohydrates: 14.0),
|
||||
productNutritionalValueId: '1',
|
||||
);
|
||||
cubit.addPortion(dayIndex: 0, mealIndex: 0, portion: portion);
|
||||
final image = XFile('test_image.jpg');
|
||||
cubit.setImage(image);
|
||||
|
||||
final result = await cubit.createDiet();
|
||||
|
||||
expect(result, 'validation');
|
||||
expect(cubit.state.dietNameError, 'Длинна названия не может быть меньше 3 символов');
|
||||
});
|
||||
|
||||
test('createDiet validates details length', () async {
|
||||
cubit.setName('Test Diet');
|
||||
cubit.setDetails('Te'); // Less than 3 characters
|
||||
cubit.setDuration(0);
|
||||
cubit.setDietState(DietState.active);
|
||||
const portion = DailySchedule(
|
||||
name: 'Apple',
|
||||
portion: Portion.grams,
|
||||
quantity: 100,
|
||||
dailyNutrition: DailyNutrition(energy: 52.0, proteins: 0.3, fats: 0.2, carbohydrates: 14.0),
|
||||
productNutritionalValueId: '1',
|
||||
);
|
||||
cubit.addPortion(dayIndex: 0, mealIndex: 0, portion: portion);
|
||||
final image = XFile('test_image.jpg');
|
||||
cubit.setImage(image);
|
||||
|
||||
final result = await cubit.createDiet();
|
||||
|
||||
expect(result, 'validation');
|
||||
expect(cubit.state.dietDescriptionError, 'Длинна описания не может быть меньше 3 символов');
|
||||
});
|
||||
|
||||
test('addPortion validates day when adding portion', () {
|
||||
cubit.setDuration(0);
|
||||
const portion = DailySchedule(
|
||||
name: 'Apple',
|
||||
portion: Portion.grams,
|
||||
quantity: 100,
|
||||
dailyNutrition: DailyNutrition(energy: 52.0, proteins: 0.3, fats: 0.2, carbohydrates: 14.0),
|
||||
productNutritionalValueId: '1',
|
||||
);
|
||||
|
||||
cubit.addPortion(dayIndex: 0, mealIndex: 0, portion: portion);
|
||||
|
||||
expect(cubit.state.dailyScheduleErrors[0], '');
|
||||
});
|
||||
|
||||
test('removePortion removes portion from daily schedule', () {
|
||||
cubit.setDuration(0);
|
||||
const portion = DailySchedule(
|
||||
name: 'Apple',
|
||||
portion: Portion.grams,
|
||||
quantity: 100,
|
||||
dailyNutrition: DailyNutrition(energy: 52.0, proteins: 0.3, fats: 0.2, carbohydrates: 14.0),
|
||||
productNutritionalValueId: '1',
|
||||
);
|
||||
|
||||
cubit.addPortion(dayIndex: 0, mealIndex: 0, portion: portion);
|
||||
expect(cubit.state.dietData.dailySchedule?[0][0].length, 1);
|
||||
|
||||
cubit.removePortion(day: 0, meal: 0, portionIndex: 0);
|
||||
expect(cubit.state.dietData.dailySchedule?[0][0].length, 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user