diet-guard/app/test/widgets/sync_health_banner_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

79 lines
2.3 KiB
Dart

import 'package:diet_guard_app/services/sync_health.dart';
import 'package:diet_guard_app/widgets/sync_health_banner.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter_test/flutter_test.dart';
Future<void> pump(WidgetTester tester, SyncHealthStatus? status) =>
tester.pumpWidget(
MaterialApp(
home: Scaffold(body: SyncHealthBanner(status: status)),
),
);
void main() {
testWidgets('renders nothing before health has been read', (tester) async {
await pump(tester, null);
expect(find.byIcon(Icons.cloud_off), findsNothing);
});
testWidgets('renders nothing for a healthy device', (tester) async {
final now = DateTime(2026, 8, 10, 12);
await pump(
tester,
SyncHealthStatus(
lastSuccess: now.subtract(const Duration(minutes: 5)),
failureKind: null,
now: now,
),
);
expect(find.byIcon(Icons.cloud_off), findsNothing);
});
testWidgets('warns when the device has stopped publishing', (tester) async {
final now = DateTime(2026, 8, 10, 12);
await pump(
tester,
SyncHealthStatus(
lastSuccess: now.subtract(const Duration(days: 2)),
failureKind: SyncFailureKind.failed,
now: now,
),
);
expect(find.byIcon(Icons.cloud_off), findsOneWidget);
expect(find.text('2d'), findsOneWidget);
expect(
find.byWidgetPredicate(
(w) =>
w is Icon &&
(w.semanticLabel?.contains('Meals stay on this device') ?? false),
),
findsOneWidget,
);
});
testWidgets('survives a theme with no AppStatusColors extension', (
tester,
) async {
// Regression guard: a `!` on the extension lookup crashed every widget
// test that pumped a bare MaterialApp.
final now = DateTime(2026, 8, 10, 12);
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(extensions: const []),
home: Scaffold(
body: SyncHealthBanner(
status: SyncHealthStatus(
lastSuccess: now.subtract(const Duration(days: 2)),
failureKind: SyncFailureKind.unconfigured,
now: now,
),
),
),
),
);
expect(tester.takeException(), isNull);
expect(find.byIcon(Icons.cloud_off), findsOneWidget);
});
}