forked from eatvio/eatvio_app
55 lines
2.0 KiB
Dart
55 lines
2.0 KiB
Dart
import 'dart:convert';
|
||
import 'dart:io';
|
||
|
||
import 'package:eatvio_app/features/insights/models/insights_payload_model.dart';
|
||
import 'package:eatvio_app/features/insights/models/insights_period.dart';
|
||
import 'package:eatvio_app/features/insights/repositories/insights_repository.dart';
|
||
import 'package:flutter_test/flutter_test.dart';
|
||
|
||
InsightsPayloadModel loadInsightsPayloadFixture([String name = 'insights_payload.json']) {
|
||
final json = jsonDecode(File('test/fixtures/insights/$name').readAsStringSync()) as Map<String, dynamic>;
|
||
return InsightsPayloadModel.fromJson(json);
|
||
}
|
||
|
||
/// Подмена [InsightsRepository] для виджет-тестов: без сети, с журналом вызовов.
|
||
class FakeInsightsRepository extends Fake implements InsightsRepository {
|
||
FakeInsightsRepository({InsightsPayloadModel? payload, this.error, this.heightCm = 176}) : payload = payload ?? loadInsightsPayloadFixture();
|
||
|
||
InsightsPayloadModel payload;
|
||
|
||
/// Если задан — выбрасывается из [getInsights] (например, [InsightsForbidden]).
|
||
Object? error;
|
||
int? heightCm;
|
||
|
||
final List<({String? slug, BodyPeriod period})> insightsRequests = [];
|
||
final List<double> addedWeights = [];
|
||
final List<({int chest, int waist, int hip})> addedCircumferences = [];
|
||
|
||
@override
|
||
Future<int?> getHeightCm({String? slug}) async => heightCm;
|
||
|
||
@override
|
||
Future<InsightsPayloadModel> getInsights({String? slug, required BodyPeriod bodyPeriod, int? heightCm}) async {
|
||
insightsRequests.add((slug: slug, period: bodyPeriod));
|
||
final failure = error;
|
||
if (failure != null) {
|
||
throw failure;
|
||
}
|
||
return payload;
|
||
}
|
||
|
||
@override
|
||
Future<void> addWeight({required double weight}) async {
|
||
addedWeights.add(weight);
|
||
}
|
||
|
||
@override
|
||
Future<void> addCircumference({
|
||
required int chestCircumference,
|
||
required int waistCircumference,
|
||
required int hipCircumference,
|
||
}) async {
|
||
addedCircumferences.add((chest: chestCircumference, waist: waistCircumference, hip: hipCircumference));
|
||
}
|
||
}
|