forked from eatvio/eatvio_app
feat(insights): added kbju fetching for analitics
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
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';
|
||||
@@ -60,7 +61,7 @@ void main() {
|
||||
expect(find.byType(DailyKbjuChart), findsOneWidget);
|
||||
expect(find.text('1930'), findsOneWidget);
|
||||
expect(find.text('ккал в среднем'), findsOneWidget);
|
||||
expect(find.text('98% от нормы'), findsOneWidget);
|
||||
expect(find.text('Калораж вырос на 5% за период'), findsOneWidget);
|
||||
for (var i = 0; i < 4; i++) {
|
||||
expect(find.byKey(Key('insights_series_$i')), findsOneWidget);
|
||||
}
|
||||
@@ -85,6 +86,20 @@ void main() {
|
||||
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(
|
||||
@@ -135,26 +150,66 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'кнопка «следующий день» отключена при isToday, «предыдущий» без колбэка тоже',
|
||||
(tester) async {
|
||||
await pumpKbjuCard(
|
||||
tester,
|
||||
FakeInsightsRepository(),
|
||||
'insights_tab_intra',
|
||||
);
|
||||
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),
|
||||
),
|
||||
);
|
||||
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, isNull);
|
||||
},
|
||||
);
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user