forked from eatvio/eatvio_app
feat(tests): updated tests coverage to 66.5%
This commit is contained in:
@@ -46,6 +46,32 @@ void main() {
|
||||
expect(model.grInPortion, 100);
|
||||
expect(model.energyOn100Gr, 52.0);
|
||||
});
|
||||
|
||||
test('toJson serializes GlossaryModel correctly', () {
|
||||
const model = GlossaryModel(
|
||||
id: 1,
|
||||
name: 'Apple',
|
||||
grInPortion: 100,
|
||||
energyOn100Gr: 52.0,
|
||||
proteinsOn100Gr: 0.3,
|
||||
fatsOn100Gr: 0.2,
|
||||
carbohydratesOn100Gr: 14.0,
|
||||
energyOnPortion: 52.0,
|
||||
proteinsOnPortion: 0.3,
|
||||
fatsOnPortion: 0.2,
|
||||
carbohydratesOnPortion: 14.0,
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['id'], 1);
|
||||
expect(json['name'], 'Apple');
|
||||
expect(json['portion_mass_gr'], 100);
|
||||
expect(json['energy_on_100gr'], 52.0);
|
||||
expect(json['proteins_on_100gr'], 0.3);
|
||||
expect(json['fats_on_100gr'], 0.2);
|
||||
expect(json['carbohydrates_on_100gr'], 14.0);
|
||||
});
|
||||
});
|
||||
|
||||
group('GlossaryPaginationModel', () {
|
||||
@@ -94,6 +120,29 @@ void main() {
|
||||
expect(pagination.glossariesList.length, 1);
|
||||
expect(pagination.glossariesList.first.id, 1);
|
||||
});
|
||||
|
||||
test('toJson serializes GlossaryPaginationModel correctly', () {
|
||||
const glossary = GlossaryModel(
|
||||
id: 1,
|
||||
name: 'Apple',
|
||||
grInPortion: 100,
|
||||
energyOn100Gr: 52.0,
|
||||
proteinsOn100Gr: 0.3,
|
||||
fatsOn100Gr: 0.2,
|
||||
carbohydratesOn100Gr: 14.0,
|
||||
energyOnPortion: 52.0,
|
||||
proteinsOnPortion: 0.3,
|
||||
fatsOnPortion: 0.2,
|
||||
carbohydratesOnPortion: 14.0,
|
||||
);
|
||||
|
||||
const pagination = GlossaryPaginationModel(glossariesList: [glossary]);
|
||||
|
||||
final json = pagination.toJson();
|
||||
|
||||
expect(json.containsKey('data'), isTrue);
|
||||
expect((json['data'] as List).length, 1);
|
||||
});
|
||||
});
|
||||
|
||||
group('GlossaryModerationModel', () {
|
||||
@@ -140,6 +189,28 @@ void main() {
|
||||
expect(model.glossary.id, 1);
|
||||
expect(model.glossary.name, 'Apple');
|
||||
});
|
||||
|
||||
test('toJson serializes GlossaryModerationModel correctly', () {
|
||||
const glossary = GlossaryModel(
|
||||
id: 1,
|
||||
name: 'Apple',
|
||||
grInPortion: 100,
|
||||
energyOn100Gr: 52.0,
|
||||
proteinsOn100Gr: 0.3,
|
||||
fatsOn100Gr: 0.2,
|
||||
carbohydratesOn100Gr: 14.0,
|
||||
energyOnPortion: 52.0,
|
||||
proteinsOnPortion: 0.3,
|
||||
fatsOnPortion: 0.2,
|
||||
carbohydratesOnPortion: 14.0,
|
||||
);
|
||||
|
||||
const model = GlossaryModerationModel(glossary: glossary);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json.containsKey('product_nutritional_value'), isTrue);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import 'package:eatvio_app/features/glossary/models/glossary_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('GlossaryModerationModel', () {
|
||||
test('fromJson parses glossary correctly', () {
|
||||
final json = {
|
||||
'product_nutritional_value': {
|
||||
'id': 1,
|
||||
'name': 'Apple',
|
||||
'portion_mass_gr': 100,
|
||||
'energy_on_100gr': 52.0,
|
||||
'proteins_on_100gr': 0.3,
|
||||
'fats_on_100gr': 0.2,
|
||||
'carbohydrates_on_100gr': 14.0,
|
||||
'energy_on_portion': 52.0,
|
||||
'proteins_on_portion': 0.3,
|
||||
'fats_on_portion': 0.2,
|
||||
'carbohydrates_on_portion': 14.0,
|
||||
},
|
||||
};
|
||||
|
||||
final model = GlossaryModerationModel.fromJson(json);
|
||||
|
||||
expect(model.glossary.id, 1);
|
||||
expect(model.glossary.name, 'Apple');
|
||||
expect(model.glossary.grInPortion, 100);
|
||||
expect(model.glossary.energyOn100Gr, 52.0);
|
||||
});
|
||||
|
||||
test('toJson serializes glossary correctly', () {
|
||||
const glossary = GlossaryModel(
|
||||
id: 1,
|
||||
name: 'Apple',
|
||||
grInPortion: 100,
|
||||
energyOn100Gr: 52.0,
|
||||
proteinsOn100Gr: 0.3,
|
||||
fatsOn100Gr: 0.2,
|
||||
carbohydratesOn100Gr: 14.0,
|
||||
energyOnPortion: 52.0,
|
||||
proteinsOnPortion: 0.3,
|
||||
fatsOnPortion: 0.2,
|
||||
carbohydratesOnPortion: 14.0,
|
||||
);
|
||||
const model = GlossaryModerationModel(glossary: glossary);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json.containsKey('product_nutritional_value'), isTrue);
|
||||
expect(json['product_nutritional_value'], isNotNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user