feat: add app lifecycle refresh coordinator

This commit is contained in:
qzl
2026-03-20 15:39:44 +08:00
parent e64b9c670c
commit f4c07287bc
3 changed files with 80 additions and 0 deletions
@@ -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);
});
}