wake-alarm/phone_app/test/home_history_card_test.dart
Krzysztof kuhy Rudnicki 8e6fa90c80
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,free-days-interop) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / free-days-interop (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Bump Flutter to 3.50.0 via material_ui
Flutter 3.50 deprecates package:flutter/material.dart, so the app
moves to material_ui 1.11.0 together with sync_settings_ui 0.8.0
and github_device_auth 0.5.0 (crdt_sync 0.13.1 rides along).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 09:06:16 +01:00

114 lines
3.6 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter_test/flutter_test.dart';
import 'package:material_ui/material_ui.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:wake_alarm_sync/screens/home_history_card.dart';
import 'package:wake_alarm_sync/services/morning_session.dart';
import 'package:wake_alarm_sync/services/session_rules.dart';
import 'package:wake_alarm_sync/services/session_store.dart';
import 'package:wake_alarm_sync/services/session_tag_settings.dart';
import 'package:wake_alarm_sync/ui/dashed_slot.dart';
import 'package:wake_alarm_sync/ui/spoken_label.dart';
MorningSession _session(
DateTime at, {
double? kg,
int reRings = 0,
SessionOutcome outcome = SessionOutcome.completed,
}) =>
SessionRules.start(
now: at,
tags: const SessionTagSettings(),
nfcAvailable: false,
)
..weightKg = kg
..reRings = reRings
..outcome = outcome;
void main() {
setUp(() => SharedPreferences.setMockInitialValues(<String, Object>{}));
test('describes a morning in one line', () {
expect(
describeMorning(
_session(DateTime(2026, 9, 17, 8), kg: 72.4, reRings: 1),
previousWeight: 72.7,
),
'09-17 ✓ 1 re-ring · 72.4 kg (−0.3)',
);
expect(
describeMorning(
_session(
DateTime(2026, 9, 16, 8),
kg: 73,
outcome: SessionOutcome.failed,
),
previousWeight: 72,
),
'09-16 ✗ 0 re-rings · 73.0 kg (+1.0)',
);
expect(
describeMorning(
_session(DateTime(2026, 9, 15, 8), kg: 72),
previousWeight: 72,
),
'09-15 ✓ 0 re-rings · 72.0 kg (±0.0)',
);
expect(
describeMorning(
_session(DateTime(2026, 9, 14, 8), outcome: SessionOutcome.active),
),
'09-14 … 0 re-rings',
);
expect(
describeMorning(_session(DateTime(2026, 9, 13, 8), kg: 72)..energy = 4),
'09-13 ✓ 0 re-rings · 72.0 kg · energy 4/5',
);
});
testWidgets('is absent until a morning has finished', (tester) async {
await tester.pumpWidget(const MaterialApp(home: HomeHistoryCard()));
await tester.pump();
expect(find.byType(Row), findsNothing);
expect(find.byType(DashedSlot), findsNothing);
});
testWidgets('shows an empty slot when no morning has finished', (
tester,
) async {
await tester.pumpWidget(
const MaterialApp(home: HomeHistoryCard(emptyText: 'None yet.')),
);
expect(find.byType(DashedSlot), findsNothing);
await tester.pump();
expect(find.byType(DashedSlot), findsOneWidget);
expect(
tester.widget<SpokenLabel>(find.byType(SpokenLabel).first).semanticLabel,
'None yet.',
);
});
testWidgets('lists the last seven with weight deltas', (tester) async {
final store = SessionStore();
for (var day = 1; day <= 9; day++) {
await store.archive(_session(DateTime(2026, 9, day, 8), kg: 70.0 + day));
}
// As the home tile shows it: a scrolling bottom sheet.
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(body: SingleChildScrollView(child: HomeHistoryCard())),
),
);
await tester.pump();
final rows = tester
.widgetList<SpokenLabel>(find.byType(SpokenLabel))
.map((w) => w.semanticLabel)
.toList();
expect(rows, hasLength(kHistoryShown));
expect(rows.first, '09-09 ✓ 0 re-rings · 79.0 kg (+1.0)');
expect(find.text('79.0'), findsOneWidget);
expect(find.text(' (+1.0)'), findsWidgets);
expect(find.text('09-03'), findsOneWidget);
expect(find.text('09-02'), findsNothing);
});
}