feat(mobile): upload queue ui and continuous capture page
Task 9 (P3 plan): queue tab replaces the stub, continuous capture page enqueues per shot, album detail gains an upload FAB, and the upload engine lifecycle is now bound to the login session. - Engine scope: session account drives UploadEngine start/stop; wired from app boot, login success, logout, and 401 eviction. Tasks stay in the store across logout (accountId hard isolation). - Queue tab: album x state x time filter bar, task rows with thumbnail, state chip, localized error copy, attempt count, per-row progress via a broadcast progress hub, state-dependent actions (re-pick retry, retryNow, cancel, delete), batch retry bar, 200ms-debounced live refresh from drift table updates. - Capture page: camera preview via injected CaptureSource, one enqueue per shutter press, persistent album/category/badges overlay with a switch-only-affects-new-shots hint, gallery multi-pick, exit confirm while uploads are pending, permission-denied and init-failure views. - POST_NOTIFICATIONS runtime permission via a small MethodChannel (photolive/permissions) + PermissionPlugin.kt: single runtime permission need, avoids permission_handler dependency; requested once on first enqueue, silent degradation when denied or unavailable. - Album detail FAB: capture-and-upload / pick-from-gallery sheet. - l10n: ~50 new keys in zh/en arbs; tests: +45 (filter matrix, engine scope lifecycle, permission gate, queue tab, capture page, FAB entry); existing page tests updated to inject session/task-store fakes. Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
/// POST_NOTIFICATIONS 权限门测试(P3 计划 Task 9)。
|
||||
///
|
||||
/// 覆盖:Android 首次请求一次(幂等,二次调用不触通道)、非 Android 跳过、
|
||||
/// 通道缺失/异常静默降级不阻断入队。
|
||||
library;
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:photo_live/core/notification_permission.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
const channel = MethodChannel(NotificationPermission.kChannelName);
|
||||
// 测试绑定的 defaultBinaryMessenger 即 TestDefaultBinaryMessenger
|
||||
// (setMockMethodCallHandler 所在)。
|
||||
final byteData = TestWidgetsFlutterBinding.instance.defaultBinaryMessenger;
|
||||
|
||||
tearDown(() => byteData.setMockMethodCallHandler(channel, null));
|
||||
|
||||
test('Android:首次请求触发通道一次;再次调用不再打扰(幂等)', () async {
|
||||
var calls = 0;
|
||||
byteData.setMockMethodCallHandler(channel, (call) async {
|
||||
expect(call.method, 'requestPostNotifications');
|
||||
calls++;
|
||||
return 'granted';
|
||||
});
|
||||
final permission =
|
||||
NotificationPermission(isAndroid: true, channel: channel);
|
||||
|
||||
await permission.ensureRequested();
|
||||
await permission.ensureRequested();
|
||||
await permission.ensureRequested();
|
||||
|
||||
expect(calls, 1, reason: '进程内只请求一次');
|
||||
});
|
||||
|
||||
test('非 Android:不触通道(iOS 后台传输不依赖通知权限)', () async {
|
||||
var calls = 0;
|
||||
byteData.setMockMethodCallHandler(channel, (call) async {
|
||||
calls++;
|
||||
return 'granted';
|
||||
});
|
||||
final permission =
|
||||
NotificationPermission(isAndroid: false, channel: channel);
|
||||
|
||||
await permission.ensureRequested();
|
||||
|
||||
expect(calls, 0);
|
||||
});
|
||||
|
||||
test('通道缺失(iOS/桌面无此方法)→ 静默降级不抛', () async {
|
||||
byteData.setMockMethodCallHandler(
|
||||
channel,
|
||||
(call) async => throw MissingPluginException('no handler'),
|
||||
);
|
||||
final permission =
|
||||
NotificationPermission(isAndroid: true, channel: channel);
|
||||
|
||||
await permission.ensureRequested(); // 不抛即通过。
|
||||
});
|
||||
|
||||
test('通道异常后仍标记已请求(失败也不二次打扰)', () async {
|
||||
var calls = 0;
|
||||
byteData.setMockMethodCallHandler(
|
||||
channel,
|
||||
(call) async {
|
||||
calls++;
|
||||
throw PlatformException(code: 'ACTIVITY_MISSING');
|
||||
},
|
||||
);
|
||||
final permission =
|
||||
NotificationPermission(isAndroid: true, channel: channel);
|
||||
|
||||
await permission.ensureRequested();
|
||||
await permission.ensureRequested();
|
||||
|
||||
expect(calls, 1);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user