Files
kooltab/test/app_lifecycle_lock_test.dart

50 lines
1.2 KiB
Dart

import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:kooltab2/app/app_lifecycle_lock.dart';
void main() {
test('locks when the app is no longer active', () {
var lockCount = 0;
final observer = AppLifecycleLockObserver(onLock: () => lockCount++);
for (final state in [
AppLifecycleState.inactive,
AppLifecycleState.hidden,
AppLifecycleState.paused,
AppLifecycleState.detached,
]) {
observer.didChangeAppLifecycleState(state);
}
expect(lockCount, 4);
});
test('does not lock while the app is active', () {
var lockCount = 0;
final observer = AppLifecycleLockObserver(onLock: () => lockCount++);
observer.didChangeAppLifecycleState(AppLifecycleState.resumed);
expect(lockCount, 0);
});
test('does not lock when auto-lock is disabled', () {
var lockCount = 0;
final observer = AppLifecycleLockObserver(
onLock: () => lockCount++,
shouldLock: () => false,
);
for (final state in [
AppLifecycleState.inactive,
AppLifecycleState.hidden,
AppLifecycleState.paused,
AppLifecycleState.detached,
]) {
observer.didChangeAppLifecycleState(state);
}
expect(lockCount, 0);
});
}