mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Consolidate frontend scanner, pagination, and tick-timer duplication
Collapse the five scanner status models into two shared shapes, ActiveScannerStatus and PassiveScannerStatus, mirroring the backend's active/passive vocabulary. Replace the five near-identical per-scanner detail card files with a single scanner_status_cards.dart (two shared resolvers plus a config list), and rebuild the combined home card to iterate a list of scanners with two shape resolvers instead of five copy-pasted resolve methods. Extract two reusable mixins: - PeriodicRebuild: the shared once-a-second "rebuild to refresh elapsed text" timer used by the scanner cards and the stale indicator. - PaginatedListState: the shared pagination state, page-size/page-count getters, cancel-token-aware fetch orchestration, and disposal used by the device and notification lists. No behaviour change; ~900 lines removed. Tests and analyzer pass.
This commit is contained in:
@@ -1,16 +1,13 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:frontend/model/arp_scanner_status.dart';
|
||||
import 'package:frontend/model/dhcp_scanner_status.dart';
|
||||
import 'package:frontend/model/mdns_scanner_status.dart';
|
||||
import 'package:frontend/model/snmp_scanner_status.dart';
|
||||
import 'package:frontend/model/ssdp_scanner_status.dart';
|
||||
import 'package:frontend/model/active_scanner_status.dart';
|
||||
import 'package:frontend/model/passive_scanner_status.dart';
|
||||
|
||||
import '../helpers/fixtures.dart';
|
||||
|
||||
void main() {
|
||||
group('interval scanners (ARP, SNMP)', () {
|
||||
test('ArpScannerStatus.fromJson maps populated fields', () {
|
||||
final status = ArpScannerStatus.fromJson(
|
||||
group('active scanners (ARP, SNMP)', () {
|
||||
test('ActiveScannerStatus.fromJson maps populated fields', () {
|
||||
final status = ActiveScannerStatus.fromJson(
|
||||
intervalScannerJson(
|
||||
isRunning: true,
|
||||
runningForSeconds: 12.5,
|
||||
@@ -27,28 +24,19 @@ void main() {
|
||||
expect(status.lastScanSecondsAgo, 5.0);
|
||||
});
|
||||
|
||||
test('ArpScannerStatus.fromJson tolerates null optionals', () {
|
||||
final status = ArpScannerStatus.fromJson(intervalScannerJson());
|
||||
test('ActiveScannerStatus.fromJson tolerates null optionals', () {
|
||||
final status = ActiveScannerStatus.fromJson(intervalScannerJson());
|
||||
|
||||
expect(status.isRunning, isFalse);
|
||||
expect(status.runningForSeconds, isNull);
|
||||
expect(status.nextRunInSeconds, isNull);
|
||||
expect(status.lastScanDevicesSeen, isNull);
|
||||
});
|
||||
|
||||
test('SnmpScannerStatus.fromJson maps fields', () {
|
||||
final status = SnmpScannerStatus.fromJson(
|
||||
intervalScannerJson(isRunning: true, runningForSeconds: 3),
|
||||
);
|
||||
|
||||
expect(status.isRunning, isTrue);
|
||||
expect(status.runningForSeconds, 3.0);
|
||||
});
|
||||
});
|
||||
|
||||
group('listener scanners (mDNS, SSDP, DHCP)', () {
|
||||
test('MdnsScannerStatus.fromJson maps populated fields', () {
|
||||
final status = MdnsScannerStatus.fromJson(
|
||||
group('passive scanners (mDNS, SSDP, DHCP)', () {
|
||||
test('PassiveScannerStatus.fromJson maps populated fields', () {
|
||||
final status = PassiveScannerStatus.fromJson(
|
||||
listenerScannerJson(
|
||||
isListening: true,
|
||||
listeningForSeconds: 99.0,
|
||||
@@ -63,9 +51,9 @@ void main() {
|
||||
expect(status.lastDeviceSeenSecondsAgo, 8.0);
|
||||
});
|
||||
|
||||
test('SsdpScannerStatus.fromJson requires devicesSeen and tolerates nulls',
|
||||
() {
|
||||
final status = SsdpScannerStatus.fromJson(
|
||||
test('PassiveScannerStatus.fromJson requires devicesSeen and tolerates '
|
||||
'nulls', () {
|
||||
final status = PassiveScannerStatus.fromJson(
|
||||
listenerScannerJson(devicesSeen: 0),
|
||||
);
|
||||
|
||||
@@ -74,14 +62,5 @@ void main() {
|
||||
expect(status.listeningForSeconds, isNull);
|
||||
expect(status.lastDeviceSeenSecondsAgo, isNull);
|
||||
});
|
||||
|
||||
test('DhcpScannerStatus.fromJson maps fields', () {
|
||||
final status = DhcpScannerStatus.fromJson(
|
||||
listenerScannerJson(isListening: true, devicesSeen: 2),
|
||||
);
|
||||
|
||||
expect(status.isListening, isTrue);
|
||||
expect(status.devicesSeen, 2);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user