diet-guard/app/test/widgets/day_status_calendar_test.dart
Krzysztof kuhy Rudnicki 49144a2c49 Move the app to material_ui for Flutter 3.50
Flutter 3.50 deprecates package:flutter/material.dart; 73 deprecation
infos failed flutter analyze --fatal-infos, and four Dart pins were
behind (crdt_sync_flutter 0.8.2, flutter_local_notifications 23.0.2,
github_device_auth 0.5.0, sync_settings_ui 0.8.2). Those UI packages
now sit on material_ui, so the app has to as well or their widgets lose
MaterialLocalizations.

Imports swap one-for-one and dart fix re-sorted the directives; no
behaviour change. analyze is clean and all six test shards pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWWfb63jncj9Lca2jeX
2026-11-16 09:25:34 +01:00

240 lines
6.6 KiB
Dart

import 'package:diet_guard_app/models/day_status.dart';
import 'package:diet_guard_app/widgets/day_status_calendar.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter_test/flutter_test.dart';
import 'day_status_calendar_test_support.dart';
void main() {
group('DayStatusCalendar', () {
final june2026 = DateTime(2026, 6);
final juneToday = DateTime(2026, 6, 20);
testWidgets('shows month and year in header', (tester) async {
await tester.pumpWidget(
wrapInApp(
DayStatusCalendar(
statusByDate: const {},
month: june2026,
today: juneToday,
onPrevMonth: () {},
onNextMonth: () {},
),
),
);
expect(find.text('06 · 2026'), findsOneWidget);
});
testWidgets('marks the weekend columns with two accent dots', (
tester,
) async {
await tester.pumpWidget(
wrapInApp(
DayStatusCalendar(
statusByDate: const {},
month: june2026,
today: juneToday,
onPrevMonth: () {},
onNextMonth: () {},
),
),
);
final dots = tester
.widgetList<Icon>(find.byIcon(Icons.circle))
.where((i) => i.size == 8);
expect(dots, hasLength(2));
});
testWidgets('calls onPrevMonth when left arrow tapped', (tester) async {
var called = false;
await tester.pumpWidget(
wrapInApp(
DayStatusCalendar(
statusByDate: const {},
month: june2026,
today: juneToday,
onPrevMonth: () => called = true,
onNextMonth: () {},
),
),
);
await tester.tap(find.byIcon(Icons.chevron_left));
expect(called, isTrue);
});
testWidgets('calls onNextMonth when right arrow tapped', (tester) async {
var called = false;
await tester.pumpWidget(
wrapInApp(
DayStatusCalendar(
statusByDate: const {},
month: june2026,
today: juneToday,
onPrevMonth: () {},
onNextMonth: () => called = true,
),
),
);
await tester.tap(find.byIcon(Icons.chevron_right));
expect(called, isTrue);
});
testWidgets('colors a green day', (tester) async {
await tester.pumpWidget(
wrapInApp(
DayStatusCalendar(
statusByDate: const {'2026-06-15': DayStatus.green},
month: june2026,
today: juneToday,
onPrevMonth: () {},
onNextMonth: () {},
),
),
);
expect(colorOfDay(tester, '15'), statusColors.success);
});
testWidgets('colors a yellow day', (tester) async {
await tester.pumpWidget(
wrapInApp(
DayStatusCalendar(
statusByDate: const {'2026-06-15': DayStatus.yellow},
month: june2026,
today: juneToday,
onPrevMonth: () {},
onNextMonth: () {},
),
),
);
expect(colorOfDay(tester, '15'), statusColors.warning);
});
testWidgets('colors a red day', (tester) async {
await tester.pumpWidget(
wrapInApp(
DayStatusCalendar(
statusByDate: const {'2026-06-15': DayStatus.red},
month: june2026,
today: juneToday,
onPrevMonth: () {},
onNextMonth: () {},
),
),
);
expect(colorOfDay(tester, '15'), appTheme.colorScheme.error);
});
testWidgets(
'a past day absent from statusByDate renders black (not logged)',
(tester) async {
await tester.pumpWidget(
wrapInApp(
DayStatusCalendar(
statusByDate: const {},
month: june2026,
today: juneToday,
onPrevMonth: () {},
onNextMonth: () {},
),
),
);
expect(colorOfDay(tester, '15'), appTheme.colorScheme.surface);
},
);
testWidgets(
'a future day renders neutrally, never as a false not-logged cell',
(tester) async {
await tester.pumpWidget(
wrapInApp(
DayStatusCalendar(
statusByDate: const {},
month: june2026,
today: DateTime(2026, 6, 10),
onPrevMonth: () {},
onNextMonth: () {},
),
),
);
// Day 25 is after the reference "today" of June 10.
expect(
colorOfDay(tester, '25'),
appTheme.colorScheme.surfaceContainerHigh,
);
},
);
testWidgets('today itself is classified, not treated as future', (
tester,
) async {
await tester.pumpWidget(
wrapInApp(
DayStatusCalendar(
statusByDate: const {'2026-06-20': DayStatus.red},
month: june2026,
today: juneToday,
onPrevMonth: () {},
onNextMonth: () {},
),
),
);
expect(colorOfDay(tester, '20'), appTheme.colorScheme.error);
});
testWidgets('renders a month starting on Sunday correctly', (tester) async {
final sep2026 = DateTime(2026, 9);
await tester.pumpWidget(
wrapInApp(
DayStatusCalendar(
statusByDate: const {},
month: sep2026,
today: DateTime(2026, 9),
onPrevMonth: () {},
onNextMonth: () {},
),
),
);
expect(find.text('09 · 2026'), findsOneWidget);
});
testWidgets('tapping a day calls onDaySelected with that date', (
tester,
) async {
DateTime? selected;
await tester.pumpWidget(
wrapInApp(
DayStatusCalendar(
statusByDate: const {'2026-06-15': DayStatus.green},
month: june2026,
today: juneToday,
onPrevMonth: () {},
onNextMonth: () {},
onDaySelected: (day) => selected = day,
),
),
);
await tester.tap(find.text('15'));
expect(selected, DateTime(2026, 6, 15));
});
testWidgets('no onDaySelected means day cells are not tappable', (
tester,
) async {
await tester.pumpWidget(
wrapInApp(
DayStatusCalendar(
statusByDate: const {},
month: june2026,
today: juneToday,
onPrevMonth: () {},
onNextMonth: () {},
),
),
);
// No GestureDetector wraps the day cells when onDaySelected is null;
// tapping must not throw.
await tester.tap(find.text('15'));
});
});
}