forked from eatvio/eatvio_app
feat(insights): first isights impemetation
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:eatvio_app/features/insights/models/insights_payload_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
Map<String, dynamic> _fixture(String name) {
|
||||
return jsonDecode(File('test/fixtures/insights/$name').readAsStringSync())
|
||||
as Map<String, dynamic>;
|
||||
}
|
||||
|
||||
void main() {
|
||||
group('InsightsPayloadModel', () {
|
||||
test('парсит полный payload (weight/bmi/measure/daily/intra)', () {
|
||||
final model = InsightsPayloadModel.fromJson(
|
||||
_fixture('insights_payload.json'),
|
||||
);
|
||||
|
||||
expect(model.weight.values, [74.5, 73.9, 73.2]);
|
||||
expect(model.weight.last, 73.2);
|
||||
expect(model.weight.delta, -1.3);
|
||||
expect(model.weight.unit, 'кг');
|
||||
|
||||
expect(model.measure.waist, [82.0, 80.5]);
|
||||
expect(model.measure.chest, [96.0, 96.0]);
|
||||
|
||||
expect(model.daily, isNotNull);
|
||||
expect(model.daily!.kcal, [1850.0, 2010.0, 1930.0]);
|
||||
expect(model.daily!.average, 1930);
|
||||
|
||||
expect(model.intra, isNotNull);
|
||||
expect(model.intra!.bars, hasLength(2));
|
||||
expect(model.intra!.bars.first.x, 8.5);
|
||||
expect(model.intra!.bars.first.c, 240);
|
||||
expect(model.intra!.satiety.last.y, 4);
|
||||
expect(model.intra!.wake, 7.5);
|
||||
expect(model.intra!.isToday, isTrue);
|
||||
});
|
||||
|
||||
test('bmi.values пустой и last/delta/category = null', () {
|
||||
final model = InsightsPayloadModel.fromJson(
|
||||
_fixture('insights_payload.json'),
|
||||
);
|
||||
|
||||
expect(model.bmi.values, isEmpty);
|
||||
expect(model.bmi.last, isNull);
|
||||
expect(model.bmi.delta, isNull);
|
||||
expect(model.bmi.category, isNull);
|
||||
expect(model.bmi.deltaText, contains('рост'));
|
||||
});
|
||||
|
||||
test('intra без wake/sleep и null в average/percent', () {
|
||||
final model = InsightsPayloadModel.fromJson(
|
||||
_fixture('insights_payload_minimal.json'),
|
||||
);
|
||||
|
||||
expect(model.intra!.wake, isNull);
|
||||
expect(model.intra!.sleep, isNull);
|
||||
expect(model.intra!.bars, isEmpty);
|
||||
expect(model.daily!.average, isNull);
|
||||
expect(model.daily!.percent, isNull);
|
||||
expect(model.weight.last, isNull);
|
||||
});
|
||||
|
||||
test('daily и intra необязательны', () {
|
||||
final json = _fixture('insights_payload_minimal.json')
|
||||
..remove('daily')
|
||||
..remove('intra');
|
||||
|
||||
final model = InsightsPayloadModel.fromJson(json);
|
||||
|
||||
expect(model.daily, isNull);
|
||||
expect(model.intra, isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user