forked from eatvio/eatvio_app
126 lines
3.3 KiB
Dart
126 lines
3.3 KiB
Dart
import 'package:eatvio_app/features/diary/models/nutrition_model.dart';
|
||
import 'package:flutter_test/flutter_test.dart';
|
||
|
||
void main() {
|
||
group('NutritionModel', () {
|
||
test('создает NutritionModel с правильными значениями', () {
|
||
const model = NutritionModel(
|
||
energy: 2000.0,
|
||
proteins: 100.0,
|
||
fats: 50.0,
|
||
carbohydrates: 250.0,
|
||
);
|
||
|
||
expect(model.energy, 2000.0);
|
||
expect(model.proteins, 100.0);
|
||
expect(model.fats, 50.0);
|
||
expect(model.carbohydrates, 250.0);
|
||
});
|
||
|
||
test('fromJson создает NutritionModel из JSON', () {
|
||
final json = {
|
||
'energy': 2000.0,
|
||
'proteins': 100.0,
|
||
'fats': 50.0,
|
||
'carbohydrates': 250.0,
|
||
};
|
||
|
||
final model = NutritionModel.fromJson(json);
|
||
|
||
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', () {
|
||
test('создает NutritionDataModel с правильными значениями', () {
|
||
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,
|
||
);
|
||
|
||
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);
|
||
});
|
||
});
|
||
}
|
||
|