2026-06-03 19:41:52 -04:00
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
2026-06-05 21:57:58 -04:00
|
|
|
import 'package:frontend/model/active_scanner_status.dart';
|
|
|
|
|
import 'package:frontend/model/passive_scanner_status.dart';
|
2026-06-03 19:41:52 -04:00
|
|
|
|
|
|
|
|
import '../helpers/fixtures.dart';
|
|
|
|
|
|
|
|
|
|
void main() {
|
2026-06-05 21:57:58 -04:00
|
|
|
group('active scanners (ARP, SNMP)', () {
|
|
|
|
|
test('ActiveScannerStatus.fromJson maps populated fields', () {
|
|
|
|
|
final status = ActiveScannerStatus.fromJson(
|
2026-06-03 19:41:52 -04:00
|
|
|
intervalScannerJson(
|
|
|
|
|
isRunning: true,
|
|
|
|
|
runningForSeconds: 12.5,
|
|
|
|
|
nextRunInSeconds: 30,
|
|
|
|
|
lastScanDevicesSeen: 7,
|
|
|
|
|
lastScanSecondsAgo: 5,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(status.isRunning, isTrue);
|
|
|
|
|
expect(status.runningForSeconds, 12.5);
|
|
|
|
|
expect(status.nextRunInSeconds, 30.0);
|
|
|
|
|
expect(status.lastScanDevicesSeen, 7);
|
|
|
|
|
expect(status.lastScanSecondsAgo, 5.0);
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-05 21:57:58 -04:00
|
|
|
test('ActiveScannerStatus.fromJson tolerates null optionals', () {
|
|
|
|
|
final status = ActiveScannerStatus.fromJson(intervalScannerJson());
|
2026-06-03 19:41:52 -04:00
|
|
|
|
|
|
|
|
expect(status.isRunning, isFalse);
|
|
|
|
|
expect(status.runningForSeconds, isNull);
|
|
|
|
|
expect(status.nextRunInSeconds, isNull);
|
|
|
|
|
expect(status.lastScanDevicesSeen, isNull);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-05 21:57:58 -04:00
|
|
|
group('passive scanners (mDNS, SSDP, DHCP)', () {
|
|
|
|
|
test('PassiveScannerStatus.fromJson maps populated fields', () {
|
|
|
|
|
final status = PassiveScannerStatus.fromJson(
|
2026-06-03 19:41:52 -04:00
|
|
|
listenerScannerJson(
|
|
|
|
|
isListening: true,
|
|
|
|
|
listeningForSeconds: 99.0,
|
|
|
|
|
devicesSeen: 4,
|
|
|
|
|
lastDeviceSeenSecondsAgo: 8,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(status.isListening, isTrue);
|
|
|
|
|
expect(status.listeningForSeconds, 99.0);
|
|
|
|
|
expect(status.devicesSeen, 4);
|
|
|
|
|
expect(status.lastDeviceSeenSecondsAgo, 8.0);
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-05 21:57:58 -04:00
|
|
|
test('PassiveScannerStatus.fromJson requires devicesSeen and tolerates '
|
|
|
|
|
'nulls', () {
|
|
|
|
|
final status = PassiveScannerStatus.fromJson(
|
2026-06-03 19:41:52 -04:00
|
|
|
listenerScannerJson(devicesSeen: 0),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(status.isListening, isFalse);
|
|
|
|
|
expect(status.devicesSeen, 0);
|
|
|
|
|
expect(status.listeningForSeconds, isNull);
|
|
|
|
|
expect(status.lastDeviceSeenSecondsAgo, isNull);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|