mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Active scanners (ARP, SNMP) now accumulate every change across a whole scan and emit one notification per type via events::notify: a single device produces the usual single-device notification (carrying its MAC), while two or more produce one consolidated summary with an empty mac_address. Device events are still recorded per device. Notification bodies no longer include MAC or IP addresses; the title MAC fallback is masked to the last two octets. Summaries list up to three devices then "…and N more devices". Split sighting handling so record_sighting persists + records the event and returns Vec<DeviceChange>; passive listeners (mDNS, SSDP, DHCP) use record_and_notify since they see one device per event. Also fixes NotificationType::from_str never mapping "DeviceChanged", which made those notifications round-trip from the DB as Other. Frontend: the card already hides the device link when mac_address is null; added widget tests for the present/absent link cases. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
99 lines
2.9 KiB
Dart
99 lines
2.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:frontend/home/notification_card.dart';
|
|
import 'package:frontend/model/notification.dart' as oott_model;
|
|
import 'package:frontend/model/notification_type.dart';
|
|
import 'package:frontend/utils/friendly_date_formatter.dart';
|
|
|
|
oott_model.Notification _sampleNotification({
|
|
String? macAddress = 'AA:BB:CC:DD:EE:FF',
|
|
}) => oott_model.Notification(
|
|
id: 1,
|
|
title: 'New device found',
|
|
body: 'A long body that wraps across multiple lines when expanded.',
|
|
notificationType: NotificationType.newDeviceFound,
|
|
createdOn: DateTime(2026, 6, 4, 12),
|
|
isNew: true,
|
|
macAddress: macAddress,
|
|
);
|
|
|
|
Future<void> _pumpCard(
|
|
WidgetTester tester, {
|
|
String? macAddress = 'AA:BB:CC:DD:EE:FF',
|
|
}) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: NotificationCard(
|
|
item: _sampleNotification(macAddress: macAddress),
|
|
formatter: FriendlyDateFormatter(),
|
|
onSetRead: (_) async => true,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('tapping the body expands and then collapses the card', (
|
|
tester,
|
|
) async {
|
|
await _pumpCard(tester);
|
|
|
|
// Initially collapsed: no action buttons.
|
|
expect(find.text('Mark as read'), findsNothing);
|
|
|
|
// Tap the body to expand.
|
|
await tester.tap(find.byType(ListTile));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Mark as read'), findsOneWidget);
|
|
|
|
// Tap directly on the body text to collapse.
|
|
await tester.tap(
|
|
find.text('A long body that wraps across multiple lines when expanded.'),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Mark as read'), findsNothing);
|
|
});
|
|
|
|
testWidgets('tapping the action area (not a button) collapses the card', (
|
|
tester,
|
|
) async {
|
|
await _pumpCard(tester);
|
|
|
|
await tester.tap(find.byType(ListTile));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Mark as read'), findsOneWidget);
|
|
|
|
// Tap the action row outside any button: its left edge is empty space
|
|
// because the buttons are aligned to the end.
|
|
final actions = tester.getRect(find.byType(OverflowBar));
|
|
await tester.tapAt(Offset(actions.left + 1, actions.center.dy));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Mark as read'), findsNothing);
|
|
});
|
|
|
|
testWidgets('shows a device link when the notification has a MAC address', (
|
|
tester,
|
|
) async {
|
|
await _pumpCard(tester);
|
|
|
|
await tester.tap(find.byType(ListTile));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('View device'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets(
|
|
'omits the device link for a multi-device notification (no MAC address)',
|
|
(tester) async {
|
|
await _pumpCard(tester, macAddress: null);
|
|
|
|
await tester.tap(find.byType(ListTile));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('View device'), findsNothing);
|
|
},
|
|
);
|
|
}
|