forked from eatvio/eatvio_app
feat(tests): updated tests coverage to 66.5%
This commit is contained in:
@@ -30,6 +30,22 @@ void main() {
|
||||
expect(model.energy, 2000.0);
|
||||
expect(model.proteins, 100.0);
|
||||
});
|
||||
|
||||
test('toJson serializes NutritionModel correctly', () {
|
||||
const model = NutritionModel(
|
||||
energy: 2000.0,
|
||||
proteins: 100.0,
|
||||
fats: 50.0,
|
||||
carbohydrates: 250.0,
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['energy'], 2000.0);
|
||||
expect(json['proteins'], 100.0);
|
||||
expect(json['fats'], 50.0);
|
||||
expect(json['carbohydrates'], 250.0);
|
||||
});
|
||||
});
|
||||
|
||||
group('NutritionDataModel', () {
|
||||
@@ -56,6 +72,54 @@ void main() {
|
||||
expect(model.dailyNutritionIntake.energy, 2000.0);
|
||||
expect(model.dailyNutritionRecommendation.energy, 2500.0);
|
||||
});
|
||||
|
||||
test('fromJson создает NutritionDataModel из JSON', () {
|
||||
final json = {
|
||||
'dailyNutritionIntake': {
|
||||
'energy': 2000.0,
|
||||
'proteins': 100.0,
|
||||
'fats': 50.0,
|
||||
'carbohydrates': 250.0,
|
||||
},
|
||||
'dailyNutritionRecommendation': {
|
||||
'energy': 2500.0,
|
||||
'proteins': 120.0,
|
||||
'fats': 60.0,
|
||||
'carbohydrates': 300.0,
|
||||
},
|
||||
};
|
||||
|
||||
final model = NutritionDataModel.fromJson(json);
|
||||
|
||||
expect(model.dailyNutritionIntake.energy, 2000.0);
|
||||
expect(model.dailyNutritionRecommendation.energy, 2500.0);
|
||||
});
|
||||
|
||||
test('toJson serializes NutritionDataModel correctly', () {
|
||||
const intake = NutritionModel(
|
||||
energy: 2000.0,
|
||||
proteins: 100.0,
|
||||
fats: 50.0,
|
||||
carbohydrates: 250.0,
|
||||
);
|
||||
|
||||
const recommendation = NutritionModel(
|
||||
energy: 2500.0,
|
||||
proteins: 120.0,
|
||||
fats: 60.0,
|
||||
carbohydrates: 300.0,
|
||||
);
|
||||
|
||||
const model = NutritionDataModel(
|
||||
dailyNutritionIntake: intake,
|
||||
dailyNutritionRecommendation: recommendation,
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json.containsKey('dailyNutritionIntake'), isTrue);
|
||||
expect(json.containsKey('dailyNutritionRecommendation'), isTrue);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user