forked from eatvio/eatvio_app
217 lines
6.1 KiB
Dart
217 lines
6.1 KiB
Dart
import 'package:eatvio_app/features/glossary/models/glossary_model.dart';
|
||
import 'package:flutter_test/flutter_test.dart';
|
||
|
||
void main() {
|
||
group('GlossaryModel', () {
|
||
test('создает GlossaryModel с правильными значениями', () {
|
||
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,
|
||
);
|
||
|
||
expect(model.id, 1);
|
||
expect(model.name, 'Apple');
|
||
expect(model.grInPortion, 100);
|
||
expect(model.energyOn100Gr, 52.0);
|
||
});
|
||
|
||
test('fromJson создает GlossaryModel из JSON', () {
|
||
final json = {
|
||
'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 = GlossaryModel.fromJson(json);
|
||
|
||
expect(model.id, 1);
|
||
expect(model.name, 'Apple');
|
||
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', () {
|
||
test('создает GlossaryPaginationModel с правильными значениями', () {
|
||
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]);
|
||
|
||
expect(pagination.glossariesList.length, 1);
|
||
expect(pagination.glossariesList.first.id, 1);
|
||
});
|
||
|
||
test('fromJson создает GlossaryPaginationModel из JSON', () {
|
||
final json = {
|
||
'data': [
|
||
{
|
||
'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 pagination = GlossaryPaginationModel.fromJson(json);
|
||
|
||
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', () {
|
||
test('создает GlossaryModerationModel с правильными значениями', () {
|
||
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);
|
||
|
||
expect(model.glossary.id, 1);
|
||
expect(model.glossary.name, 'Apple');
|
||
});
|
||
|
||
test('fromJson создает GlossaryModerationModel из JSON', () {
|
||
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');
|
||
});
|
||
|
||
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);
|
||
});
|
||
});
|
||
}
|
||
|