feat: add app lifecycle refresh coordinator
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:social_app/core/cache/cache_refresh_coordinator.dart';
|
||||
|
||||
void main() {
|
||||
test('resume should trigger refresh only when min interval elapsed', () {
|
||||
var calls = 0;
|
||||
var now = DateTime(2026, 3, 20, 10, 0);
|
||||
|
||||
final coordinator = CacheRefreshCoordinator(
|
||||
minInterval: const Duration(minutes: 5),
|
||||
onRefresh: () => calls += 1,
|
||||
now: () => now,
|
||||
);
|
||||
|
||||
coordinator.didChangeAppLifecycleState(AppLifecycleState.resumed);
|
||||
expect(calls, 1);
|
||||
|
||||
now = DateTime(2026, 3, 20, 10, 3);
|
||||
coordinator.didChangeAppLifecycleState(AppLifecycleState.resumed);
|
||||
expect(calls, 1);
|
||||
|
||||
now = DateTime(2026, 3, 20, 10, 6);
|
||||
coordinator.didChangeAppLifecycleState(AppLifecycleState.resumed);
|
||||
expect(calls, 2);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user