mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
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>
62 lines
2.1 KiB
Dart
62 lines
2.1 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:frontend/model/notification.dart';
|
|
import 'package:frontend/model/notification_type.dart';
|
|
|
|
import '../helpers/fixtures.dart';
|
|
|
|
void main() {
|
|
group('Notification.fromJson', () {
|
|
test('maps all fields', () {
|
|
final notification = Notification.fromJson(
|
|
notificationJson(
|
|
id: 9,
|
|
createdOn: '2026-05-15T09:00:00Z',
|
|
notificationType: 'deviceChanged',
|
|
title: 'Device changed',
|
|
body: 'Something changed',
|
|
isNew: false,
|
|
macAddress: '11:22:33:44:55:66',
|
|
),
|
|
);
|
|
|
|
expect(notification.id, 9);
|
|
expect(notification.createdOn, DateTime.parse('2026-05-15T09:00:00Z'));
|
|
expect(notification.notificationType, NotificationType.deviceChanged);
|
|
expect(notification.title, 'Device changed');
|
|
expect(notification.body, 'Something changed');
|
|
expect(notification.isNew, isFalse);
|
|
expect(notification.macAddress, '11:22:33:44:55:66');
|
|
});
|
|
|
|
test('leaves macAddress null when absent', () {
|
|
final notification = Notification.fromJson(
|
|
notificationJson(macAddress: null),
|
|
);
|
|
expect(notification.macAddress, isNull);
|
|
});
|
|
});
|
|
|
|
test('toJson round-trips back through fromJson', () {
|
|
final original = Notification.fromJson(notificationJson(id: 3));
|
|
final restored = Notification.fromJson(original.toJson());
|
|
|
|
expect(restored.id, original.id);
|
|
expect(restored.title, original.title);
|
|
expect(restored.body, original.body);
|
|
expect(restored.isNew, original.isNew);
|
|
expect(restored.notificationType, original.notificationType);
|
|
expect(restored.createdOn, original.createdOn);
|
|
expect(restored.macAddress, original.macAddress);
|
|
});
|
|
|
|
test('copyWith only overrides isNew', () {
|
|
final original = Notification.fromJson(notificationJson(isNew: true));
|
|
final updated = original.copyWith(isNew: false);
|
|
|
|
expect(updated.isNew, isFalse);
|
|
expect(updated.id, original.id);
|
|
expect(updated.title, original.title);
|
|
expect(original.isNew, isTrue, reason: 'original is not mutated');
|
|
});
|
|
}
|