merge upstream

This commit is contained in:
2026-11-16 13:42:34 +00:00
77 changed files with 8772 additions and 1571 deletions

View File

@@ -31,24 +31,70 @@ void main() {
};
test('parses commented_from_diet state', () {
final model = PortionModel.fromJson(portionJson(state: 'commented_from_diet'));
final model = PortionModel.fromJson(
portionJson(state: 'commented_from_diet'),
);
expect(model.portionState, PortionState.commentedFromDiet);
});
test('parses reviewed_from_diet state', () {
final model = PortionModel.fromJson(portionJson(state: 'reviewed_from_diet'));
final model = PortionModel.fromJson(
portionJson(state: 'reviewed_from_diet'),
);
expect(model.portionState, PortionState.reviewedFromDiet);
});
test('does not throw on unknown state from backend', () {
final model = PortionModel.fromJson(portionJson(state: 'some_future_state'));
final model = PortionModel.fromJson(
portionJson(state: 'some_future_state'),
);
expect(model.portionState, PortionState.unknown);
});
});
group('DiaryDayModel.user (владелец дневника)', () {
Map<String, dynamic> diaryJson({Object? user}) => {
'id': 1,
'date': '2026-11-09',
'closed': 0,
'comment': '',
'state': {
'has_chosen_diet': false,
'has_chosen_plan': false,
'last_state': null,
},
'meals': <dynamic>[],
'chosen_plan_id': null,
'day_of_chosen_diet': null,
'chosen_diet': null,
'user': ?user,
};
test('user.slug попадает в entity как ownerSlug', () {
final model = DiaryDayModel.fromJson(
diaryJson(user: {'id': 3577, 'slug': 'id-3577'}),
);
expect(model.owner?.id, 3577);
expect(model.toEntity()!.ownerSlug, 'id-3577');
});
test('старый ответ без user: ownerSlug == null', () {
expect(DiaryDayModel.fromJson(diaryJson()).toEntity()!.ownerSlug, isNull);
});
test('user.slug == null (у владельца нет slug): ownerSlug == null', () {
final model = DiaryDayModel.fromJson(
diaryJson(user: {'id': 1, 'slug': null}),
);
expect(model.toEntity()!.ownerSlug, isNull);
});
});
group('DiaryDayWrapperModel', () {
test('fromJson parses diary correctly', () {
final json = {
@@ -57,7 +103,11 @@ void main() {
'date': '2024-01-15',
'closed': 0,
'comment': 'Test comment',
'state': {'has_chosen_diet': false, 'has_chosen_plan': false, 'last_state': null},
'state': {
'has_chosen_diet': false,
'has_chosen_plan': false,
'last_state': null,
},
'meals': [],
'chosen_plan_id': null,
'day_of_chosen_diet': null,
@@ -78,7 +128,11 @@ void main() {
date: '2024-01-15',
closed: 0,
comment: 'Test comment',
typeOfDiary: TypeOfDiaryModel(hasChosenDiet: false, hasChosenPlan: false, diaryState: null),
typeOfDiary: TypeOfDiaryModel(
hasChosenDiet: false,
hasChosenPlan: false,
diaryState: null,
),
meals: [],
chosenPlanId: null,
dayOfChosenDiet: null,
@@ -119,7 +173,12 @@ void main() {
group('DiaryPhotoModel', () {
test('fromJson parses all fields correctly', () {
final json = {'id': 10, 'original_name': 'photo.jpg', 'path': '/path/to/photo.jpg', 'size': 1024};
final json = {
'id': 10,
'original_name': 'photo.jpg',
'path': '/path/to/photo.jpg',
'size': 1024,
};
final model = DiaryPhotoModel.fromJson(json);
@@ -130,7 +189,12 @@ void main() {
});
test('toJson serializes all fields correctly', () {
const model = DiaryPhotoModel(id: 10, originalName: 'photo.jpg', path: '/path/to/photo.jpg', size: 1024);
const model = DiaryPhotoModel(
id: 10,
originalName: 'photo.jpg',
path: '/path/to/photo.jpg',
size: 1024,
);
final json = model.toJson();
@@ -201,7 +265,11 @@ void main() {
group('ProductInMeal', () {
test('fromJson parses all fields correctly', () {
final json = {'product_name': 'Banana', 'portion': '1 piece', 'quantity': 2};
final json = {
'product_name': 'Banana',
'portion': '1 piece',
'quantity': 2,
};
final model = ProductInMeal.fromJson(json);
@@ -211,7 +279,11 @@ void main() {
});
test('toJson serializes all fields correctly', () {
const model = ProductInMeal(productName: 'Banana', portion: '1 piece', quantity: 2);
const model = ProductInMeal(
productName: 'Banana',
portion: '1 piece',
quantity: 2,
);
final json = model.toJson();
@@ -228,7 +300,11 @@ void main() {
date: '2024-01-15',
closed: 0,
comment: 'Test',
typeOfDiary: TypeOfDiaryModel(hasChosenDiet: false, hasChosenPlan: false, diaryState: null),
typeOfDiary: TypeOfDiaryModel(
hasChosenDiet: false,
hasChosenPlan: false,
diaryState: null,
),
meals: [],
chosenPlanId: null,
dayOfChosenDiet: null,
@@ -248,7 +324,11 @@ void main() {
retire: '22:00',
closed: 0,
comment: 'Test comment',
typeOfDiary: TypeOfDiaryModel(hasChosenDiet: false, hasChosenPlan: false, diaryState: null),
typeOfDiary: TypeOfDiaryModel(
hasChosenDiet: false,
hasChosenPlan: false,
diaryState: null,
),
meals: [],
chosenPlanId: null,
dayOfChosenDiet: null,
@@ -272,7 +352,11 @@ void main() {
date: '2024-01-15',
closed: 0,
comment: 'Test',
typeOfDiary: TypeOfDiaryModel(hasChosenDiet: true, hasChosenPlan: false, diaryState: null),
typeOfDiary: TypeOfDiaryModel(
hasChosenDiet: true,
hasChosenPlan: false,
diaryState: null,
),
meals: [],
chosenPlanId: null,
dayOfChosenDiet: 5,

View File

@@ -1,3 +1,5 @@
import 'dart:async';
import 'package:eatvio_app/core/app_config.dart';
import 'package:eatvio_app/core/app_initializer.dart';
import 'package:eatvio_app/core/locator_service.dart';
@@ -15,6 +17,8 @@ import 'package:eatvio_app/features/diary/models/diary_day_model.dart';
import 'package:eatvio_app/features/diary/models/nutrition_model.dart';
import 'package:eatvio_app/core/widgets/data_error_widget.dart';
import 'package:eatvio_app/features/diary/presentation/widgets/meal_widget.dart';
import 'package:eatvio_app/features/insights/presentation/widgets/insights_card.dart';
import 'package:eatvio_app/features/insights/repositories/insights_repository.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
@@ -23,6 +27,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import '../../../../fixtures/doubles/insights_doubles.dart';
import 'diary_screen_smoke_test.mocks.dart';
@GenerateNiceMocks([
@@ -44,6 +49,9 @@ void main() {
AppConfig(buildType: AppBuildType.tests)
..setBaseUrl('http://localhost'),
);
sl.registerLazySingleton<InsightsRepository>(
() => FakeInsightsRepository(),
);
});
Widget wrap(Widget child) {
@@ -66,11 +74,13 @@ void main() {
bool isDiaryFinished = false,
bool isDiaryCommented = false,
int closed = 0,
String? ownerSlug,
String wakeup = '07:00',
}) {
final diary = DiaryDayEntity(
id: 1,
date: date,
wakeup: '07:00',
wakeup: wakeup,
retire: '23:00',
closed: closed,
comment: '',
@@ -93,6 +103,7 @@ void main() {
chosenPlanId: hasChosenPlan ? 10 : null,
dayOfChosenDiet: null,
diet: null,
ownerSlug: ownerSlug,
);
const nutrition = NutritionDataModel(
dailyNutritionIntake: NutritionModel(
@@ -383,6 +394,241 @@ void main() {
expect(find.byType(Text), findsWidgets);
});
Future<void> pumpDiaryWithInsights(
WidgetTester tester, {
required bool isConsultantView,
String? ownerSlug,
String? diaryOwnerSlug,
Stream<DiaryState>? diaryStates,
required FakeInsightsRepository insightsRepository,
}) async {
final diaryCubit = MockDiaryCubit();
final state = loadedState(
hasChosenPlan: false,
ownerSlug: diaryOwnerSlug,
).copyWith(isConsultantView: isConsultantView);
when(diaryCubit.state).thenReturn(state);
when(
diaryCubit.stream,
).thenAnswer((_) => diaryStates ?? const Stream<DiaryState>.empty());
when(diaryCubit.close()).thenAnswer((_) async => Future<void>.value());
when(
diaryCubit.fetchDiaryV2(
needLoading: anyNamed('needLoading'),
diaryId: anyNamed('diaryId'),
),
).thenAnswer((_) async => true);
final commentsCubit = MockConsultantCommentsCubit();
when(commentsCubit.state).thenReturn(
ConsultantCommentsState(
commentsModel: ConsultantCommentModel(comment: ''),
),
);
when(
commentsCubit.stream,
).thenAnswer((_) => const Stream<ConsultantCommentsState>.empty());
when(commentsCubit.close()).thenAnswer((_) async => Future<void>.value());
sl.registerFactory<DiaryCubit>(() => diaryCubit);
sl.registerFactory<ConsultantCommentsCubit>(() => commentsCubit);
sl.unregister<InsightsRepository>();
sl.registerLazySingleton<InsightsRepository>(() => insightsRepository);
await tester.pumpWidget(
wrap(
isConsultantView
? UserDiaryScreen(diaryId: 1, ownerSlug: ownerSlug)
: DiaryScreen(date: DateTime(2025, 1, 1)),
),
);
await tester.pump(const Duration(milliseconds: 200));
}
testWidgets(
'own diary shows insights card for own data with add button enabled',
(tester) async {
final insightsRepository = FakeInsightsRepository();
await pumpDiaryWithInsights(
tester,
isConsultantView: false,
insightsRepository: insightsRepository,
);
expect(find.byType(InsightsCard), findsOneWidget);
final card = tester.widget<InsightsCard>(find.byType(InsightsCard));
expect(card.slug, isNull);
expect(card.canAdd, isTrue);
expect(card.initialIntraDate, '2025-01-01');
expect(insightsRepository.serverRequests.single.slug, isNull);
expect(
insightsRepository.serverRequests.single.intraDate,
'2025-01-01',
);
},
);
testWidgets(
'consultant view shows insights card of the client without add button',
(tester) async {
final insightsRepository = FakeInsightsRepository();
await pumpDiaryWithInsights(
tester,
isConsultantView: true,
ownerSlug: 'client',
insightsRepository: insightsRepository,
);
final card = tester.widget<InsightsCard>(find.byType(InsightsCard));
expect(card.slug, 'client');
expect(card.canAdd, isFalse);
expect(insightsRepository.serverRequests.single.slug, 'client');
},
);
testWidgets(
'consultant view takes the owner slug from the diary (user.slug)',
(tester) async {
final insightsRepository = FakeInsightsRepository();
await pumpDiaryWithInsights(
tester,
isConsultantView: true,
diaryOwnerSlug: 'client-from-diary',
insightsRepository: insightsRepository,
);
expect(
tester.widget<InsightsCard>(find.byType(InsightsCard)).slug,
'client-from-diary',
);
expect(
insightsRepository.serverRequests.single.slug,
'client-from-diary',
);
},
);
testWidgets('diary owner slug wins over the route parameter', (
tester,
) async {
final insightsRepository = FakeInsightsRepository();
await pumpDiaryWithInsights(
tester,
isConsultantView: true,
ownerSlug: 'from-route',
diaryOwnerSlug: 'from-diary',
insightsRepository: insightsRepository,
);
expect(
tester.widget<InsightsCard>(find.byType(InsightsCard)).slug,
'from-diary',
);
});
testWidgets(
'own diary refreshes insights when meals or wake-up time change',
(tester) async {
final insightsRepository = FakeInsightsRepository();
final states = StreamController<DiaryState>.broadcast();
addTearDown(states.close);
await pumpDiaryWithInsights(
tester,
isConsultantView: false,
diaryStates: states.stream,
insightsRepository: insightsRepository,
);
expect(insightsRepository.serverRequests, hasLength(1));
states.add(loadedState(hasChosenPlan: false, wakeup: '06:30'));
await tester.pump(const Duration(milliseconds: 200));
expect(insightsRepository.serverRequests, hasLength(2));
},
);
testWidgets(
'own diary does not refresh insights when nothing relevant changed',
(tester) async {
final insightsRepository = FakeInsightsRepository();
final states = StreamController<DiaryState>.broadcast();
addTearDown(states.close);
await pumpDiaryWithInsights(
tester,
isConsultantView: false,
diaryStates: states.stream,
insightsRepository: insightsRepository,
);
states.add(loadedState(hasChosenPlan: false));
await tester.pump(const Duration(milliseconds: 200));
expect(insightsRepository.serverRequests, hasLength(1));
},
);
testWidgets('consultant view does not refresh insights on diary changes', (
tester,
) async {
final insightsRepository = FakeInsightsRepository();
final states = StreamController<DiaryState>.broadcast();
addTearDown(states.close);
await pumpDiaryWithInsights(
tester,
isConsultantView: true,
ownerSlug: 'client',
diaryStates: states.stream,
insightsRepository: insightsRepository,
);
states.add(
loadedState(
hasChosenPlan: false,
wakeup: '06:30',
).copyWith(isConsultantView: true),
);
await tester.pump(const Duration(milliseconds: 200));
expect(insightsRepository.serverRequests, hasLength(1));
});
testWidgets('consultant view without owner slug hides insights card', (
tester,
) async {
final insightsRepository = FakeInsightsRepository();
await pumpDiaryWithInsights(
tester,
isConsultantView: true,
insightsRepository: insightsRepository,
);
expect(find.byType(InsightsCard), findsNothing);
expect(insightsRepository.serverRequests, isEmpty);
});
testWidgets('consultant view hides insights card on 403', (tester) async {
final insightsRepository = FakeInsightsRepository(
error: const InsightsForbidden(),
);
await pumpDiaryWithInsights(
tester,
isConsultantView: true,
ownerSlug: 'client',
insightsRepository: insightsRepository,
);
expect(find.byKey(const Key('insights_card')), findsNothing);
});
testWidgets('shows add button for a finished day inside the edit window', (
tester,
) async {

View File

@@ -0,0 +1,285 @@
import 'package:eatvio_app/features/insights/domain/insights_text_builder.dart';
import 'package:eatvio_app/features/insights/models/insights_period.dart';
import 'package:eatvio_app/features/profile/models/circumference_model.dart';
import 'package:eatvio_app/features/profile/models/weight_model.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
WeightModel _weight(double weight, {double? bmi, int day = 1}) {
final date = DateTime(2026, 11, day, 12);
return WeightModel(
id: day,
userId: 1,
weight: weight,
createdAt: date,
updatedAt: date,
bmi: bmi,
);
}
CircumferenceModel _circumference({
double waist = 80,
double chest = 95,
double hips = 100,
int day = 1,
}) {
final date = DateTime(2026, 11, day, 12);
return CircumferenceModel(
id: day,
userId: 1,
chestCircumference: chest,
waistCircumference: waist,
hipCircumference: hips,
createdAt: date,
updatedAt: date,
);
}
void main() {
late InsightsTextBuilder builder;
setUpAll(() async {
final s = await S.load(const Locale('ru'));
builder = InsightsTextBuilder(s);
});
group('форматирование', () {
test('formatNumber: один знак без хвостового нуля', () {
expect(builder.formatNumber(3), '3');
expect(builder.formatNumber(3.5), '3.5');
expect(builder.formatNumber(3.04), '3');
expect(builder.formatNumber(3.26), '3.3');
});
test('formatLabel: dd.MM', () {
expect(builder.formatLabel(DateTime(2026, 11, 9, 12)), '09.11');
});
test('periodLabel: все периоды', () {
expect(builder.periodLabel(BodyPeriod.month), 'месяц');
expect(builder.periodLabel(BodyPeriod.threeMonths), '3 месяца');
expect(builder.periodLabel(BodyPeriod.sixMonths), '6 месяцев');
expect(builder.periodLabel(BodyPeriod.year), 'год');
expect(builder.periodLabel(BodyPeriod.all), 'всё время');
});
});
group('вес', () {
test('снижение', () {
final model = builder.buildWeight([
_weight(74.5),
_weight(73.2, day: 9),
], BodyPeriod.month);
expect(model.deltaText, 'Снизили на 1.3 кг за месяц');
expect(model.delta, -1.3);
expect(model.last, 73.2);
expect(model.headline, '73.2');
expect(model.unit, 'кг');
expect(model.labels, ['01.11', '09.11']);
expect(model.values, [74.5, 73.2]);
});
test('набор', () {
final model = builder.buildWeight([
_weight(70),
_weight(72, day: 3),
], BodyPeriod.threeMonths);
expect(model.deltaText, 'Набрали 2 кг за 3 месяца');
expect(model.delta, 2);
});
test('порог 0.05: меньше — не изменился', () {
final model = builder.buildWeight([
_weight(70),
_weight(70.04, day: 3),
], BodyPeriod.year);
expect(model.deltaText, 'Вес не изменился за год');
});
test('порог 0.05: ровно 0.25 — уже изменение', () {
final model = builder.buildWeight([
_weight(70),
_weight(70.25, day: 3),
], BodyPeriod.all);
expect(model.deltaText, 'Набрали 0.3 кг за всё время');
});
test('одна точка: недостаточно данных, но headline есть', () {
final model = builder.buildWeight([_weight(72)], BodyPeriod.month);
expect(model.deltaText, 'Недостаточно данных');
expect(model.delta, isNull);
expect(model.headline, '72.0');
});
test('нет точек', () {
final model = builder.buildWeight([], BodyPeriod.month);
expect(model.deltaText, 'Недостаточно данных');
expect(model.last, isNull);
expect(model.headline, '—');
expect(model.values, isEmpty);
});
});
group('категории ИМТ (границы)', () {
final cases = <double, String>{
15.9: 'выраженный дефицит массы',
16.0: 'недостаточная масса',
18.4: 'недостаточная масса',
18.5: 'норма',
24.9: 'норма',
25.0: 'избыточная масса',
29.9: 'избыточная масса',
30.0: 'ожирение I ст.',
34.9: 'ожирение I ст.',
35.0: 'ожирение II ст.',
39.9: 'ожирение II ст.',
40.0: 'ожирение III ст.',
55.0: 'ожирение III ст.',
};
cases.forEach((bmi, expected) {
test('$bmi → $expected', () {
expect(builder.bmiCategory(bmi), expected);
});
});
});
group('ИМТ', () {
test('без роста: пусто и подсказка', () {
final model = builder.buildBmi(
[_weight(70, bmi: 22)],
BodyPeriod.month,
null,
);
expect(model.values, isEmpty);
expect(model.headline, '—');
expect(model.hint, 'Укажите рост, чтобы посчитать ИМТ.');
expect(model.deltaText, 'Укажите рост, чтобы посчитать ИМТ.');
expect(model.category, isNull);
});
test('нулевой рост считается отсутствующим', () {
final model = builder.buildBmi(
[_weight(70, bmi: 22)],
BodyPeriod.month,
0,
);
expect(model.values, isEmpty);
});
test('ИМТ ниже', () {
final model = builder.buildBmi(
[_weight(80, bmi: 26.5), _weight(75, bmi: 24.2, day: 5)],
BodyPeriod.threeMonths,
176,
);
expect(model.deltaText, 'ИМТ ниже на 2.3 за 3 месяца · норма');
expect(model.category, 'норма');
expect(model.headline, '24.2');
expect(model.last, 24.2);
expect(model.delta, -2.3);
expect(model.hint, contains('Считаем при росте 176 см.'));
});
test('ИМТ выше', () {
final model = builder.buildBmi(
[_weight(70, bmi: 24), _weight(80, bmi: 27, day: 5)],
BodyPeriod.month,
170,
);
expect(model.deltaText, 'ИМТ выше на 3 за месяц · избыточная масса');
});
test('ИМТ не изменился', () {
final model = builder.buildBmi(
[_weight(70, bmi: 22), _weight(70, bmi: 22.01, day: 5)],
BodyPeriod.year,
170,
);
expect(model.deltaText, 'ИМТ не изменился за год · норма');
});
test('точки с bmi = null пропускаются', () {
final model = builder.buildBmi(
[_weight(70, bmi: null), _weight(71, bmi: 22, day: 3)],
BodyPeriod.month,
170,
);
expect(model.values, [22]);
expect(model.labels, ['03.11']);
expect(model.deltaText, 'Недостаточно данных');
});
test('рост есть, точек нет', () {
final model = builder.buildBmi([], BodyPeriod.month, 170);
expect(model.values, isEmpty);
expect(model.deltaText, 'Недостаточно данных');
expect(model.hint, contains('170'));
});
});
group('замеры', () {
test('по каждой части: меньше / больше / без изменений', () {
final model = builder.buildMeasure([
_circumference(waist: 82, chest: 96, hips: 100),
_circumference(waist: 80.5, chest: 98, hips: 100, day: 9),
], BodyPeriod.month);
expect(
model.deltaText,
'Талия меньше на 1.5 см, Грудь больше на 2 см, Бёдра без изменений за месяц',
);
expect(model.headline, '81');
expect(model.waist, [82, 80.5]);
expect(model.labels, ['01.11', '09.11']);
});
test('одна точка — недостаточно данных', () {
final model = builder.buildMeasure([_circumference()], BodyPeriod.month);
expect(model.deltaText, 'Недостаточно данных');
expect(model.headline, '80');
});
test('нет точек', () {
final model = builder.buildMeasure([], BodyPeriod.month);
expect(model.headline, '—');
expect(model.deltaText, 'Недостаточно данных');
});
});
group('build', () {
test('сортирует по дате, daily/intra = null', () {
final payload = builder.build(
weights: [_weight(73, bmi: 23, day: 9), _weight(75, bmi: 24, day: 1)],
circumferences: [
_circumference(waist: 79, day: 9),
_circumference(waist: 81),
],
period: BodyPeriod.month,
heightCm: 175,
);
expect(payload.weight.values, [75, 73]);
expect(payload.bmi.values, [24, 23]);
expect(payload.measure.waist, [81, 79]);
expect(payload.daily, isNull);
expect(payload.intra, isNull);
});
});
}

View File

@@ -0,0 +1,75 @@
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; daily == null', () {
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, 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);
});
});
}

View File

@@ -0,0 +1,154 @@
import 'dart:convert';
import 'dart:io';
import 'package:eatvio_app/features/insights/models/insights_response_model.dart';
import 'package:flutter_test/flutter_test.dart';
Map<String, dynamic> _fixture(String name) =>
jsonDecode(File('test/fixtures/insights/$name').readAsStringSync())
as Map<String, dynamic>;
/// Контракт `GET /api/profile/insights*` (eatvio/eatvio#3017).
void main() {
group('InsightsResponseModel', () {
test('полный ответ: data с weight/bmi/measure/daily/intra', () {
final data = InsightsResponseModel.fromJson(
_fixture('insights_response.json'),
).data;
expect(data.weight.headline, '73.2');
expect(data.measure.waist, [82, 80.5]);
expect(data.daily!.kcal, hasLength(3));
expect(data.intra!.bars, hasLength(2));
});
test('daily.percent — изменение за период, а не процент от нормы', () {
final daily = InsightsResponseModel.fromJson(
_fixture('insights_response.json'),
).data.daily!;
expect(daily.percent, 5);
expect(daily.deltaText, 'Калораж вырос на 5% за период');
});
test('нет КБЖУ за период: daily == null', () {
final data = InsightsResponseModel.fromJson(
_fixture('insights_response_empty.json'),
).data;
expect(data.daily, isNull);
});
test('пустые замеры: headline "—" и текст «Недостаточно данных»', () {
final measure = InsightsResponseModel.fromJson(
_fixture('insights_response_empty.json'),
).data.measure;
expect(measure.labels, isEmpty);
expect(measure.headline, '—');
expect(measure.deltaText, 'Недостаточно данных');
});
test('пустой день: intra приходит объектом с датами, без сна', () {
final intra = InsightsResponseModel.fromJson(
_fixture('insights_response_empty.json'),
).data.intra!;
expect(intra.bars, isEmpty);
expect(intra.satiety, isEmpty);
expect(intra.mood, isEmpty);
expect(intra.wake, isNull);
expect(intra.sleep, isNull);
expect(intra.date, '2026-11-09');
expect(intra.maxDate, '2026-11-09');
expect(intra.isToday, isTrue);
});
test(
'сокращённый пример из описания бэка разбирается без подписей сна',
() {
final data = InsightsResponseModel.fromJson(
jsonDecode(
jsonEncode({
'data': {
'weight': {
'labels': ['30.10', '07.11'],
'values': [80, 78],
'last': 78,
'delta': -2,
'headline': '78',
'unit': 'кг',
'deltaText': 'Снизили на 2 кг за 3 месяца',
},
'bmi': {},
'measure': {
'labels': [],
'waist': [],
'chest': [],
'hips': [],
'headline': '—',
'deltaText': 'Недостаточно данных',
},
'daily': {
'labels': ['09.11'],
'kcal': [250],
'proteins': [10],
'fats': [5],
'carbs': [30],
'average': 250,
'percent': 0,
'headline': '250',
'deltaText': 'Калораж не изменился за период',
},
'intra': {
'bars': [
{'x': 12.5, 'p': 40, 'f': 45, 'c': 120},
],
'satiety': [
{'x': 12.5, 'y': 4},
],
'mood': [
{'x': 12.5, 'y': 3},
],
'wake': 7,
'sleep': 23,
'date': '2026-11-09',
'maxDate': '2026-11-09',
'dateLabel': 'Сегодня',
'isToday': true,
},
},
}),
)
as Map<String, dynamic>,
).data;
expect(data.weight.values, [80, 78]);
expect(data.daily!.percent, 0);
expect(data.intra!.wake, 7);
expect(data.intra!.wakeLabel, isNull);
expect(data.intra!.wakeText, isNull);
},
);
});
group('InsightsIntraResponseModel', () {
test('ответ /insights/intra: data.intra', () {
final intra = InsightsIntraResponseModel.fromJson(
_fixture('insights_intra_response.json'),
).data.intra;
expect(intra.date, '2026-11-09');
expect(intra.bars, isNotEmpty);
});
test('прошедший день: isToday == false', () {
final intra = InsightsIntraResponseModel.fromJson(
_fixture('insights_intra_response_yesterday.json'),
).data.intra;
expect(intra.isToday, isFalse);
expect(intra.dateLabel, '8 ноября');
});
});
}

View File

@@ -0,0 +1,76 @@
import 'package:eatvio_app/features/insights/presentation/charts/insights_chart_common.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
void main() {
test('insightsSplineType — monotonic, чтобы кривая не уходила ниже точек', () {
expect(insightsSplineType, SplineType.monotonic);
});
group('buildPoints', () {
test('сохраняет индекс и дату даже при повторяющихся labels', () {
final points = buildPoints(
['05.07', '05.07', '06.07', '07.07'],
[10, 20, 30, 40],
);
expect(points.map((p) => p.index).toList(), [0, 1, 2, 3]);
expect(points.map((p) => p.label).toList(), [
'05.07',
'05.07',
'06.07',
'07.07',
]);
expect(points.map((p) => p.value).toList(), [10, 20, 30, 40]);
});
test('обрезает по короткому массиву', () {
expect(buildPoints(['a', 'b'], [1]), hasLength(1));
});
});
group('buildInsightsIndexAxis', () {
test('ось строится по числу точек, а не по уникальным строкам дат', () {
final labels = [
'05.07',
'06.07',
'07.07',
'08.07',
'09.07',
'10.07',
'11.07',
];
final axis = buildInsightsIndexAxis(labels);
expect(axis.minimum, 0);
expect(axis.maximum, 6);
expect(axis.interval, 1);
expect(axis.axisLabelFormatter, isNotNull);
});
test('для длинного периода ставит интервал больше 1', () {
final labels = List.generate(30, (i) => '${i + 1}.07');
final axis = buildInsightsIndexAxis(labels);
expect(axis.maximum, 29);
expect(axis.interval, greaterThan(1));
});
});
group('paddedRange', () {
test('даёт локальный диапазон вокруг данных', () {
final range = paddedRange([70, 72], minPadding: 1);
expect(range.min, lessThan(70));
expect(range.max, greaterThan(72));
expect(range.min, greaterThan(0));
});
test('clampZero не уводит минимум ниже нуля', () {
final range = paddedRange([2, 8], minPadding: 5, clampZero: true);
expect(range.min, 0);
expect(range.max, greaterThan(8));
});
});
}

View File

@@ -0,0 +1,395 @@
import 'package:dio/dio.dart';
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/presentation/cubit/insights_cubit.dart';
import 'package:eatvio_app/features/insights/presentation/cubit/insights_panel.dart';
import 'package:eatvio_app/features/insights/presentation/cubit/insights_state.dart';
import 'package:eatvio_app/features/insights/repositories/insights_repository.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../../../fixtures/doubles/insights_doubles.dart';
/// Серверный режим (`kbjuEnabled: true`): `GET /api/profile/insights*`.
void main() {
late FakeInsightsRepository repository;
late IntraChartModel today;
late IntraChartModel yesterday;
setUp(() {
repository = FakeInsightsRepository();
today = repository.payload.intra!;
yesterday = today.copyWith(
date: '2026-11-08',
dateLabel: '8 ноября',
isToday: false,
);
repository.intraByDate['2026-11-08'] = yesterday;
repository.intraByDate['2026-11-09'] = today;
});
InsightsCubit buildCubit({String? slug}) {
return InsightsCubit(repository: repository, slug: slug, kbjuEnabled: true);
}
InsightsStateLoaded loaded(InsightsCubit cubit) =>
cubit.state as InsightsStateLoaded;
group('load', () {
test('запрашивает серверный payload с дефолтными периодами', () async {
final cubit = buildCubit();
await cubit.load();
expect(repository.serverRequests, [
(
slug: null,
bodyPeriod: BodyPeriod.threeMonths,
dailyPeriod: DailyPeriod.twoWeeks,
intraDate: null,
),
]);
expect(repository.insightsRequests, isEmpty);
expect(loaded(cubit).payload.daily, isNotNull);
expect(loaded(cubit).dailyPeriod, DailyPeriod.twoWeeks);
expect(loaded(cubit).intraDate, isNull);
await cubit.close();
});
test('рост профиля не запрашивается: ИМТ считает сервер', () async {
repository.heightCm = null;
final cubit = buildCubit(slug: 'client');
await cubit.load();
expect(repository.serverRequests.single.slug, 'client');
expect(loaded(cubit).payload.bmi, repository.payload.bmi);
await cubit.close();
});
test('403 скрывает блок', () async {
repository.error = const InsightsForbidden();
final cubit = buildCubit(slug: 'client');
await cubit.load();
expect(cubit.state, isA<InsightsStateHidden>());
await cubit.close();
});
test('ошибка сервера → error', () async {
repository.error = DioException(requestOptions: RequestOptions());
final cubit = buildCubit();
await cubit.load();
expect(cubit.state, isA<InsightsStateError>());
await cubit.close();
});
});
group('setDailyPeriod', () {
test('перезапрашивает все данные, сохраняя период тела и день', () async {
final cubit = buildCubit();
await cubit.load();
await cubit.setBodyPeriod(BodyPeriod.year);
await cubit.setIntraDate(DateTime(2026, 11, 8));
repository.serverRequests.clear();
await cubit.setDailyPeriod(DailyPeriod.month);
expect(repository.serverRequests, [
(
slug: null,
bodyPeriod: BodyPeriod.year,
dailyPeriod: DailyPeriod.month,
intraDate: '2026-11-08',
),
]);
expect(loaded(cubit).dailyPeriod, DailyPeriod.month);
expect(loaded(cubit).isRefreshing, isFalse);
await cubit.close();
});
test('тот же период не перезапрашивается', () async {
final cubit = buildCubit();
await cubit.load();
repository.serverRequests.clear();
await cubit.setDailyPeriod(DailyPeriod.twoWeeks);
expect(repository.serverRequests, isEmpty);
await cubit.close();
});
test('ошибка оставляет выбранный период и старые данные', () async {
final cubit = buildCubit();
await cubit.load();
final before = loaded(cubit).payload;
repository.error = DioException(requestOptions: RequestOptions());
await cubit.setDailyPeriod(DailyPeriod.week);
expect(loaded(cubit).dailyPeriod, DailyPeriod.week);
expect(loaded(cubit).payload, before);
expect(loaded(cubit).isRefreshing, isFalse);
await cubit.close();
});
test('смена периода тела передаёт текущий период КБЖУ', () async {
final cubit = buildCubit();
await cubit.load();
await cubit.setDailyPeriod(DailyPeriod.week);
repository.serverRequests.clear();
await cubit.setBodyPeriod(BodyPeriod.month);
expect(repository.serverRequests.single.dailyPeriod, DailyPeriod.week);
await cubit.close();
});
});
group('«В течение дня»', () {
test(
'setIntraDate запрашивает только intra и подменяет её в payload',
() async {
final cubit = buildCubit();
await cubit.load();
repository.serverRequests.clear();
await cubit.setIntraDate(DateTime(2026, 11, 8));
expect(repository.serverRequests, isEmpty);
expect(repository.intraRequests, [(slug: null, date: '2026-11-08')]);
final state = loaded(cubit);
expect(state.payload.intra, yesterday);
expect(state.payload.weight, repository.payload.weight);
expect(state.intraDate, '2026-11-08');
expect(state.isRefreshing, isFalse);
await cubit.close();
},
);
test('slug передаётся в запрос чужого дня', () async {
final cubit = buildCubit(slug: 'client');
await cubit.load();
await cubit.setIntraDate(DateTime(2026, 11, 8));
expect(repository.intraRequests.single.slug, 'client');
await cubit.close();
});
test(
'быстрые «назад» запрашивают разные дни (оптимистичная дата)',
() async {
repository.fetchIntraDelay = const Duration(milliseconds: 30);
repository.intraByDate['2026-11-07'] = yesterday.copyWith(
date: '2026-11-07',
dateLabel: '7 ноября',
);
final cubit = buildCubit();
await cubit.load();
final first = cubit.showPreviousDay();
final second = cubit.showPreviousDay();
await Future.wait([first, second]);
expect(repository.intraRequests.map((e) => e.date).toList(), [
'2026-11-08',
'2026-11-07',
]);
expect(loaded(cubit).payload.intra!.date, '2026-11-07');
await cubit.close();
},
);
test('полный ответ не затирает более свежий intra и UI-выбор', () async {
repository.fetchInsightsDelay = const Duration(milliseconds: 40);
final cubit = buildCubit();
await cubit.load();
repository.fetchInsightsDelay = const Duration(milliseconds: 80);
repository.serverRequests.clear();
final periodChange = cubit.setBodyPeriod(BodyPeriod.year);
await Future<void>.delayed(const Duration(milliseconds: 10));
cubit.setPanel(InsightsPanel.measures);
cubit.toggleExpanded();
await cubit.setIntraDate(DateTime(2026, 11, 8));
await periodChange;
final state = loaded(cubit);
expect(state.bodyPeriod, BodyPeriod.year);
expect(state.payload.weight, repository.payload.weight);
expect(state.payload.intra, yesterday);
expect(state.intraDate, '2026-11-08');
expect(state.panel, InsightsPanel.measures);
expect(state.isExpanded, isTrue);
expect(state.isRefreshing, isFalse);
await cubit.close();
});
test('load с initialIntraDate запрашивает этот день', () async {
final cubit = buildCubit();
await cubit.load(intraDate: '2026-11-08');
expect(repository.serverRequests.single.intraDate, '2026-11-08');
expect(loaded(cubit).intraDate, '2026-11-08');
await cubit.close();
});
test('showPreviousDay и showNextDay листают по дню', () async {
final cubit = buildCubit();
await cubit.load();
await cubit.showPreviousDay();
expect(repository.intraRequests.last.date, '2026-11-08');
expect(loaded(cubit).payload.intra!.isToday, isFalse);
await cubit.showNextDay();
expect(repository.intraRequests.last.date, '2026-11-09');
expect(loaded(cubit).payload.intra!.isToday, isTrue);
expect(loaded(cubit).intraDate, isNull);
await cubit.close();
});
test('showPreviousDay переходит через границу месяца', () async {
repository.payload = repository.payload.copyWith(
intra: today.copyWith(date: '2026-11-01', isToday: false),
);
final cubit = buildCubit();
await cubit.load();
await cubit.showPreviousDay();
expect(repository.intraRequests.single.date, '2026-10-31');
await cubit.close();
});
test('showNextDay на сегодняшнем дне ничего не запрашивает', () async {
final cubit = buildCubit();
await cubit.load();
await cubit.showNextDay();
expect(repository.intraRequests, isEmpty);
await cubit.close();
});
test('сервер вернул другую дату (clamp) — берём её', () async {
repository.intraByDate['2026-11-20'] = today;
final cubit = buildCubit();
await cubit.load();
await cubit.setIntraDate(DateTime(2026, 11, 20));
expect(loaded(cubit).intraDate, isNull);
expect(loaded(cubit).payload.intra!.date, '2026-11-09');
await cubit.close();
});
test('пустой день: intra с пустыми сериями остаётся объектом', () async {
final empty = today.copyWith(
date: '2026-11-07',
dateLabel: '7 ноября',
isToday: false,
bars: const [],
satiety: const [],
mood: const [],
wake: null,
sleep: null,
wakeText: null,
sleepText: null,
);
repository.intraByDate['2026-11-07'] = empty;
final cubit = buildCubit();
await cubit.load();
await cubit.setIntraDate(DateTime(2026, 11, 7));
expect(loaded(cubit).payload.intra, empty);
await cubit.close();
});
test('ошибка запроса дня не стирает показанные данные', () async {
final cubit = buildCubit();
await cubit.load();
repository.intraError = DioException(requestOptions: RequestOptions());
await cubit.setIntraDate(DateTime(2026, 11, 8));
final state = loaded(cubit);
expect(state.payload.intra, today);
expect(state.intraDate, isNull);
expect(state.isRefreshing, isFalse);
await cubit.close();
});
test('403 при листании скрывает блок', () async {
final cubit = buildCubit(slug: 'client');
await cubit.load();
repository.intraError = const InsightsForbidden();
await cubit.showPreviousDay();
expect(cubit.state, isA<InsightsStateHidden>());
await cubit.close();
});
test('refresh сохраняет выбранный день, вкладку и серии', () async {
final cubit = buildCubit();
await cubit.load();
cubit.toggleExpanded();
cubit.setPanel(InsightsPanel.intra);
cubit.toggleSleep();
await cubit.setIntraDate(DateTime(2026, 11, 8));
repository.serverRequests.clear();
await cubit.refresh();
expect(repository.serverRequests.single.intraDate, '2026-11-08');
final state = loaded(cubit);
expect(state.panel, InsightsPanel.intra);
expect(state.isExpanded, isTrue);
expect(state.showSleep, isFalse);
expect(state.intraDate, '2026-11-08');
await cubit.close();
});
test('refresh во время первой загрузки не дублирует запрос', () async {
final cubit = buildCubit();
final loading = cubit.load();
await cubit.refresh();
await loading;
expect(repository.serverRequests, hasLength(1));
await cubit.close();
});
test('без флага навигация по дням игнорируется', () async {
final cubit = InsightsCubit(repository: repository, kbjuEnabled: false);
await cubit.load();
await cubit.showPreviousDay();
await cubit.setDailyPeriod(DailyPeriod.week);
expect(repository.intraRequests, isEmpty);
expect(repository.serverRequests, isEmpty);
await cubit.close();
});
});
test('после добавления веса данные обновляются с сервера', () async {
final cubit = buildCubit();
await cubit.load();
repository.serverRequests.clear();
final isSaved = await cubit.addWeight(weight: 72.5);
expect(isSaved, isTrue);
expect(repository.addedWeights, [72.5]);
expect(repository.serverRequests, hasLength(1));
await cubit.close();
});
}

View File

@@ -0,0 +1,439 @@
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/presentation/cubit/insights_cubit.dart';
import 'package:eatvio_app/features/insights/presentation/cubit/insights_panel.dart';
import 'package:eatvio_app/features/insights/presentation/cubit/insights_state.dart';
import 'package:eatvio_app/features/insights/repositories/insights_repository.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
class _MockInsightsRepository extends Mock implements InsightsRepository {}
const _payload = InsightsPayloadModel(
weight: WeightChartModel(values: [70, 71], headline: '71.0'),
bmi: BmiChartModel(),
measure: MeasureChartModel(),
);
const _payload2 = InsightsPayloadModel(
weight: WeightChartModel(values: [72], headline: '72.0'),
bmi: BmiChartModel(),
measure: MeasureChartModel(),
);
void main() {
late _MockInsightsRepository repository;
setUpAll(() {
registerFallbackValue(BodyPeriod.month);
registerFallbackValue(DailyPeriod.week);
});
setUp(() {
repository = _MockInsightsRepository();
when(
() => repository.getHeightCm(slug: any(named: 'slug')),
).thenAnswer((_) async => 176);
when(
() => repository.getInsights(
slug: any(named: 'slug'),
bodyPeriod: any(named: 'bodyPeriod'),
heightCm: any(named: 'heightCm'),
),
).thenAnswer((_) async => _payload);
when(
() => repository.fetchInsights(
slug: any(named: 'slug'),
bodyPeriod: any(named: 'bodyPeriod'),
dailyPeriod: any(named: 'dailyPeriod'),
intraDate: any(named: 'intraDate'),
),
).thenAnswer((_) async => _payload);
});
InsightsCubit buildCubit({
String? slug,
bool canAdd = false,
bool kbjuEnabled = false,
}) {
return InsightsCubit(
repository: repository,
slug: slug,
canAdd: canAdd,
kbjuEnabled: kbjuEnabled,
);
}
InsightsStateLoaded loaded(InsightsCubit cubit) =>
cubit.state as InsightsStateLoaded;
test('начальное состояние — initial', () {
expect(buildCubit().state, isA<InsightsStateInitial>());
});
group('load', () {
test('дефолты: период 3М, вкладка «Вес», блок свёрнут', () async {
final cubit = buildCubit();
final states = <InsightsState>[];
cubit.stream.listen(states.add);
await cubit.load();
await Future<void>.delayed(Duration.zero);
expect(states.first, isA<InsightsStateLoading>());
final state = loaded(cubit);
expect(state.bodyPeriod, BodyPeriod.threeMonths);
expect(state.panel, InsightsPanel.weight);
expect(state.isExpanded, isFalse);
expect(state.isRefreshing, isFalse);
expect(state.showSleep, isTrue);
expect(state.payload, _payload);
verify(
() => repository.getInsights(
slug: null,
bodyPeriod: BodyPeriod.threeMonths,
heightCm: 176,
),
).called(1);
await cubit.close();
});
test('пробрасывает slug владельца', () async {
final cubit = buildCubit(slug: 'client');
await cubit.load();
verify(() => repository.getHeightCm(slug: 'client')).called(1);
verify(
() => repository.getInsights(
slug: 'client',
bodyPeriod: BodyPeriod.threeMonths,
heightCm: 176,
),
).called(1);
await cubit.close();
});
test('403 → hidden', () async {
when(
() => repository.getHeightCm(slug: any(named: 'slug')),
).thenThrow(const InsightsForbidden());
final cubit = buildCubit(slug: 'client');
await cubit.load();
expect(cubit.state, isA<InsightsStateHidden>());
await cubit.close();
});
test('403 на запросе точек → hidden', () async {
when(
() => repository.getInsights(
slug: any(named: 'slug'),
bodyPeriod: any(named: 'bodyPeriod'),
heightCm: any(named: 'heightCm'),
),
).thenThrow(const InsightsForbidden());
final cubit = buildCubit(slug: 'client');
await cubit.load();
expect(cubit.state, isA<InsightsStateHidden>());
await cubit.close();
});
test('другая ошибка → error', () async {
when(
() => repository.getInsights(
slug: any(named: 'slug'),
bodyPeriod: any(named: 'bodyPeriod'),
heightCm: any(named: 'heightCm'),
),
).thenThrow(Exception('boom'));
final cubit = buildCubit();
await cubit.load();
expect(cubit.state, isA<InsightsStateError>());
await cubit.close();
});
});
group('setBodyPeriod', () {
test(
'смена периода → перезапрос; рост не запрашивается повторно',
() async {
final cubit = buildCubit();
await cubit.load();
when(
() => repository.getInsights(
slug: null,
bodyPeriod: BodyPeriod.year,
heightCm: 176,
),
).thenAnswer((_) async => _payload2);
await cubit.setBodyPeriod(BodyPeriod.year);
expect(loaded(cubit).bodyPeriod, BodyPeriod.year);
expect(loaded(cubit).payload, _payload2);
expect(loaded(cubit).isRefreshing, isFalse);
verify(() => repository.getHeightCm(slug: null)).called(1);
await cubit.close();
},
);
test('тот же период — без запроса', () async {
final cubit = buildCubit();
await cubit.load();
clearInteractions(repository);
await cubit.setBodyPeriod(BodyPeriod.threeMonths);
verifyNever(
() => repository.getInsights(
slug: any(named: 'slug'),
bodyPeriod: any(named: 'bodyPeriod'),
heightCm: any(named: 'heightCm'),
),
);
await cubit.close();
});
test('ошибка перезапроса оставляет выбранный период и старые данные', () async {
final cubit = buildCubit();
await cubit.load();
when(
() => repository.getInsights(
slug: null,
bodyPeriod: BodyPeriod.all,
heightCm: 176,
),
).thenThrow(Exception('boom'));
await cubit.setBodyPeriod(BodyPeriod.all);
expect(loaded(cubit).bodyPeriod, BodyPeriod.all);
expect(loaded(cubit).payload, _payload);
expect(loaded(cubit).isRefreshing, isFalse);
await cubit.close();
});
test('403 при перезапросе → hidden', () async {
final cubit = buildCubit(slug: 'c');
await cubit.load();
when(
() => repository.getInsights(
slug: 'c',
bodyPeriod: BodyPeriod.month,
heightCm: 176,
),
).thenThrow(const InsightsForbidden());
await cubit.setBodyPeriod(BodyPeriod.month);
expect(cubit.state, isA<InsightsStateHidden>());
await cubit.close();
});
});
group('панели и серии', () {
test('toggleExpanded раскрывает и сворачивает', () async {
final cubit = buildCubit();
await cubit.load();
cubit.toggleExpanded();
expect(loaded(cubit).isExpanded, isTrue);
cubit.toggleExpanded();
expect(loaded(cubit).isExpanded, isFalse);
await cubit.close();
});
test('setPanel переключает вкладку', () async {
final cubit = buildCubit();
await cubit.load();
cubit.setPanel(InsightsPanel.measures);
expect(loaded(cubit).panel, InsightsPanel.measures);
await cubit.close();
});
test('вкладки КБЖУ недоступны при выключенном флаге', () async {
final cubit = buildCubit();
await cubit.load();
cubit.setPanel(InsightsPanel.daily);
expect(loaded(cubit).panel, InsightsPanel.weight);
expect(cubit.panels, [
InsightsPanel.weight,
InsightsPanel.bmi,
InsightsPanel.measures,
]);
await cubit.close();
});
test('вкладки КБЖУ доступны при включённом флаге', () async {
final cubit = buildCubit(kbjuEnabled: true);
await cubit.load();
cubit.setPanel(InsightsPanel.intra);
expect(loaded(cubit).panel, InsightsPanel.intra);
expect(cubit.panels, InsightsPanel.values);
await cubit.close();
});
test('toggleSeries переключает только выбранную серию', () async {
final cubit = buildCubit();
await cubit.load();
cubit.toggleSeries(InsightsPanel.measures, 1);
expect(loaded(cubit).seriesVisibility.measure, [true, false, true]);
cubit.toggleSeries(InsightsPanel.measures, 1);
expect(loaded(cubit).seriesVisibility.measure, [true, true, true]);
cubit.toggleSeries(InsightsPanel.daily, 0);
expect(loaded(cubit).seriesVisibility.daily, [false, true, true, true]);
expect(loaded(cubit).seriesVisibility.measure, [true, true, true]);
await cubit.close();
});
test(
'toggleSeries игнорирует неверный индекс и вкладку без серий',
() async {
final cubit = buildCubit();
await cubit.load();
final before = loaded(cubit).seriesVisibility;
cubit.toggleSeries(InsightsPanel.measures, 5);
cubit.toggleSeries(InsightsPanel.weight, 0);
expect(loaded(cubit).seriesVisibility, before);
await cubit.close();
},
);
test('toggleSleep', () async {
final cubit = buildCubit();
await cubit.load();
cubit.toggleSleep();
expect(loaded(cubit).showSleep, isFalse);
await cubit.close();
});
});
group('refresh и добавление записей', () {
test('refresh сохраняет вкладку, период, серии и раскрытие', () async {
final cubit = buildCubit();
await cubit.load();
cubit.toggleExpanded();
cubit.setPanel(InsightsPanel.measures);
cubit.toggleSeries(InsightsPanel.measures, 0);
when(
() => repository.getInsights(
slug: null,
bodyPeriod: BodyPeriod.threeMonths,
heightCm: 176,
),
).thenAnswer((_) async => _payload2);
await cubit.refresh();
final state = loaded(cubit);
expect(state.payload, _payload2);
expect(state.panel, InsightsPanel.measures);
expect(state.isExpanded, isTrue);
expect(state.seriesVisibility.measure, [false, true, true]);
expect(state.isRefreshing, isFalse);
await cubit.close();
});
test('addWeight сохраняет и обновляет данные', () async {
when(
() => repository.addWeight(weight: any(named: 'weight')),
).thenAnswer((_) async {});
final cubit = buildCubit(canAdd: true);
await cubit.load();
when(
() => repository.getInsights(
slug: null,
bodyPeriod: BodyPeriod.threeMonths,
heightCm: 176,
),
).thenAnswer((_) async => _payload2);
final isSaved = await cubit.addWeight(weight: 72);
expect(isSaved, isTrue);
verify(() => repository.addWeight(weight: 72)).called(1);
expect(loaded(cubit).payload, _payload2);
await cubit.close();
});
test('addCircumference сохраняет и обновляет данные', () async {
when(
() => repository.addCircumference(
chestCircumference: any(named: 'chestCircumference'),
waistCircumference: any(named: 'waistCircumference'),
hipCircumference: any(named: 'hipCircumference'),
),
).thenAnswer((_) async {});
final cubit = buildCubit(canAdd: true);
await cubit.load();
when(
() => repository.getInsights(
slug: null,
bodyPeriod: BodyPeriod.threeMonths,
heightCm: 176,
),
).thenAnswer((_) async => _payload2);
final isSaved = await cubit.addCircumference(
chestCircumference: 95,
waistCircumference: 80,
hipCircumference: 100,
);
expect(isSaved, isTrue);
verify(
() => repository.addCircumference(
chestCircumference: 95,
waistCircumference: 80,
hipCircumference: 100,
),
).called(1);
expect(loaded(cubit).payload, _payload2);
await cubit.close();
});
test(
'ошибка сохранения не перезагружает данные и возвращает false',
() async {
when(
() => repository.addWeight(weight: any(named: 'weight')),
).thenThrow(Exception('boom'));
final cubit = buildCubit(canAdd: true);
await cubit.load();
clearInteractions(repository);
expect(await cubit.addWeight(weight: 72), isFalse);
verifyNever(
() => repository.getInsights(
slug: any(named: 'slug'),
bodyPeriod: any(named: 'bodyPeriod'),
heightCm: any(named: 'heightCm'),
),
);
expect(loaded(cubit).payload, _payload);
await cubit.close();
},
);
});
}

View File

@@ -0,0 +1,382 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/insights/models/insights_period.dart';
import 'package:eatvio_app/features/insights/presentation/charts/bmi_chart.dart';
import 'package:eatvio_app/features/insights/presentation/charts/measure_chart.dart';
import 'package:eatvio_app/features/insights/presentation/charts/weight_chart.dart';
import 'package:eatvio_app/features/insights/presentation/widgets/insights_card.dart';
import 'package:eatvio_app/features/insights/repositories/insights_repository.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../../../fixtures/doubles/insights_doubles.dart';
void main() {
Widget wrap(Widget child) {
return MaterialApp(
theme: ThemeHelper().themeData(),
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [Locale('ru')],
home: Scaffold(body: SingleChildScrollView(child: child)),
);
}
Future<void> pumpCard(
WidgetTester tester,
FakeInsightsRepository repository, {
String? slug,
bool canAdd = false,
bool kbjuEnabled = false,
bool expand = true,
}) async {
tester.view.physicalSize = const Size(900, 2400);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
wrap(
InsightsCard(
slug: slug,
canAdd: canAdd,
repository: repository,
kbjuEnabled: kbjuEnabled,
),
),
);
await tester.pumpAndSettle();
if (expand &&
find.byKey(const Key('insights_toggle')).evaluate().isNotEmpty) {
await tester.tap(find.byKey(const Key('insights_toggle')));
await tester.pumpAndSettle();
}
}
group('свёрнутое состояние', () {
testWidgets('по умолчанию свёрнут: виден заголовок, графиков нет', (
tester,
) async {
await pumpCard(tester, FakeInsightsRepository(), expand: false);
expect(find.text('Аналитика'), findsOneWidget);
expect(find.text('нажмите, чтобы посмотреть прогресс'), findsOneWidget);
expect(find.byType(WeightChart), findsNothing);
expect(find.byKey(const Key('insights_tab_weight')), findsNothing);
});
testWidgets('тап по заголовку раскрывает и сворачивает блок', (
tester,
) async {
await pumpCard(tester, FakeInsightsRepository(), expand: false);
await tester.tap(find.byKey(const Key('insights_toggle')));
await tester.pumpAndSettle();
expect(find.byType(WeightChart), findsOneWidget);
expect(find.text('вес, замеры и питание'), findsOneWidget);
await tester.tap(find.byKey(const Key('insights_toggle')));
await tester.pumpAndSettle();
expect(find.byType(WeightChart), findsNothing);
});
});
group('вкладки', () {
testWidgets(
'показаны Вес, ИМТ, Замеры; вкладки КБЖУ скрыты при выключенном флаге',
(tester) async {
await pumpCard(tester, FakeInsightsRepository());
expect(find.byKey(const Key('insights_tab_weight')), findsOneWidget);
expect(find.byKey(const Key('insights_tab_bmi')), findsOneWidget);
expect(find.byKey(const Key('insights_tab_measures')), findsOneWidget);
expect(find.byKey(const Key('insights_tab_daily')), findsNothing);
expect(find.byKey(const Key('insights_tab_intra')), findsNothing);
},
);
testWidgets('вкладки переключают панели', (tester) async {
await pumpCard(tester, FakeInsightsRepository());
expect(find.byType(WeightChart), findsOneWidget);
expect(find.byKey(const Key('insights_headline')), findsOneWidget);
await tester.tap(find.byKey(const Key('insights_tab_measures')));
await tester.pumpAndSettle();
expect(find.byType(MeasureChart), findsOneWidget);
expect(find.byType(WeightChart), findsNothing);
await tester.tap(find.byKey(const Key('insights_tab_bmi')));
await tester.pumpAndSettle();
expect(find.byType(BmiChart), findsOneWidget);
expect(find.byType(MeasureChart), findsNothing);
await tester.tap(find.byKey(const Key('insights_tab_weight')));
await tester.pumpAndSettle();
expect(find.byType(WeightChart), findsOneWidget);
});
testWidgets('вкладки КБЖУ видны при включённом флаге', (tester) async {
await pumpCard(tester, FakeInsightsRepository(), kbjuEnabled: true);
expect(find.byKey(const Key('insights_tab_daily')), findsOneWidget);
expect(find.byKey(const Key('insights_tab_intra')), findsOneWidget);
});
});
group('вес', () {
testWidgets('показывает крупное число и текст дельты из payload', (
tester,
) async {
await pumpCard(tester, FakeInsightsRepository());
expect(find.text('73.2'), findsOneWidget);
expect(find.text('кг'), findsWidgets);
expect(find.text('Снизили на 1.3 кг за период'), findsOneWidget);
});
});
group('пилюли периодов', () {
testWidgets(
'по умолчанию запрошены 3 месяца; смена периода перезапрашивает данные',
(tester) async {
final repository = FakeInsightsRepository();
await pumpCard(tester, repository);
expect(
repository.insightsRequests.single.period,
BodyPeriod.threeMonths,
);
await tester.tap(find.byKey(const Key('insights_period_12')));
await tester.pumpAndSettle();
expect(repository.insightsRequests.map((e) => e.period), [
BodyPeriod.threeMonths,
BodyPeriod.year,
]);
await tester.tap(find.byKey(const Key('insights_period_all')));
await tester.pumpAndSettle();
expect(repository.insightsRequests.last.period, BodyPeriod.all);
},
);
testWidgets('повторный тап по активной пилюле не делает запрос', (
tester,
) async {
final repository = FakeInsightsRepository();
await pumpCard(tester, repository);
await tester.tap(find.byKey(const Key('insights_period_3')));
await tester.pumpAndSettle();
expect(repository.insightsRequests, hasLength(1));
});
testWidgets('slug пробрасывается в запросы', (tester) async {
final repository = FakeInsightsRepository();
await pumpCard(tester, repository, slug: 'client');
await tester.tap(find.byKey(const Key('insights_period_1')));
await tester.pumpAndSettle();
expect(repository.insightsRequests.map((e) => e.slug), [
'client',
'client',
]);
});
});
group('кнопка «+»', () {
testWidgets('нет при canAdd = false', (tester) async {
await pumpCard(tester, FakeInsightsRepository());
expect(find.byKey(const Key('insights_fab')), findsNothing);
});
testWidgets('есть на вкладках «Вес» и «Замеры», нет на «ИМТ»', (
tester,
) async {
await pumpCard(tester, FakeInsightsRepository(), canAdd: true);
expect(find.byKey(const Key('insights_fab')), findsOneWidget);
await tester.tap(find.byKey(const Key('insights_tab_bmi')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('insights_fab')), findsNothing);
await tester.tap(find.byKey(const Key('insights_tab_measures')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('insights_fab')), findsOneWidget);
});
testWidgets('нет в свёрнутом состоянии', (tester) async {
await pumpCard(
tester,
FakeInsightsRepository(),
canAdd: true,
expand: false,
);
expect(find.byKey(const Key('insights_fab')), findsNothing);
});
testWidgets(
'сохранение веса отправляет значение и перезапрашивает данные',
(tester) async {
final repository = FakeInsightsRepository();
await pumpCard(tester, repository, canAdd: true);
await tester.tap(find.byKey(const Key('insights_fab')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('add_weight_kilo_picker')), findsOneWidget);
await tester.tap(find.byKey(const Key('add_sheet_save')));
await tester.pumpAndSettle();
// Начальное значение шторки — последний вес из payload (73.2).
expect(repository.addedWeights, [73.2]);
expect(repository.insightsRequests, hasLength(2));
},
);
testWidgets(
'сохранение замеров отправляет значения и перезапрашивает данные',
(tester) async {
final repository = FakeInsightsRepository();
await pumpCard(tester, repository, canAdd: true);
await tester.tap(find.byKey(const Key('insights_tab_measures')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('insights_fab')));
await tester.pumpAndSettle();
expect(
find.byKey(const Key('add_circumference_waist_picker')),
findsOneWidget,
);
await tester.tap(find.byKey(const Key('add_sheet_save')));
await tester.pumpAndSettle();
// Последние значения из payload: грудь 96, талия 80.5 → 81 (округление), бёдра 100.
expect(repository.addedCircumferences, [
(chest: 96, waist: 81, hip: 100),
]);
expect(repository.insightsRequests, hasLength(2));
},
);
});
group('серии замеров', () {
testWidgets('чипы переключают видимость серии', (tester) async {
await pumpCard(tester, FakeInsightsRepository());
await tester.tap(find.byKey(const Key('insights_tab_measures')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('insights_series_0')), findsOneWidget);
expect(find.byKey(const Key('insights_series_1')), findsOneWidget);
expect(find.byKey(const Key('insights_series_2')), findsOneWidget);
expect(
tester
.widget<Opacity>(
find
.ancestor(
of: find.byKey(const Key('insights_series_1')),
matching: find.byType(Opacity),
)
.first,
)
.opacity,
1,
);
await tester.tap(find.byKey(const Key('insights_series_1')));
await tester.pumpAndSettle();
expect(
tester
.widget<Opacity>(
find
.ancestor(
of: find.byKey(const Key('insights_series_1')),
matching: find.byType(Opacity),
)
.first,
)
.opacity,
0.45,
);
});
});
group('ИМТ', () {
testWidgets('без значений показывает только deltaText', (tester) async {
await pumpCard(tester, FakeInsightsRepository());
await tester.tap(find.byKey(const Key('insights_tab_bmi')));
await tester.pumpAndSettle();
expect(find.text('Укажите рост, чтобы посчитать ИМТ.'), findsOneWidget);
expect(find.byKey(const Key('insights_bmi_chart')), findsNothing);
expect(find.byKey(const Key('insights_headline')), findsNothing);
});
testWidgets('со значениями рисует график и подсказку', (tester) async {
final payload = loadInsightsPayloadFixture().copyWith.bmi(
labels: ['01.11', '09.11'],
values: [26.1, 24.2],
last: 24.2,
delta: -1.9,
headline: '24.2',
category: 'норма',
deltaText: 'ИМТ ниже на 1.9 за 3 месяца · норма',
hint: 'Считаем при росте 176 см.',
);
await pumpCard(tester, FakeInsightsRepository(payload: payload));
await tester.tap(find.byKey(const Key('insights_tab_bmi')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('insights_bmi_chart')), findsOneWidget);
expect(find.byKey(const Key('insights_bmi_hint')), findsOneWidget);
expect(find.text('ИМТ ниже на 1.9 за 3 месяца · норма'), findsOneWidget);
});
});
group('скрытие и ошибки', () {
testWidgets('403 → блок скрыт целиком', (tester) async {
await pumpCard(
tester,
FakeInsightsRepository(error: const InsightsForbidden()),
slug: 'client',
expand: false,
);
expect(find.byKey(const Key('insights_card')), findsNothing);
expect(find.text('Аналитика'), findsNothing);
});
testWidgets(
'ошибка загрузки показывает кнопку «Повторить», повтор грузит данные',
(tester) async {
final repository = FakeInsightsRepository(error: Exception('boom'));
await pumpCard(tester, repository, expand: false);
expect(find.text('Не удалось загрузить аналитику'), findsOneWidget);
repository.error = null;
await tester.tap(find.byKey(const Key('insights_retry')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('insights_toggle')), findsOneWidget);
expect(find.text('Не удалось загрузить аналитику'), findsNothing);
},
);
});
}

View File

@@ -0,0 +1,453 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
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/presentation/charts/daily_kbju_chart.dart';
import 'package:eatvio_app/features/insights/presentation/charts/intra_day_chart.dart';
import 'package:eatvio_app/features/insights/presentation/widgets/insights_card.dart';
import 'package:eatvio_app/features/insights/presentation/widgets/intra_date_nav.dart';
import 'package:eatvio_app/features/insights/presentation/widgets/intra_legend.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
import '../../../../fixtures/doubles/insights_doubles.dart';
void main() {
Widget wrap(Widget child) {
return MaterialApp(
theme: ThemeHelper().themeData(),
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [Locale('ru')],
home: Scaffold(body: SingleChildScrollView(child: child)),
);
}
Future<void> pumpKbjuCard(
WidgetTester tester,
FakeInsightsRepository repository,
String tabKey,
) async {
tester.view.physicalSize = const Size(900, 2600);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
wrap(InsightsCard(repository: repository, kbjuEnabled: true)),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('insights_toggle')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(Key(tabKey)));
await tester.pumpAndSettle();
}
group('КБЖУ по дням', () {
testWidgets('рисует график, шапку со средним и 4 чипа серий', (
tester,
) async {
await pumpKbjuCard(
tester,
FakeInsightsRepository(),
'insights_tab_daily',
);
expect(find.byType(DailyKbjuChart), findsOneWidget);
expect(find.text('1930'), findsOneWidget);
expect(find.text('ккал в среднем'), findsOneWidget);
expect(find.text('Калораж вырос на 5% за период'), findsOneWidget);
for (var i = 0; i < 4; i++) {
expect(find.byKey(Key('insights_series_$i')), findsOneWidget);
}
expect(find.byKey(const Key('insights_series_4')), findsNothing);
});
testWidgets('чипы скрывают серии', (tester) async {
await pumpKbjuCard(
tester,
FakeInsightsRepository(),
'insights_tab_daily',
);
SfCartesianChart chart() => tester.widget<SfCartesianChart>(
find.byKey(const Key('insights_daily_chart')),
);
expect(chart().series, hasLength(4));
await tester.tap(find.byKey(const Key('insights_series_1')));
await tester.pumpAndSettle();
expect(chart().series, hasLength(3));
});
testWidgets('пилюли периода активны и перезапрашивают данные', (
tester,
) async {
final repository = FakeInsightsRepository();
await pumpKbjuCard(tester, repository, 'insights_tab_daily');
repository.serverRequests.clear();
await tester.tap(find.byKey(const Key('insights_period_30')));
await tester.pumpAndSettle();
expect(repository.serverRequests.single.dailyPeriod, DailyPeriod.month);
expect(
repository.serverRequests.single.bodyPeriod,
BodyPeriod.threeMonths,
);
});
testWidgets('без daily показывает заглушку', (tester) async {
final payload = loadInsightsPayloadFixture().copyWith(daily: null);
await pumpKbjuCard(
tester,
FakeInsightsRepository(payload: payload),
'insights_tab_daily',
);
expect(find.byType(DailyKbjuChart), findsNothing);
expect(find.text('Недостаточно данных'), findsOneWidget);
});
testWidgets('пустой daily показывает заглушку вместо графика', (
tester,
) async {
await pumpKbjuCard(
tester,
FakeInsightsRepository(
payload: loadInsightsPayloadFixture('insights_payload_minimal.json'),
),
'insights_tab_daily',
);
expect(find.byKey(const Key('insights_daily_chart')), findsNothing);
expect(find.text('Недостаточно данных'), findsWidgets);
});
});
group('В течение дня', () {
testWidgets('рисует график, навигацию по дням, легенду и подсказку', (
tester,
) async {
await pumpKbjuCard(
tester,
FakeInsightsRepository(),
'insights_tab_intra',
);
expect(find.byType(IntraDayChart), findsOneWidget);
expect(find.byType(IntraDateNav), findsOneWidget);
expect(find.text('Сегодня'), findsOneWidget);
expect(find.text('Подъём в 07:30'), findsOneWidget);
expect(find.text('Отход ко сну в 23:00'), findsOneWidget);
expect(find.text('Затемнение — время сна'), findsOneWidget);
expect(find.byKey(const Key('insights_intra_hint')), findsOneWidget);
for (var i = 0; i < 6; i++) {
expect(find.byKey(Key('insights_series_$i')), findsOneWidget);
}
});
testWidgets(
'на сегодняшнем дне «следующий день» отключён, «предыдущий» нет',
(tester) async {
await pumpKbjuCard(
tester,
FakeInsightsRepository(),
'insights_tab_intra',
);
IconButton buttonIn(String key) => tester.widget<IconButton>(
find.descendant(
of: find.byKey(Key(key)),
matching: find.byType(IconButton),
),
);
expect(buttonIn('insights_intra_next').onPressed, isNull);
expect(buttonIn('insights_intra_prev').onPressed, isNotNull);
},
);
testWidgets('«предыдущий день» запрашивает только intra и меняет дату', (
tester,
) async {
final repository = FakeInsightsRepository();
repository.intraByDate['2026-11-08'] = loadInsightsPayloadFixture().intra!
.copyWith(date: '2026-11-08', dateLabel: '8 ноября', isToday: false);
await pumpKbjuCard(tester, repository, 'insights_tab_intra');
repository.serverRequests.clear();
await tester.tap(find.byKey(const Key('insights_intra_prev')));
await tester.pumpAndSettle();
expect(repository.intraRequests, [(slug: null, date: '2026-11-08')]);
expect(repository.serverRequests, isEmpty);
expect(find.text('8 ноября'), findsOneWidget);
expect(find.text('Сегодня'), findsNothing);
});
testWidgets('с прошедшего дня можно вернуться «следующим днём»', (
tester,
) async {
final repository = FakeInsightsRepository();
final today = loadInsightsPayloadFixture().intra!;
repository.intraByDate['2026-11-08'] = today.copyWith(
date: '2026-11-08',
dateLabel: '8 ноября',
isToday: false,
);
repository.intraByDate['2026-11-09'] = today;
await pumpKbjuCard(tester, repository, 'insights_tab_intra');
await tester.tap(find.byKey(const Key('insights_intra_prev')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('insights_intra_next')));
await tester.pumpAndSettle();
expect(repository.intraRequests.last.date, '2026-11-09');
expect(find.text('Сегодня'), findsOneWidget);
});
testWidgets('чип «Сон и подъём» убирает затемнение и легенду не трогает', (
tester,
) async {
await pumpKbjuCard(
tester,
FakeInsightsRepository(),
'insights_tab_intra',
);
NumericAxis xAxis() =>
tester
.widget<SfCartesianChart>(
find.byKey(const Key('insights_intra_chart')),
)
.primaryXAxis
as NumericAxis;
// wake + sleep: две полосы затемнения и две линии.
expect(xAxis().plotBands, hasLength(4));
await tester.tap(find.byKey(const Key('insights_series_5')));
await tester.pumpAndSettle();
expect(xAxis().plotBands, isEmpty);
expect(find.text('Затемнение — время сна'), findsOneWidget);
});
testWidgets('чипы сытости и настроения скрывают линии', (tester) async {
await pumpKbjuCard(
tester,
FakeInsightsRepository(),
'insights_tab_intra',
);
int seriesCount() => tester
.widget<SfCartesianChart>(
find.byKey(const Key('insights_intra_chart')),
)
.series
.length;
// 3 столбика + сытость + настроение.
expect(seriesCount(), 5);
await tester.tap(find.byKey(const Key('insights_series_3')));
await tester.pumpAndSettle();
expect(seriesCount(), 4);
await tester.tap(find.byKey(const Key('insights_series_4')));
await tester.pumpAndSettle();
expect(seriesCount(), 3);
});
testWidgets('пустые линии не создают серий (без экстраполяции)', (
tester,
) async {
final intra = loadInsightsPayloadFixture().intra!.copyWith(
satiety: const [],
mood: const [],
);
final payload = loadInsightsPayloadFixture().copyWith(intra: intra);
await pumpKbjuCard(
tester,
FakeInsightsRepository(payload: payload),
'insights_tab_intra',
);
final chart = tester.widget<SfCartesianChart>(
find.byKey(const Key('insights_intra_chart')),
);
expect(chart.series, hasLength(3));
});
testWidgets('без wake/sleep затемнения нет', (tester) async {
const intra = IntraChartModel(
bars: [IntraBarModel(x: 12, p: 100, f: 50, c: 200)],
date: '2026-11-09',
maxDate: '2026-11-09',
dateLabel: 'Сегодня',
isToday: true,
);
final payload = loadInsightsPayloadFixture().copyWith(intra: intra);
await pumpKbjuCard(
tester,
FakeInsightsRepository(payload: payload),
'insights_tab_intra',
);
final xAxis =
tester
.widget<SfCartesianChart>(
find.byKey(const Key('insights_intra_chart')),
)
.primaryXAxis
as NumericAxis;
expect(xAxis.plotBands, isEmpty);
expect(find.byKey(const Key('insights_legend_wake')), findsNothing);
expect(find.byKey(const Key('insights_legend_sleep')), findsNothing);
expect(find.byType(IntraLegend), findsOneWidget);
});
testWidgets('день только со сном рисует затемнение, без заглушки', (
tester,
) async {
final intra = loadInsightsPayloadFixture().intra!.copyWith(
bars: const [],
satiety: const [],
mood: const [],
);
await pumpKbjuCard(
tester,
FakeInsightsRepository(
payload: loadInsightsPayloadFixture().copyWith(intra: intra),
),
'insights_tab_intra',
);
expect(find.byKey(const Key('insights_intra_chart')), findsOneWidget);
expect(find.text('Недостаточно данных'), findsNothing);
final xAxis =
tester
.widget<SfCartesianChart>(
find.byKey(const Key('insights_intra_chart')),
)
.primaryXAxis
as NumericAxis;
expect(xAxis.plotBands, isNotEmpty);
});
testWidgets('пустой день показывает заглушку', (tester) async {
await pumpKbjuCard(
tester,
FakeInsightsRepository(
payload: loadInsightsPayloadFixture('insights_payload_minimal.json'),
),
'insights_tab_intra',
);
expect(find.byKey(const Key('insights_intra_chart')), findsNothing);
expect(find.text('Недостаточно данных'), findsOneWidget);
});
});
group('IntraDateNav', () {
const model = IntraChartModel(
date: '2026-11-08',
maxDate: '2026-11-09',
dateLabel: '8 ноября',
isToday: false,
);
testWidgets('вызывает колбэки предыдущего и следующего дня', (
tester,
) async {
var prev = 0;
var next = 0;
await tester.pumpWidget(
wrap(
IntraDateNav(
model: model,
onPreviousDay: () => prev++,
onNextDay: () => next++,
onDatePicked: (_) {},
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('insights_intra_prev')));
await tester.tap(find.byKey(const Key('insights_intra_next')));
expect(prev, 1);
expect(next, 1);
expect(find.text('8 ноября'), findsOneWidget);
});
testWidgets('«следующий день» отключён, когда выбран сегодняшний день', (
tester,
) async {
var next = 0;
await tester.pumpWidget(
wrap(
IntraDateNav(
model: model.copyWith(isToday: true, dateLabel: 'Сегодня'),
onPreviousDay: () {},
onNextDay: () => next++,
),
),
);
await tester.pumpAndSettle();
await tester.tap(
find.byKey(const Key('insights_intra_next')),
warnIfMissed: false,
);
expect(next, 0);
});
testWidgets(
'выбор даты: календарь ограничен maxDate и возвращает выбранный день',
(tester) async {
DateTime? picked;
await tester.pumpWidget(
wrap(
IntraDateNav(
model: model,
onPreviousDay: () {},
onNextDay: () {},
onDatePicked: (date) => picked = date,
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('insights_intra_pick')));
await tester.pumpAndSettle();
final dialog = tester.widget<CalendarDatePicker>(
find.byType(CalendarDatePicker),
);
expect(dialog.lastDate, DateTime(2026, 11, 9));
expect(dialog.initialDate, DateTime(2026, 11, 8));
await tester.tap(find.text('5'));
await tester.tap(
find.text('OK').evaluate().isNotEmpty
? find.text('OK')
: find.text('ОК'),
);
await tester.pumpAndSettle();
expect(picked, DateTime(2026, 11, 5));
},
);
});
}

View File

@@ -0,0 +1,341 @@
import 'package:dio/dio.dart';
import 'package:eatvio_app/features/insights/domain/insights_text_builder.dart';
import 'package:eatvio_app/features/insights/models/insights_period.dart';
import 'package:eatvio_app/features/insights/models/insights_response_model.dart';
import 'package:eatvio_app/features/insights/repositories/insights_repository.dart';
import 'package:eatvio_app/features/insights/services/insights_service.dart';
import 'package:eatvio_app/features/profile/models/circumference_model.dart';
import 'package:eatvio_app/features/profile/models/profile_model.dart';
import 'package:eatvio_app/features/profile/models/weight_model.dart';
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import '../../../fixtures/doubles/insights_doubles.dart';
class _MockProfileRepository extends Mock implements ProfileRepository {}
class _MockInsightsService extends Mock implements InsightsService {}
ProfileDetailsModel _details({int height = 176}) => ProfileDetailsModel(
firstName: 'A',
lastName: 'B',
birthdate: '1990-01-01',
gender: 'male',
country: 'RU',
city: 'Moscow',
lang: 'ru',
weight: 70,
height: height,
chestCircumference: 90,
waistCircumference: 80,
hipCircumference: 95,
bloodPressureUp: 120,
bloodPressureDown: 80,
hasHypo: false,
hasHyper: false,
aboutAlergy: '',
aboutTakingPils: '',
aboutSportHobbies: '',
favoriteFoods: '',
unfavoriteFoods: '',
additionalInfo: '',
isMoodFillable: false,
isBedtimeFillable: false,
activityCoefficient: 1.2,
);
DioException _dio(int status) => DioException(
requestOptions: RequestOptions(path: '/x'),
response: Response(
requestOptions: RequestOptions(path: '/x'),
statusCode: status,
),
);
void main() {
late _MockProfileRepository profileRepository;
late _MockInsightsService insightsService;
late InsightsRepository repository;
final date1 = DateTime(2026, 11, 1, 12);
final date2 = DateTime(2026, 11, 9, 12);
final weights = [
WeightModel(
id: 1,
userId: 1,
weight: 75,
createdAt: date1,
updatedAt: date1,
bmi: 24,
),
WeightModel(
id: 2,
userId: 1,
weight: 73.5,
createdAt: date2,
updatedAt: date2,
bmi: 23.5,
),
];
final circumferences = [
CircumferenceModel(
id: 1,
userId: 1,
chestCircumference: 95,
waistCircumference: 82,
hipCircumference: 100,
createdAt: date1,
updatedAt: date1,
),
];
setUp(() async {
final s = await S.load(const Locale('ru'));
profileRepository = _MockProfileRepository();
insightsService = _MockInsightsService();
repository = InsightsRepository(
profileRepository: profileRepository,
insightsService: insightsService,
textBuilderFactory: () => InsightsTextBuilder(s),
);
});
group('getInsights', () {
test('собирает payload из веса и замеров; daily/intra == null', () async {
when(
() => profileRepository.getWeight(period: '3', slug: null),
).thenAnswer((_) async => weights);
when(
() => profileRepository.getCircumferences(period: '3', slug: null),
).thenAnswer((_) async => circumferences);
final payload = await repository.getInsights(
bodyPeriod: BodyPeriod.threeMonths,
heightCm: 176,
);
expect(payload.weight.values, [75, 73.5]);
expect(payload.weight.deltaText, 'Снизили на 1.5 кг за 3 месяца');
expect(payload.bmi.values, [24, 23.5]);
expect(payload.measure.waist, [82]);
expect(payload.daily, isNull);
expect(payload.intra, isNull);
});
test('пробрасывает slug и значение периода', () async {
when(
() => profileRepository.getWeight(period: 'all', slug: 'client'),
).thenAnswer((_) async => weights);
when(
() =>
profileRepository.getCircumferences(period: 'all', slug: 'client'),
).thenAnswer((_) async => circumferences);
await repository.getInsights(slug: 'client', bodyPeriod: BodyPeriod.all);
verify(
() => profileRepository.getWeight(period: 'all', slug: 'client'),
).called(1);
verify(
() =>
profileRepository.getCircumferences(period: 'all', slug: 'client'),
).called(1);
});
test('403 → InsightsForbidden', () async {
when(
() => profileRepository.getWeight(period: '3', slug: 'client'),
).thenThrow(_dio(403));
when(
() => profileRepository.getCircumferences(period: '3', slug: 'client'),
).thenAnswer((_) async => circumferences);
expect(
repository.getInsights(
slug: 'client',
bodyPeriod: BodyPeriod.threeMonths,
),
throwsA(isA<InsightsForbidden>()),
);
});
test('прочие ошибки пробрасываются как есть', () async {
when(
() => profileRepository.getWeight(period: '3', slug: null),
).thenThrow(_dio(500));
when(
() => profileRepository.getCircumferences(period: '3', slug: null),
).thenAnswer((_) async => circumferences);
expect(
repository.getInsights(bodyPeriod: BodyPeriod.threeMonths),
throwsA(isA<DioException>()),
);
});
});
group('getHeightCm', () {
test('свой профиль', () async {
when(
() => profileRepository.getMyProfileDetails(),
).thenAnswer((_) async => _details());
expect(await repository.getHeightCm(), 176);
});
test('профиль клиента по slug', () async {
when(
() => profileRepository.getProfileDetailsBySlug('client'),
).thenAnswer((_) async => _details(height: 168));
expect(await repository.getHeightCm(slug: 'client'), 168);
});
test('нулевой рост → null', () async {
when(
() => profileRepository.getMyProfileDetails(),
).thenAnswer((_) async => _details(height: 0));
expect(await repository.getHeightCm(), isNull);
});
test('ошибка не 403 → null', () async {
when(() => profileRepository.getMyProfileDetails()).thenThrow(_dio(500));
expect(await repository.getHeightCm(), isNull);
});
test('403 → InsightsForbidden', () async {
when(
() => profileRepository.getProfileDetailsBySlug('client'),
).thenThrow(_dio(403));
expect(
repository.getHeightCm(slug: 'client'),
throwsA(isA<InsightsForbidden>()),
);
});
});
group('fetchInsights (сервер)', () {
final response = InsightsResponseModel(data: loadInsightsPayloadFixture());
test('свой профиль: /insights с периодами и датой', () async {
when(
() => insightsService.getInsights(
bodyPeriod: '6',
dailyPeriod: '30',
intraDate: '2026-11-08',
),
).thenAnswer((_) async => response);
final payload = await repository.fetchInsights(
bodyPeriod: BodyPeriod.sixMonths,
dailyPeriod: DailyPeriod.month,
intraDate: '2026-11-08',
);
expect(payload, response.data);
verifyNever(
() => insightsService.getInsightsBySlug(
slug: any(named: 'slug'),
bodyPeriod: any(named: 'bodyPeriod'),
dailyPeriod: any(named: 'dailyPeriod'),
intraDate: any(named: 'intraDate'),
),
);
});
test('чужой профиль: /insights/{slug}', () async {
when(
() => insightsService.getInsightsBySlug(
slug: 'client',
bodyPeriod: 'all',
dailyPeriod: 'all',
intraDate: null,
),
).thenAnswer((_) async => response);
final payload = await repository.fetchInsights(
slug: 'client',
bodyPeriod: BodyPeriod.all,
dailyPeriod: DailyPeriod.all,
);
expect(payload, response.data);
});
test('403 → InsightsForbidden', () {
when(
() => insightsService.getInsightsBySlug(
slug: 'client',
bodyPeriod: '3',
dailyPeriod: '14',
intraDate: null,
),
).thenThrow(_dio(403));
expect(
repository.fetchInsights(
slug: 'client',
bodyPeriod: BodyPeriod.threeMonths,
dailyPeriod: DailyPeriod.twoWeeks,
),
throwsA(isA<InsightsForbidden>()),
);
});
test('422 пробрасывается как DioException', () {
when(
() => insightsService.getInsights(
bodyPeriod: '3',
dailyPeriod: '14',
intraDate: null,
),
).thenThrow(_dio(422));
expect(
repository.fetchInsights(
bodyPeriod: BodyPeriod.threeMonths,
dailyPeriod: DailyPeriod.twoWeeks,
),
throwsA(isA<DioException>()),
);
});
});
group('fetchIntra (сервер)', () {
final intra = loadInsightsPayloadFixture().intra!;
final response = InsightsIntraResponseModel(
data: InsightsIntraDataModel(intra: intra),
);
test('свой профиль: /insights/intra', () async {
when(
() => insightsService.getIntra(intraDate: '2026-11-09'),
).thenAnswer((_) async => response);
expect(await repository.fetchIntra(intraDate: '2026-11-09'), intra);
});
test('чужой профиль: /insights/{slug}/intra', () async {
when(
() => insightsService.getIntraBySlug(slug: 'client', intraDate: null),
).thenAnswer((_) async => response);
expect(await repository.fetchIntra(slug: 'client'), intra);
});
test('403 → InsightsForbidden', () {
when(
() => insightsService.getIntra(intraDate: null),
).thenThrow(_dio(403));
expect(repository.fetchIntra(), throwsA(isA<InsightsForbidden>()));
});
});
}

View File

@@ -1,3 +1,4 @@
import 'package:eatvio_app/features/profile/models/circumference_model.dart';
import 'package:eatvio_app/features/profile/models/weight_model.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -42,6 +43,51 @@ void main() {
expect(json['created_at'], isA<String>());
expect(json['updated_at'], isA<String>());
});
Map<String, dynamic> json({Object? weight = 72.3, Object? bmi = 22.4}) => {
'id': 1,
'user_id': 2,
'weight': weight,
'created_at': '2026-11-01T10:00:00.000000Z',
'updated_at': '2026-11-01T10:00:00.000000Z',
'bmi': bmi,
};
test('парсит дробный weight', () {
final model = WeightModel.fromJson(json());
expect(model.weight, 72.3);
expect(model.bmi, 22.4);
});
test('парсит целый weight как double', () {
final model = WeightModel.fromJson(json(weight: 72));
expect(model.weight, 72.0);
});
test('допускает bmi: null (рост не указан)', () {
final model = WeightModel.fromJson(json(bmi: null));
expect(model.bmi, isNull);
});
});
group('CircumferenceModel', () {
test('парсит целые и дробные значения (прореженные средние)', () {
final model = CircumferenceModel.fromJson({
'id': 1,
'user_id': 2,
'chest_circumference': 95,
'waist_circumference': 80.5,
'hip_circumference': 100,
'created_at': '2026-11-01T10:00:00.000000Z',
'updated_at': '2026-11-01T10:00:00.000000Z',
});
expect(model.chestCircumference, 95.0);
expect(model.waistCircumference, 80.5);
expect(model.hipCircumference, 100.0);
});
});
}

View File

@@ -4,10 +4,11 @@ import 'package:eatvio_app/core/locator_service.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/chat/repositories/chat_repository.dart';
import 'package:eatvio_app/features/consultant/become_consultant/repositories/consultant_repository.dart';
import 'package:eatvio_app/features/profile/models/circumference_model.dart';
import 'package:eatvio_app/features/insights/presentation/widgets/insights_card.dart';
import 'package:eatvio_app/features/insights/repositories/insights_repository.dart';
import 'package:eatvio_app/features/profile/models/profile_model.dart';
import 'package:eatvio_app/features/profile/models/weight_model.dart';
import 'package:eatvio_app/features/profile/presentation/bloc/plans_cubit/plans_cubit.dart' as profile_plans;
import 'package:eatvio_app/features/profile/presentation/bloc/plans_cubit/plans_cubit.dart'
as profile_plans;
import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart';
import 'package:eatvio_app/features/profile/presentation/pages/profile_screen.dart';
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
@@ -21,9 +22,15 @@ import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:network_image_mock/network_image_mock.dart';
import '../../../../fixtures/doubles/insights_doubles.dart';
import 'profile_screen_smoke_test.mocks.dart';
@GenerateNiceMocks([MockSpec<ProfileRepository>(), MockSpec<ChatRepository>(), MockSpec<ConsultantRepository>(), MockSpec<PlansRepository>()])
@GenerateNiceMocks([
MockSpec<ProfileRepository>(),
MockSpec<ChatRepository>(),
MockSpec<ConsultantRepository>(),
MockSpec<PlansRepository>(),
])
void main() {
group('ProfileScreen smoke', () {
late MockProfileRepository profileRepository;
@@ -32,12 +39,18 @@ void main() {
late MockPlansRepository plansRepository;
setUpAll(() async {
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
dotenv.loadFromString(
envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost',
);
});
setUp(() async {
await sl.reset();
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
sl.registerLazySingleton<AppConfig>(
() =>
AppConfig(buildType: AppBuildType.tests)
..setBaseUrl('http://localhost'),
);
profileRepository = MockProfileRepository();
chatRepository = MockChatRepository();
@@ -45,12 +58,25 @@ void main() {
plansRepository = MockPlansRepository();
sl.registerLazySingleton<ProfileRepository>(() => profileRepository);
sl.registerLazySingleton<InsightsRepository>(
() => FakeInsightsRepository(),
);
sl.registerLazySingleton<ChatRepository>(() => chatRepository);
sl.registerLazySingleton<ConsultantRepository>(() => consultantRepository);
sl.registerLazySingleton<ConsultantRepository>(
() => consultantRepository,
);
sl.registerLazySingleton<PlansRepository>(() => plansRepository);
sl.registerFactory<ProfileCubit>(() => ProfileCubit(profileRepository: sl(), chatRepository: sl(), consultantRepository: sl()));
sl.registerFactory<profile_plans.PlansCubit>(() => profile_plans.PlansCubit(plansRepository: sl()));
sl.registerFactory<ProfileCubit>(
() => ProfileCubit(
profileRepository: sl(),
chatRepository: sl(),
consultantRepository: sl(),
),
);
sl.registerFactory<profile_plans.PlansCubit>(
() => profile_plans.PlansCubit(plansRepository: sl()),
);
});
Widget wrap(Widget child) {
@@ -115,10 +141,12 @@ void main() {
);
when(profileRepository.getMyProfile()).thenAnswer((_) async => profile);
when(profileRepository.getMyProfileDetails()).thenAnswer((_) async => profileDetails);
when(profileRepository.getBlogPostsByAuthorSlug(slug: anyNamed('slug'))).thenAnswer((_) async => []);
when(profileRepository.getWeight(period: anyNamed('period'))).thenAnswer((_) async => <WeightModel>[]);
when(profileRepository.getCircumferences(period: anyNamed('period'))).thenAnswer((_) async => <CircumferenceModel>[]);
when(
profileRepository.getMyProfileDetails(),
).thenAnswer((_) async => profileDetails);
when(
profileRepository.getBlogPostsByAuthorSlug(slug: anyNamed('slug')),
).thenAnswer((_) async => []);
await mockNetworkImagesFor(() async {
await tester.pumpWidget(wrap(const ProfileScreen()));
@@ -129,8 +157,12 @@ void main() {
});
testWidgets('renders error state', (tester) async {
when(profileRepository.getMyProfile()).thenThrow(Exception('Error loading profile'));
when(profileRepository.getMyProfileDetails()).thenThrow(Exception('Error'));
when(
profileRepository.getMyProfile(),
).thenThrow(Exception('Error loading profile'));
when(
profileRepository.getMyProfileDetails(),
).thenThrow(Exception('Error'));
await tester.pumpWidget(wrap(const ProfileScreen()));
await tester.pumpAndSettle();
@@ -185,13 +217,19 @@ void main() {
activityCoefficient: 1.5,
);
when(profileRepository.getProfileBySlug(any)).thenAnswer((_) async => profile);
when(
profileRepository.getProfileBySlug(any),
).thenAnswer((_) async => profile);
when(profileRepository.getMyProfile()).thenAnswer((_) async => profile);
when(profileRepository.getMyProfileDetails()).thenAnswer((_) async => profileDetails);
when(profileRepository.getProfileDetailsBySlug(any)).thenAnswer((_) async => profileDetails);
when(profileRepository.getBlogPostsByAuthorSlug(slug: anyNamed('slug'))).thenAnswer((_) async => []);
when(profileRepository.getWeight(period: anyNamed('period'))).thenAnswer((_) async => <WeightModel>[]);
when(profileRepository.getCircumferences(period: anyNamed('period'))).thenAnswer((_) async => <CircumferenceModel>[]);
when(
profileRepository.getMyProfileDetails(),
).thenAnswer((_) async => profileDetails);
when(
profileRepository.getProfileDetailsBySlug(any),
).thenAnswer((_) async => profileDetails);
when(
profileRepository.getBlogPostsByAuthorSlug(slug: anyNamed('slug')),
).thenAnswer((_) async => []);
await mockNetworkImagesFor(() async {
await tester.pumpWidget(wrap(const ProfileScreen(slug: 'test-user')));
@@ -199,7 +237,159 @@ void main() {
});
expect(find.byType(ProfileScreen), findsOneWidget);
expect(find.text('Пользователь ограничил доступ к своей странице'), findsOneWidget);
expect(
find.text('Пользователь ограничил доступ к своей странице'),
findsOneWidget,
);
});
group('аналитика (InsightsCard)', () {
ProfileModel profileOf(
String slug, {
bool blockedByMe = false,
bool blockedByAuthor = false,
}) => ProfileModel(
id: 1,
name: 'Test User',
email: 'test@example.com',
phoneConfirmationState: 'confirmed',
slug: slug,
isPublicProfile: true,
isBlockedByMe: blockedByMe,
isBlockedByAuthor: blockedByAuthor,
isBlockedByUser: false,
isEntitySubscribedByMe: false,
profilePhotoUrl: '',
roles: const [],
badges: const [],
subscriptions: const [],
subscribers: const [],
);
const details = ProfileDetailsModel(
firstName: 'Test',
lastName: 'User',
birthdate: '1990-01-01',
gender: 'male',
country: 'Russia',
city: 'Moscow',
lang: 'ru',
weight: 70.0,
height: 175,
chestCircumference: 100,
waistCircumference: 80,
hipCircumference: 90,
bloodPressureUp: 120,
bloodPressureDown: 80,
hasHypo: false,
hasHyper: false,
aboutAlergy: '',
aboutTakingPils: '',
aboutSportHobbies: '',
favoriteFoods: '',
unfavoriteFoods: '',
additionalInfo: '',
isMoodFillable: true,
isBedtimeFillable: true,
activityCoefficient: 1.5,
);
Future<FakeInsightsRepository> pumpProfile(
WidgetTester tester, {
required ProfileModel viewed,
String? slug,
Object? insightsError,
}) async {
final insights = FakeInsightsRepository(error: insightsError);
sl.unregister<InsightsRepository>();
sl.registerLazySingleton<InsightsRepository>(() => insights);
when(
profileRepository.getProfileBySlug(any),
).thenAnswer((_) async => viewed);
when(
profileRepository.getMyProfile(),
).thenAnswer((_) async => profileOf('me'));
when(
profileRepository.getMyProfileDetails(),
).thenAnswer((_) async => details);
when(
profileRepository.getProfileDetailsBySlug(any),
).thenAnswer((_) async => details);
when(
profileRepository.getBlogPostsByAuthorSlug(slug: anyNamed('slug')),
).thenAnswer((_) async => []);
await mockNetworkImagesFor(() async {
await tester.pumpWidget(wrap(ProfileScreen(slug: slug)));
await tester.pumpAndSettle();
});
return insights;
}
testWidgets('собственный профиль: свои данные и кнопка добавления', (
tester,
) async {
final insights = await pumpProfile(tester, viewed: profileOf('me'));
final card = tester.widget<InsightsCard>(find.byType(InsightsCard));
expect(card.slug, isNull);
expect(card.canAdd, isTrue);
expect(insights.serverRequests.single.slug, isNull);
});
testWidgets(
'чужой профиль (консультант → клиент): данные по slug без кнопки добавления',
(tester) async {
final insights = await pumpProfile(
tester,
viewed: profileOf('client'),
slug: 'client',
);
final card = tester.widget<InsightsCard>(find.byType(InsightsCard));
expect(card.slug, 'client');
expect(card.canAdd, isFalse);
expect(insights.serverRequests.single.slug, 'client');
expect(find.byKey(const Key('insights_card')), findsOneWidget);
},
);
testWidgets('чужой профиль: 403 скрывает блок', (tester) async {
await pumpProfile(
tester,
viewed: profileOf('client'),
slug: 'client',
insightsError: const InsightsForbidden(),
);
expect(find.byKey(const Key('insights_card')), findsNothing);
});
testWidgets(
'профиль, заблокированный мной, не показывает аналитику и не запрашивает её',
(tester) async {
final insights = await pumpProfile(
tester,
viewed: profileOf('client', blockedByMe: true),
slug: 'client',
);
expect(find.byType(InsightsCard), findsNothing);
expect(insights.serverRequests, isEmpty);
},
);
testWidgets('профиль, ограничивший доступ, не показывает аналитику', (
tester,
) async {
final insights = await pumpProfile(
tester,
viewed: profileOf('client', blockedByAuthor: true),
slug: 'client',
);
expect(find.byType(InsightsCard), findsNothing);
expect(insights.serverRequests, isEmpty);
});
});
});
}

View File

@@ -1,47 +0,0 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/profile/models/circumference_model.dart';
import 'package:eatvio_app/features/profile/presentation/widgets/circumference_chart_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:intl/date_symbol_data_local.dart';
void main() {
group('CircumferenceChartWidget smoke', () {
setUpAll(() async {
await initializeDateFormatting('ru', null);
});
Widget wrap(Widget child) {
return MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(body: child),
);
}
testWidgets('renders circumference chart widget with empty points', (tester) async {
await tester.pumpWidget(wrap(const CircumferenceChartWidget(circumferencePoints: [])));
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
expect(find.byType(CircumferenceChartWidget), findsOneWidget);
});
testWidgets('renders circumference chart widget with points', (tester) async {
final points = [
CircumferenceModel(
id: 1,
userId: 1,
chestCircumference: 90,
waistCircumference: 80,
hipCircumference: 95,
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
),
];
await tester.pumpWidget(wrap(CircumferenceChartWidget(circumferencePoints: points)));
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
expect(find.byType(CircumferenceChartWidget), findsOneWidget);
});
});
}

View File

@@ -1,132 +0,0 @@
import 'package:eatvio_app/core/app_config.dart';
import 'package:eatvio_app/core/app_initializer.dart';
import 'package:eatvio_app/core/locator_service.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/profile/models/weight_model.dart';
import 'package:eatvio_app/features/profile/presentation/widgets/imt_chart_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_portal/flutter_portal.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:intl/date_symbol_data_local.dart';
void main() {
group('ImtChartWidget', () {
setUp(() async {
await sl.reset();
await initializeDateFormatting('ru', null);
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
});
Widget createTestWidget(Widget child) {
return MaterialApp(
theme: ThemeHelper().themeData(),
home: Portal(
child: Scaffold(body: SingleChildScrollView(child: child)),
),
);
}
testWidgets('should display chart with empty weight points', (WidgetTester tester) async {
// Arrange
const widget = ImtChartWidget(weightPoints: []);
// Act
await tester.pumpWidget(createTestWidget(widget));
await tester.pump();
await tester.pump(const Duration(seconds: 1));
// Assert
expect(find.byType(ImtChartWidget), findsOneWidget);
});
testWidgets('should display chart with single weight point', (WidgetTester tester) async {
// Arrange
final weightPoints = [
WeightModel(
id: 1,
userId: 1,
weight: 70,
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
bmi: 23.5,
),
];
final widget = ImtChartWidget(weightPoints: weightPoints);
// Act
await tester.pumpWidget(createTestWidget(widget));
await tester.pump();
await tester.pump(const Duration(seconds: 1));
// Assert
expect(find.byType(ImtChartWidget), findsOneWidget);
});
testWidgets('should display chart with multiple weight points and show increase arrow', (WidgetTester tester) async {
// Arrange
final now = DateTime.now();
final weightPoints = [
WeightModel(
id: 1,
userId: 1,
weight: 70,
createdAt: now.subtract(const Duration(days: 7)),
updatedAt: now.subtract(const Duration(days: 7)),
bmi: 23.0,
),
WeightModel(
id: 2,
userId: 1,
weight: 72,
createdAt: now,
updatedAt: now,
bmi: 24.0,
),
];
final widget = ImtChartWidget(weightPoints: weightPoints);
// Act
await tester.pumpWidget(createTestWidget(widget));
await tester.pump();
await tester.pump(const Duration(seconds: 1));
// Assert
expect(find.byType(ImtChartWidget), findsOneWidget);
});
testWidgets('should display chart with multiple weight points and show decrease arrow', (WidgetTester tester) async {
// Arrange
final now = DateTime.now();
final weightPoints = [
WeightModel(
id: 1,
userId: 1,
weight: 72,
createdAt: now.subtract(const Duration(days: 7)),
updatedAt: now.subtract(const Duration(days: 7)),
bmi: 24.0,
),
WeightModel(
id: 2,
userId: 1,
weight: 70,
createdAt: now,
updatedAt: now,
bmi: 23.0,
),
];
final widget = ImtChartWidget(weightPoints: weightPoints);
// Act
await tester.pumpWidget(createTestWidget(widget));
await tester.pump();
await tester.pump(const Duration(seconds: 1));
// Assert
expect(find.byType(ImtChartWidget), findsOneWidget);
});
});
}

View File

@@ -1,64 +0,0 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/profile/models/circumference_model.dart';
import 'package:eatvio_app/features/profile/models/weight_model.dart';
import 'package:eatvio_app/features/profile/presentation/widgets/circumference_chart_widget.dart';
import 'package:eatvio_app/features/profile/presentation/widgets/weight_chart_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
void main() {
group('Profile chart widgets smoke', () {
setUpAll(() async {
Intl.defaultLocale = 'ru';
await initializeDateFormatting('ru');
});
Widget wrap(Widget child) {
return MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(body: SingleChildScrollView(child: child)),
);
}
testWidgets('WeightChartWidget renders empty state', (tester) async {
await tester.pumpWidget(wrap(const WeightChartWidget(weightPoints: [])));
await tester.pumpAndSettle(const Duration(milliseconds: 200));
expect(find.text('Добавьте Ваш вес'), findsOneWidget);
});
testWidgets('WeightChartWidget renders with one point', (tester) async {
final points = [WeightModel(id: 1, userId: 1, weight: 70, createdAt: DateTime(2025, 1, 1), updatedAt: DateTime(2025, 1, 1), bmi: 22.0)];
await tester.pumpWidget(wrap(WeightChartWidget(weightPoints: points)));
await tester.pumpAndSettle(const Duration(milliseconds: 200));
expect(find.textContaining('кг'), findsWidgets);
});
testWidgets('CircumferenceChartWidget renders empty state', (tester) async {
await tester.pumpWidget(wrap(const CircumferenceChartWidget(circumferencePoints: [])));
await tester.pumpAndSettle(const Duration(milliseconds: 200));
expect(find.text('Добавьте Ваши замеры'), findsOneWidget);
});
testWidgets('CircumferenceChartWidget renders with one point', (tester) async {
final points = [
CircumferenceModel(
id: 1,
userId: 1,
chestCircumference: 100,
waistCircumference: 80,
hipCircumference: 90,
createdAt: DateTime(2025, 1, 1),
updatedAt: DateTime(2025, 1, 1),
),
];
await tester.pumpWidget(wrap(CircumferenceChartWidget(circumferencePoints: points)));
await tester.pumpAndSettle(const Duration(milliseconds: 200));
expect(find.text('100'), findsOneWidget);
expect(find.text('80'), findsOneWidget);
expect(find.text('90'), findsOneWidget);
});
});
}

View File

@@ -1,37 +0,0 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/profile/models/weight_model.dart';
import 'package:eatvio_app/features/profile/presentation/widgets/weight_chart_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:intl/date_symbol_data_local.dart';
void main() {
group('WeightChartWidget smoke', () {
setUpAll(() async {
await initializeDateFormatting('ru', null);
});
Widget wrap(Widget child) {
return MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(body: child),
);
}
testWidgets('renders weight chart widget with empty points', (tester) async {
await tester.pumpWidget(wrap(const WeightChartWidget(weightPoints: [])));
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
expect(find.byType(WeightChartWidget), findsOneWidget);
});
testWidgets('renders weight chart widget with points', (tester) async {
final points = [WeightModel(id: 1, userId: 1, weight: 70, bmi: 22.5, createdAt: DateTime.now(), updatedAt: DateTime.now())];
await tester.pumpWidget(wrap(WeightChartWidget(weightPoints: points)));
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
expect(find.byType(WeightChartWidget), findsOneWidget);
});
});
}

View File

@@ -1,6 +1,4 @@
import 'package:eatvio_app/features/profile/models/circumference_model.dart';
import 'package:eatvio_app/features/profile/models/profile_model.dart';
import 'package:eatvio_app/features/profile/models/weight_model.dart';
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
import 'package:eatvio_app/features/user_details/presentation/cubit/user_details_cubit.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -28,8 +26,6 @@ void main() {
expect(cubit.state.isLoading, isFalse);
expect(cubit.state.error, isNull);
expect(cubit.state.profileDetails, isNull);
expect(cubit.state.weightPoints, isNull);
expect(cubit.state.circumferencePoints, isNull);
});
test('getUserDetails - успешная загрузка деталей пользователя', () async {
@@ -62,37 +58,8 @@ void main() {
activityCoefficient: 1.5,
);
final weightPoints = [
WeightModel(
id: 1,
userId: 1,
weight: 70,
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
bmi: 22.9,
),
];
final circumferencePoints = [
CircumferenceModel(
id: 1,
userId: 1,
chestCircumference: 100,
waistCircumference: 80,
hipCircumference: 90,
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
),
];
when(mockProfileRepository.getProfileDetailsBySlug(slug))
.thenAnswer((_) async => profileDetails);
when(mockProfileRepository.getWeight(period: '1', slug: slug))
.thenAnswer((_) async => weightPoints);
when(mockProfileRepository.getCircumferences(period: '1', slug: slug))
.thenAnswer((_) async => circumferencePoints);
cubit.getUserDetails(slug);
@@ -119,75 +86,6 @@ void main() {
expect(cubit.state.error, equals(error.toString()));
expect(cubit.state.isLoading, isFalse);
});
test('getChartData - успешная загрузка данных графика', () async {
const slug = 'test-user';
const period = '1';
final weightPoints = [
WeightModel(
id: 1,
userId: 1,
weight: 70,
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
bmi: 22.9,
),
WeightModel(
id: 2,
userId: 1,
weight: 71,
createdAt: DateTime.now().add(const Duration(days: 1)),
updatedAt: DateTime.now().add(const Duration(days: 1)),
bmi: 23.2,
),
];
final circumferencePoints = [
CircumferenceModel(
id: 1,
userId: 1,
chestCircumference: 100,
waistCircumference: 80,
hipCircumference: 90,
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
),
];
when(mockProfileRepository.getWeight(period: period, slug: slug))
.thenAnswer((_) async => weightPoints);
when(mockProfileRepository.getCircumferences(period: period, slug: slug))
.thenAnswer((_) async => circumferencePoints);
cubit.getChartData(period: period, slug: slug);
// Ждем завершения асинхронных операций
await Future.delayed(const Duration(milliseconds: 100));
expect(cubit.state.weightPoints, equals(weightPoints));
expect(cubit.state.circumferencePoints, equals(circumferencePoints));
verify(mockProfileRepository.getWeight(period: period, slug: slug)).called(1);
verify(mockProfileRepository.getCircumferences(period: period, slug: slug)).called(1);
});
test('getChartData - обработка ошибки', () async {
const slug = 'test-user';
const period = '1';
final error = Exception('Ошибка загрузки');
when(mockProfileRepository.getWeight(period: period, slug: slug))
.thenThrow(error);
cubit.getChartData(period: period, slug: slug);
// Ждем завершения асинхронных операций
await Future.delayed(const Duration(milliseconds: 100));
expect(cubit.state.error, equals(error.toString()));
expect(cubit.state.isLoading, isFalse);
});
});
}

View File

@@ -2,6 +2,7 @@ import 'package:eatvio_app/core/app_config.dart';
import 'package:eatvio_app/core/app_initializer.dart';
import 'package:eatvio_app/core/locator_service.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/insights/repositories/insights_repository.dart';
import 'package:eatvio_app/features/profile/models/circumference_model.dart';
import 'package:eatvio_app/features/profile/models/profile_model.dart';
import 'package:eatvio_app/features/profile/models/weight_model.dart';
@@ -17,6 +18,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import '../../../fixtures/doubles/insights_doubles.dart';
import 'user_details_screen_smoke_test.mocks.dart';
@GenerateNiceMocks([MockSpec<ProfileRepository>()])
@@ -97,10 +99,11 @@ void main() {
final cubit = UserDetailsCubit(profileRepository: profileRepository);
when(profileRepository.getProfileDetailsBySlug('test-slug')).thenAnswer((_) async => mockProfileDetails);
when(profileRepository.getWeight(period: '1', slug: 'test-slug')).thenAnswer((_) async => mockWeightPoints);
when(profileRepository.getCircumferences(period: '1', slug: 'test-slug')).thenAnswer((_) async => mockCircumferencePoints);
when(profileRepository.getWeight(period: '3', slug: 'test-slug')).thenAnswer((_) async => mockWeightPoints);
when(profileRepository.getCircumferences(period: '3', slug: 'test-slug')).thenAnswer((_) async => mockCircumferencePoints);
sl.registerLazySingleton<ProfileRepository>(() => profileRepository);
sl.registerLazySingleton<InsightsRepository>(() => FakeInsightsRepository());
sl.registerLazySingleton<UserDetailsCubit>(() => cubit);
await tester.pumpWidget(wrap(const UserDetailsScreen(slug: 'test-slug')));
@@ -117,10 +120,11 @@ void main() {
final cubit = UserDetailsCubit(profileRepository: profileRepository);
when(profileRepository.getProfileDetailsBySlug('test-slug')).thenAnswer((_) async => mockProfileDetails);
when(profileRepository.getWeight(period: '1', slug: 'test-slug')).thenAnswer((_) async => mockWeightPoints);
when(profileRepository.getCircumferences(period: '1', slug: 'test-slug')).thenAnswer((_) async => mockCircumferencePoints);
when(profileRepository.getWeight(period: '3', slug: 'test-slug')).thenAnswer((_) async => mockWeightPoints);
when(profileRepository.getCircumferences(period: '3', slug: 'test-slug')).thenAnswer((_) async => mockCircumferencePoints);
sl.registerLazySingleton<ProfileRepository>(() => profileRepository);
sl.registerLazySingleton<InsightsRepository>(() => FakeInsightsRepository());
sl.registerLazySingleton<UserDetailsCubit>(() => cubit);
await tester.pumpWidget(wrap(const UserDetailsScreen(slug: 'test-slug')));
@@ -136,6 +140,7 @@ void main() {
when(profileRepository.getProfileDetailsBySlug('test-slug')).thenThrow(Exception('Error loading profile'));
sl.registerLazySingleton<ProfileRepository>(() => profileRepository);
sl.registerLazySingleton<InsightsRepository>(() => FakeInsightsRepository());
sl.registerLazySingleton<UserDetailsCubit>(() => cubit);
await tester.pumpWidget(wrap(const UserDetailsScreen(slug: 'test-slug')));

View File

@@ -0,0 +1,131 @@
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;
/// Ответ [fetchIntra] по запрошенной дате (`YYYY-MM-DD`); для остальных дат
/// берётся `payload.intra`.
final Map<String, IntraChartModel> intraByDate = {};
/// Если задан — выбрасывается из [fetchIntra].
Object? intraError;
/// Если задан — выбрасывается из [getInsights] (например, [InsightsForbidden]).
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, String? date})> intraRequests = [];
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<InsightsPayloadModel> fetchInsights({
String? slug,
required BodyPeriod bodyPeriod,
required DailyPeriod dailyPeriod,
String? intraDate,
}) async {
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;
}
return payload;
}
@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;
}
return intraByDate[intraDate] ?? payload.intra!;
}
@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,
));
}
}

View File

@@ -0,0 +1,46 @@
{
"data": {
"intra": {
"bars": [
{
"x": 8.5,
"p": 120,
"f": 90,
"c": 240
},
{
"x": 13,
"p": 160,
"f": 130,
"c": 300
}
],
"satiety": [
{
"x": 8.5,
"y": 3
},
{
"x": 13,
"y": 4
}
],
"mood": [
{
"x": 8.5,
"y": 4
}
],
"wake": 7.5,
"sleep": 23,
"wakeLabel": "07:30",
"sleepLabel": "23:00",
"wakeText": "Подъём в 07:30",
"sleepText": "Отход ко сну в 23:00",
"date": "2026-11-09",
"maxDate": "2026-11-09",
"dateLabel": "Сегодня",
"isToday": true
}
}
}

View File

@@ -0,0 +1,46 @@
{
"data": {
"intra": {
"bars": [
{
"x": 8.5,
"p": 120,
"f": 90,
"c": 240
},
{
"x": 13,
"p": 160,
"f": 130,
"c": 300
}
],
"satiety": [
{
"x": 8.5,
"y": 3
},
{
"x": 13,
"y": 4
}
],
"mood": [
{
"x": 8.5,
"y": 4
}
],
"wake": 7.5,
"sleep": 23,
"wakeLabel": "07:30",
"sleepLabel": "23:00",
"wakeText": "Подъём в 07:30",
"sleepText": "Отход ко сну в 23:00",
"date": "2026-11-08",
"maxDate": "2026-11-09",
"dateLabel": "8 ноября",
"isToday": false
}
}
}

View File

@@ -0,0 +1,122 @@
{
"weight": {
"labels": [
"01.11",
"05.11",
"09.11"
],
"values": [
74.5,
73.9,
73.2
],
"last": 73.2,
"delta": -1.3,
"headline": "73.2",
"unit": "кг",
"deltaText": "Снизили на 1.3 кг за период"
},
"bmi": {
"labels": [],
"values": [],
"last": null,
"delta": null,
"headline": "—",
"category": null,
"deltaText": "Укажите рост, чтобы посчитать ИМТ.",
"hint": ""
},
"measure": {
"labels": [
"01.11",
"09.11"
],
"waist": [
82,
80.5
],
"chest": [
96,
96
],
"hips": [
101,
100
],
"headline": "81",
"deltaText": "Талия меньше на 1.5 см за период"
},
"daily": {
"labels": [
"03.11",
"04.11",
"05.11"
],
"kcal": [
1850,
2010,
1930
],
"proteins": [
92,
101,
96
],
"fats": [
60,
66,
63
],
"carbs": [
210,
222,
215
],
"average": 1930,
"percent": 5,
"headline": "1930",
"deltaText": "Калораж вырос на 5% за период"
},
"intra": {
"bars": [
{
"x": 8.5,
"p": 120,
"f": 90,
"c": 240
},
{
"x": 13,
"p": 160,
"f": 130,
"c": 300
}
],
"satiety": [
{
"x": 8.5,
"y": 3
},
{
"x": 13,
"y": 4
}
],
"mood": [
{
"x": 8.5,
"y": 4
}
],
"wake": 7.5,
"sleep": 23,
"wakeLabel": "07:30",
"sleepLabel": "23:00",
"wakeText": "Подъём в 07:30",
"sleepText": "Отход ко сну в 23:00",
"date": "2026-11-09",
"maxDate": "2026-11-09",
"dateLabel": "Сегодня",
"isToday": true
}
}

View File

@@ -0,0 +1,38 @@
{
"weight": {
"labels": [],
"values": [],
"last": null,
"delta": null,
"headline": "—",
"unit": "кг",
"deltaText": "Недостаточно данных"
},
"bmi": {
"labels": [],
"values": [],
"headline": "—",
"deltaText": "Укажите рост, чтобы посчитать ИМТ.",
"hint": ""
},
"measure": {
"labels": [],
"waist": [],
"chest": [],
"hips": [],
"headline": "—",
"deltaText": "Недостаточно данных"
},
"daily": null,
"intra": {
"bars": [],
"satiety": [],
"mood": [],
"wake": null,
"sleep": null,
"date": "2026-11-09",
"maxDate": "2026-11-09",
"dateLabel": "Сегодня",
"isToday": true
}
}

View File

@@ -0,0 +1,124 @@
{
"data": {
"weight": {
"labels": [
"01.11",
"05.11",
"09.11"
],
"values": [
74.5,
73.9,
73.2
],
"last": 73.2,
"delta": -1.3,
"headline": "73.2",
"unit": "кг",
"deltaText": "Снизили на 1.3 кг за период"
},
"bmi": {
"labels": [],
"values": [],
"last": null,
"delta": null,
"headline": "—",
"category": null,
"deltaText": "Укажите рост, чтобы посчитать ИМТ.",
"hint": ""
},
"measure": {
"labels": [
"01.11",
"09.11"
],
"waist": [
82,
80.5
],
"chest": [
96,
96
],
"hips": [
101,
100
],
"headline": "81",
"deltaText": "Талия меньше на 1.5 см за период"
},
"daily": {
"labels": [
"03.11",
"04.11",
"05.11"
],
"kcal": [
1850,
2010,
1930
],
"proteins": [
92,
101,
96
],
"fats": [
60,
66,
63
],
"carbs": [
210,
222,
215
],
"average": 1930,
"percent": 5,
"headline": "1930",
"deltaText": "Калораж вырос на 5% за период"
},
"intra": {
"bars": [
{
"x": 8.5,
"p": 120,
"f": 90,
"c": 240
},
{
"x": 13,
"p": 160,
"f": 130,
"c": 300
}
],
"satiety": [
{
"x": 8.5,
"y": 3
},
{
"x": 13,
"y": 4
}
],
"mood": [
{
"x": 8.5,
"y": 4
}
],
"wake": 7.5,
"sleep": 23,
"wakeLabel": "07:30",
"sleepLabel": "23:00",
"wakeText": "Подъём в 07:30",
"sleepText": "Отход ко сну в 23:00",
"date": "2026-11-09",
"maxDate": "2026-11-09",
"dateLabel": "Сегодня",
"isToday": true
}
}
}

View File

@@ -0,0 +1,40 @@
{
"data": {
"weight": {
"labels": [],
"values": [],
"last": null,
"delta": null,
"headline": "—",
"unit": "кг",
"deltaText": "Недостаточно данных"
},
"bmi": {
"labels": [],
"values": [],
"headline": "—",
"deltaText": "Укажите рост, чтобы посчитать ИМТ.",
"hint": ""
},
"measure": {
"labels": [],
"waist": [],
"chest": [],
"hips": [],
"headline": "—",
"deltaText": "Недостаточно данных"
},
"daily": null,
"intra": {
"bars": [],
"satiety": [],
"mood": [],
"wake": null,
"sleep": null,
"date": "2026-11-09",
"maxDate": "2026-11-09",
"dateLabel": "Сегодня",
"isToday": true
}
}
}