mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Add automated test suite for the Flutter frontend
Introduce a headless `flutter test` suite (83 tests) covering models, utilities, every API endpoint, and the five screens, with shared helpers and fixtures so new tests stay terse. API endpoint methods are statically-dispatched extensions on the BackendAPI singleton, so they cannot be mocked via `implements`. Mock at the Dio HTTP-adapter layer (http_mock_adapter) instead, enabled by two small @visibleForTesting seams: BackendAPI.dioForTesting swaps the singleton's Dio, and BackendReachability.forceOnlineForTesting() forces a deterministic online state so polling widgets load. Add frontend/run_tests.sh and document it in CLAUDE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
e6813a78fb
commit
98b5fa267f
@@ -0,0 +1,47 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:frontend/utils/friendly_date_formatter.dart';
|
||||
|
||||
void main() {
|
||||
final formatter = FriendlyDateFormatter();
|
||||
final now = DateTime.now();
|
||||
|
||||
test('renders very recent times as "Just now"', () {
|
||||
expect(formatter.format(now.subtract(const Duration(seconds: 30))), 'Just now');
|
||||
expect(formatter.format(now.subtract(const Duration(minutes: 2))), 'Just now');
|
||||
});
|
||||
|
||||
test('renders times under an hour as relative minutes', () {
|
||||
expect(
|
||||
formatter.format(now.subtract(const Duration(minutes: 30))),
|
||||
'30 minutes ago',
|
||||
);
|
||||
});
|
||||
|
||||
test('renders earlier-today / late-yesterday times with a clock time', () {
|
||||
final candidate = now.subtract(const Duration(hours: 2));
|
||||
final sameDay = candidate.year == now.year &&
|
||||
candidate.month == now.month &&
|
||||
candidate.day == now.day;
|
||||
|
||||
expect(
|
||||
formatter.format(candidate),
|
||||
startsWith(sameDay ? 'Today at' : 'Yesterday at'),
|
||||
);
|
||||
});
|
||||
|
||||
test('renders a yesterday-noon time as "Yesterday at"', () {
|
||||
final yesterdayNoon =
|
||||
DateTime(now.year, now.month, now.day - 1, 12, 0);
|
||||
|
||||
expect(formatter.format(yesterdayNoon), startsWith('Yesterday at'));
|
||||
});
|
||||
|
||||
test('renders older dates with the full date', () {
|
||||
final threeDaysAgo = DateTime(now.year, now.month, now.day - 3, 12, 0);
|
||||
final result = formatter.format(threeDaysAgo);
|
||||
|
||||
expect(result, contains(threeDaysAgo.year.toString()));
|
||||
expect(result, isNot(startsWith('Today')));
|
||||
expect(result, isNot(startsWith('Yesterday')));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user