feat: 实现日历提醒 in-app fallback 机制及通知服务重构

This commit is contained in:
zl-q
2026-03-20 01:30:34 +08:00
parent 7fd536e976
commit d574128815
55 changed files with 4565 additions and 647 deletions
@@ -0,0 +1,70 @@
import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:social_app/features/settings/data/services/settings_user_cache.dart';
import 'package:social_app/features/users/data/models/user_response.dart';
void main() {
test('getOrLoad calls loader only once when cache exists', () async {
final cache = SettingsUserCache();
var loadCalls = 0;
Future<UserResponse> loader() async {
loadCalls += 1;
return const UserResponse(id: 'u1', username: 'first');
}
final first = await cache.getOrLoad(loader);
final second = await cache.getOrLoad(loader);
expect(first.username, 'first');
expect(second.username, 'first');
expect(loadCalls, 1);
});
test('invalidate forces next load', () async {
final cache = SettingsUserCache();
var loadCalls = 0;
Future<UserResponse> loader() async {
loadCalls += 1;
return UserResponse(id: 'u$loadCalls', username: 'user$loadCalls');
}
final first = await cache.getOrLoad(loader);
cache.invalidate();
final second = await cache.getOrLoad(loader);
expect(first.id, 'u1');
expect(second.id, 'u2');
expect(loadCalls, 2);
});
test(
'invalidate blocks stale inflight response from repopulating cache',
() async {
final cache = SettingsUserCache();
final completer = Completer<UserResponse>();
var loadCalls = 0;
Future<UserResponse> slowLoader() {
loadCalls += 1;
return completer.future;
}
final pending = cache.getOrLoad(slowLoader);
cache.invalidate();
completer.complete(const UserResponse(id: 'u1', username: 'stale'));
await pending;
final fresh = await cache.getOrLoad(() async {
loadCalls += 1;
return const UserResponse(id: 'u2', username: 'fresh');
});
expect(fresh.id, 'u2');
expect(cache.cachedUser?.id, 'u2');
expect(loadCalls, 2);
},
);
}