forked from eatvio/eatvio_app
feat(insights): review fixes
This commit is contained in:
57
test/fixtures/doubles/insights_doubles.dart
vendored
57
test/fixtures/doubles/insights_doubles.dart
vendored
@@ -6,14 +6,22 @@ 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>;
|
||||
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();
|
||||
FakeInsightsRepository({
|
||||
InsightsPayloadModel? payload,
|
||||
this.error,
|
||||
this.heightCm = 176,
|
||||
}) : payload = payload ?? loadInsightsPayloadFixture();
|
||||
|
||||
InsightsPayloadModel payload;
|
||||
|
||||
@@ -28,8 +36,22 @@ class FakeInsightsRepository extends Fake implements InsightsRepository {
|
||||
Object? error;
|
||||
int? heightCm;
|
||||
|
||||
/// Задержка ответа [fetchInsights] (для тестов гонок).
|
||||
Duration? fetchInsightsDelay;
|
||||
|
||||
/// Задержка ответа [fetchIntra] (для тестов гонок).
|
||||
Duration? fetchIntraDelay;
|
||||
|
||||
final List<({String? slug, BodyPeriod period})> insightsRequests = [];
|
||||
final List<({String? slug, BodyPeriod bodyPeriod, DailyPeriod dailyPeriod, String? intraDate})> serverRequests = [];
|
||||
final List<
|
||||
({
|
||||
String? slug,
|
||||
BodyPeriod bodyPeriod,
|
||||
DailyPeriod dailyPeriod,
|
||||
String? intraDate,
|
||||
})
|
||||
>
|
||||
serverRequests = [];
|
||||
final List<({String? slug, String? date})> intraRequests = [];
|
||||
final List<double> addedWeights = [];
|
||||
final List<({int chest, int waist, int hip})> addedCircumferences = [];
|
||||
@@ -38,7 +60,11 @@ class FakeInsightsRepository extends Fake implements InsightsRepository {
|
||||
Future<int?> getHeightCm({String? slug}) async => heightCm;
|
||||
|
||||
@override
|
||||
Future<InsightsPayloadModel> getInsights({String? slug, required BodyPeriod bodyPeriod, int? heightCm}) async {
|
||||
Future<InsightsPayloadModel> getInsights({
|
||||
String? slug,
|
||||
required BodyPeriod bodyPeriod,
|
||||
int? heightCm,
|
||||
}) async {
|
||||
insightsRequests.add((slug: slug, period: bodyPeriod));
|
||||
final failure = error;
|
||||
if (failure != null) {
|
||||
@@ -54,7 +80,16 @@ class FakeInsightsRepository extends Fake implements InsightsRepository {
|
||||
required DailyPeriod dailyPeriod,
|
||||
String? intraDate,
|
||||
}) async {
|
||||
serverRequests.add((slug: slug, bodyPeriod: bodyPeriod, dailyPeriod: dailyPeriod, intraDate: intraDate));
|
||||
serverRequests.add((
|
||||
slug: slug,
|
||||
bodyPeriod: bodyPeriod,
|
||||
dailyPeriod: dailyPeriod,
|
||||
intraDate: intraDate,
|
||||
));
|
||||
final delay = fetchInsightsDelay;
|
||||
if (delay != null) {
|
||||
await Future<void>.delayed(delay);
|
||||
}
|
||||
final failure = error;
|
||||
if (failure != null) {
|
||||
throw failure;
|
||||
@@ -65,6 +100,10 @@ class FakeInsightsRepository extends Fake implements InsightsRepository {
|
||||
@override
|
||||
Future<IntraChartModel> fetchIntra({String? slug, String? intraDate}) async {
|
||||
intraRequests.add((slug: slug, date: intraDate));
|
||||
final delay = fetchIntraDelay;
|
||||
if (delay != null) {
|
||||
await Future<void>.delayed(delay);
|
||||
}
|
||||
final failure = intraError ?? error;
|
||||
if (failure != null) {
|
||||
throw failure;
|
||||
@@ -83,6 +122,10 @@ class FakeInsightsRepository extends Fake implements InsightsRepository {
|
||||
required int waistCircumference,
|
||||
required int hipCircumference,
|
||||
}) async {
|
||||
addedCircumferences.add((chest: chestCircumference, waist: waistCircumference, hip: hipCircumference));
|
||||
addedCircumferences.add((
|
||||
chest: chestCircumference,
|
||||
waist: waistCircumference,
|
||||
hip: hipCircumference,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user