diet-guard/app/test/widgets/day_status_calendar_test_support.dart
Krzysztof kuhy Rudnicki c0ed6154ac Split the remaining seven Dart test files
Eleventh batch of the 250-line sweep (over-cap count 12 -> 5). Every test file
in the repo, Python and Dart, is now under cap; the five left are all in
app/lib/.

  wrapper_server_test.dart        349 -> 145  (+ proxy, account siblings)
  app_settings_service_test.dart  321 -> 162  (+ sync sibling)
  average_service_test.dart       299 -> 158  (+ periods sibling)
  settings_screen_test.dart       274 -> 189  (+ battery sibling)
  day_status_service_test.dart    270 -> 161  (+ streaks sibling)
  edit_entry_screen_test.dart     269 -> 159  (+ foodbank sibling)
  day_status_calendar_test.dart   256 -> 237  (+ _test_support sibling)

day_status_calendar_test is a single group whose tests close over group-local
state, so it could not be split by block. Its ~25 lines of file-level fixtures
moved to `day_status_calendar_test_support.dart` instead, which required the
same publicisation as the sync support file (`_theme` -> `appTheme`, `_wrap` ->
`wrapInApp`, `_colorOfDay` -> `colorOfDay`) with doc comments.

Block counts were compared against HEAD per family rather than trusting the
suite total, since the duplication bug in the previous batch passed green at an
inflated count. All seven families match exactly (29/26/34/11/34/8/14).

Verified: flutter test 555 (unchanged), flutter analyze clean, pre-commit
clean.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RA9ynjqXPnexRQnR5oAuCC
2026-08-15 20:53:55 +02:00

34 lines
1.4 KiB
Dart

// Shared fixtures for the day_status_calendar widget tests.
//
// Split out of `day_status_calendar_test.dart` for the repo's 250-line cap.
// Public because the names now cross a file boundary -- a leading underscore
// is library-private in Dart.
import 'package:diet_guard_app/ui/theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
// The real app theme, not a bare default MaterialApp -- the widget under
// test reads its colors from Theme.of(context), so asserting against the
// same theme the app actually ships is what makes these assertions mean
// anything (a bare MaterialApp's own default colors would be arbitrary).
/// The real app theme the widget under test reads its colors from.
final ThemeData appTheme = buildAppTheme();
/// The app's status-color extension, for asserting per-day cell colors.
final AppStatusColors statusColors = appTheme.extension<AppStatusColors>()!;
/// Wraps [child] in a MaterialApp carrying the real app theme.
Widget wrapInApp(Widget child) => MaterialApp(
theme: appTheme,
home: Scaffold(body: child),
);
/// Returns the background color of the calendar cell showing [day].
Color colorOfDay(WidgetTester tester, String day) {
final container = tester.widget<Container>(
find.ancestor(of: find.text(day), matching: find.byType(Container)).first,
);
final decoration = container.decoration! as BoxDecoration;
return decoration.color!;
}