74 lines
1.9 KiB
Dart
74 lines
1.9 KiB
Dart
import 'dart:async';
|
|
import 'package:xp_nix/src/interfaces/i_idle_monitor.dart';
|
|
|
|
/// Mock implementation of IIdleMonitor for testing
|
|
class MockIdleMonitor implements IIdleMonitor {
|
|
final StreamController<IdleStatus> _idleStateController = StreamController<IdleStatus>.broadcast();
|
|
IdleStatus _status = IdleStatus.active;
|
|
|
|
@override
|
|
Stream<IdleStatus> get idleStateStream => _idleStateController.stream;
|
|
|
|
@override
|
|
Future<void> start() async {
|
|
// No-op for mock
|
|
}
|
|
|
|
@override
|
|
void stop() {
|
|
_idleStateController.close();
|
|
}
|
|
|
|
@override
|
|
IdleStatus get status => _status;
|
|
|
|
/// Simulate user going to deep idle
|
|
void simulateDeepIdle() {
|
|
_status = IdleStatus.deepIdle;
|
|
_idleStateController.add(IdleStatus.deepIdle);
|
|
}
|
|
|
|
/// Simulate user going to light idle
|
|
void simulateLightIdle() {
|
|
_status = IdleStatus.lightIdle;
|
|
_idleStateController.add(IdleStatus.lightIdle);
|
|
}
|
|
|
|
/// Simulate user becoming active
|
|
void simulateActive() {
|
|
_status = IdleStatus.active;
|
|
_idleStateController.add(IdleStatus.active);
|
|
}
|
|
|
|
/// Simulate user going idle (backwards compatibility - defaults to deep idle)
|
|
void simulateIdle() {
|
|
simulateDeepIdle();
|
|
}
|
|
|
|
/// Simulate a sequence of idle/active events with delays
|
|
Future<void> simulateIdleSequence(List<IdleEvent> events) async {
|
|
for (final event in events) {
|
|
await Future.delayed(event.delay);
|
|
if (event.isIdle) {
|
|
simulateIdle();
|
|
} else {
|
|
simulateActive();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Represents an idle state change event for simulation
|
|
class IdleEvent {
|
|
final bool isIdle;
|
|
final Duration delay;
|
|
|
|
const IdleEvent({required this.isIdle, this.delay = Duration.zero});
|
|
|
|
/// Factory for idle event
|
|
factory IdleEvent.idle({Duration delay = Duration.zero}) => IdleEvent(isIdle: true, delay: delay);
|
|
|
|
/// Factory for active event
|
|
factory IdleEvent.active({Duration delay = Duration.zero}) => IdleEvent(isIdle: false, delay: delay);
|
|
}
|