feat(mobile): UI-03 theme calibration and account pages (01-04)
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
/// UI-01 主题一致性测试(Task 3)。
|
||||
///
|
||||
/// 覆盖:浅色 ColorScheme 方案 §3.1 精确值、深色语义对应值、字阶
|
||||
/// (22/17/16-14/13-12)、组件主题(按钮高 48/圆角 12、输入圆角 12、
|
||||
/// Dialog 圆角 16、BottomSheet 顶部圆角 16、AppBar titleLarge)、动效
|
||||
/// 令牌(含「减少动态效果」归零)。
|
||||
/// (UI-03 §3 校准:24/17/16-14/13-12)、组件主题(按钮高 48/圆角 12、
|
||||
/// 输入圆角 12、Dialog 圆角 16、BottomSheet 顶部圆角 16、AppBar
|
||||
/// titleLarge)、动效令牌(含「减少动态效果」归零)。
|
||||
library;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -57,8 +57,8 @@ void main() {
|
||||
group('字阶(随系统缩放:fontSize 走 TextScaler)', () {
|
||||
final textTheme = AppTheme.light.textTheme;
|
||||
|
||||
test('22 页面标题 / 17 分组 / 16-14 正文 / 13-12 辅助', () {
|
||||
expect(textTheme.titleLarge!.fontSize, 22);
|
||||
test('24 页面标题 / 17 分组 / 16-14 正文 / 13-12 辅助', () {
|
||||
expect(textTheme.titleLarge!.fontSize, 24);
|
||||
expect(textTheme.titleMedium!.fontSize, 17);
|
||||
expect(textTheme.bodyLarge!.fontSize, 16);
|
||||
expect(textTheme.bodyMedium!.fontSize, 14);
|
||||
@@ -67,7 +67,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('AppBar 标题用 titleLarge', () {
|
||||
expect(AppTheme.light.appBarTheme.titleTextStyle!.fontSize, 22);
|
||||
expect(AppTheme.light.appBarTheme.titleTextStyle!.fontSize, 24);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,453 @@
|
||||
/// UI-03 页面 01-04(登录/设置/修改密码/语言选择)重设计回归。
|
||||
///
|
||||
/// 覆盖:登录拼贴占位与 l10n 文案、密码显示/隐藏切换、键盘压缩布局、
|
||||
/// 登录页右上语言入口复用共享面板;设置账号摘要卡(首字母头像)、分组
|
||||
/// 与真实版本号、上传帮助面板、退出确认(有任务/无任务两态);修改密码
|
||||
/// 确认不匹配即时提示(修正新密码即清除)、提交中防重复;语言面板
|
||||
/// Done 提交/取消不改(各语言以自身语言书写)。
|
||||
library;
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:photo_live/app/locale_controller.dart';
|
||||
import 'package:photo_live/core/api_client.dart';
|
||||
import 'package:photo_live/core/error_codes.dart';
|
||||
import 'package:photo_live/core/session_store.dart';
|
||||
import 'package:photo_live/features/uploads/task_state.dart';
|
||||
import 'package:photo_live/features/uploads/task_store.dart';
|
||||
import 'package:photo_live/l10n/app_localizations.dart';
|
||||
import 'package:photo_live/pages/home_page.dart';
|
||||
import 'package:photo_live/pages/login_page.dart';
|
||||
import 'package:photo_live/pages/password_change_page.dart';
|
||||
|
||||
import '../helpers/fakes.dart';
|
||||
|
||||
void main() {
|
||||
late FakeSessionStore session;
|
||||
late TaskStore taskStore;
|
||||
|
||||
setUp(() {
|
||||
session = FakeSessionStore();
|
||||
taskStore = TaskStore.memory();
|
||||
});
|
||||
|
||||
ApiClient clientOf(FakeAdapter adapter) => ApiClient(
|
||||
sessionStore: session,
|
||||
dio: Dio(BaseOptions(baseUrl: 'http://test.local'))
|
||||
..httpClientAdapter = adapter,
|
||||
);
|
||||
|
||||
/// 登录页(默认 en;不触网——未提交不发请求)。
|
||||
Future<void> pumpLogin(WidgetTester tester, ApiClient client) async {
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [...pageTestOverrides(session: session, client: client)],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: const LoginPage(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
/// 主壳设置页签(IndexedStack 三页签同建:相册列表走空页兜底)。
|
||||
Future<ProviderContainer> pumpSettings(
|
||||
WidgetTester tester, {
|
||||
FakeLocaleStore? localeStore,
|
||||
AppLocaleChoice initialLocale = AppLocaleChoice.system,
|
||||
}) async {
|
||||
final adapter = FakeAdapter(
|
||||
(o) => o.path == '/v1/albums'
|
||||
? (200, cursorPageBody(<Map<String, dynamic>>[]))
|
||||
: throw StateError('unexpected ${o.path}'),
|
||||
);
|
||||
final store = localeStore ?? FakeLocaleStore();
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
...pageTestOverrides(
|
||||
session: session,
|
||||
taskStore: taskStore,
|
||||
client: clientOf(adapter),
|
||||
),
|
||||
localeSettingsProvider.overrideWith(
|
||||
() => LocaleSettings(initial: initialLocale, store: store),
|
||||
),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: const HomePage(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
// 切到设置页签(底部导航第三项;IndexedStack 默认在相册页签)。
|
||||
await tester.tap(find.byIcon(Icons.settings_outlined));
|
||||
await tester.pumpAndSettle();
|
||||
return ProviderScope.containerOf(
|
||||
tester.element(find.byType(HomePage)),
|
||||
);
|
||||
}
|
||||
|
||||
/// 修改密码页(推入命名路由,上级页面带 MARK)。
|
||||
Future<void> pumpPasswordChange(WidgetTester tester, ApiClient client) async {
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [apiClientProvider.overrideWith((ref) => client)],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: const Scaffold(body: Center(child: Text('MARK'))),
|
||||
routes: {
|
||||
'/password-change': (context) => const PasswordChangePage(),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
tester
|
||||
.state<NavigatorState>(find.byType(Navigator).first)
|
||||
.pushNamed('/password-change');
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
UploadTaskDraft makeDraft(String id) => UploadTaskDraft(
|
||||
id: id,
|
||||
accountId: 'staff01',
|
||||
albumId: 'alb-1',
|
||||
clientTaskId: 'ct-$id',
|
||||
sourceFilePath: '/tmp/$id.jpg',
|
||||
filename: '$id.jpg',
|
||||
bytes: 10,
|
||||
contentType: 'image/jpeg',
|
||||
);
|
||||
|
||||
/// 任务库写通知 → 200ms 防抖后角标计数生效。
|
||||
Future<void> pumpCounts(WidgetTester tester) async {
|
||||
await tester.pump(const Duration(milliseconds: 450));
|
||||
}
|
||||
|
||||
group('页面 01 登录', () {
|
||||
testWidgets('拼贴占位 + 主标题/说明/管理员提示均来自 l10n', (tester) async {
|
||||
await pumpLogin(tester, clientOf(FakeAdapter(
|
||||
(o) => throw StateError('不应发起请求: ${o.path}'))));
|
||||
|
||||
expect(find.byKey(const Key('login-collage')), findsOneWidget,
|
||||
reason: '拼贴渐变占位在场');
|
||||
expect(find.text('Your event. In focus.'), findsOneWidget);
|
||||
expect(
|
||||
find.text('Sign in to manage albums and photos'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Ask admin for account'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('密码显示/隐藏切换(Tooltip 语义 + obscureText 翻转)',
|
||||
(tester) async {
|
||||
await pumpLogin(tester, clientOf(FakeAdapter(
|
||||
(o) => throw StateError('不应发起请求: ${o.path}'))));
|
||||
|
||||
TextField passwordField() => tester.widget<TextField>(
|
||||
find.descendant(
|
||||
of: find.widgetWithText(TextFormField, 'Password'),
|
||||
matching: find.byType(TextField),
|
||||
),
|
||||
);
|
||||
expect(passwordField().obscureText, isTrue);
|
||||
expect(find.byTooltip('Show password'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byTooltip('Show password'));
|
||||
await tester.pump();
|
||||
expect(passwordField().obscureText, isFalse,
|
||||
reason: '切换后明文可见');
|
||||
expect(find.byTooltip('Hide password'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byTooltip('Hide password'));
|
||||
await tester.pump();
|
||||
expect(passwordField().obscureText, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('键盘开启 → 拼贴压缩(高度显著缩小,整页可滚动)', (tester) async {
|
||||
await pumpLogin(tester, clientOf(FakeAdapter(
|
||||
(o) => throw StateError('不应发起请求: ${o.path}'))));
|
||||
|
||||
final before = tester.getSize(find.byKey(const Key('login-collage')));
|
||||
tester.view.viewInsets = const FakeViewPadding(bottom: 420);
|
||||
addTearDown(tester.view.resetViewInsets);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final after = tester.getSize(find.byKey(const Key('login-collage')));
|
||||
expect(after.height, lessThan(before.height),
|
||||
reason: '键盘开启时拼贴压缩(28% → 10% 档)');
|
||||
expect(find.byKey(const Key('login-collage')), findsOneWidget,
|
||||
reason: '压缩而非移除');
|
||||
|
||||
// 表单仍可达(滚动到密码字段并聚焦)。
|
||||
await tester.ensureVisible(find.text('Password'));
|
||||
expect(find.text('Password'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('右上语言入口打开共享语言面板', (tester) async {
|
||||
await pumpLogin(tester, clientOf(FakeAdapter(
|
||||
(o) => throw StateError('不应发起请求: ${o.path}'))));
|
||||
|
||||
await tester.tap(find.text('EN'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Follow system'), findsOneWidget);
|
||||
expect(find.text('Done'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('失败 → 表单附近内联错误徽章', (tester) async {
|
||||
final adapter = FakeAdapter(
|
||||
(o) => o.path == '/v1/auth/password'
|
||||
? (401, errorBody(ErrorCodes.authInvalidCredentials))
|
||||
: throw StateError('unexpected ${o.path}'),
|
||||
);
|
||||
await pumpLogin(tester, clientOf(adapter));
|
||||
|
||||
await tester.enterText(
|
||||
find.widgetWithText(TextFormField, 'Account'),
|
||||
'staff01',
|
||||
);
|
||||
await tester.enterText(
|
||||
find.widgetWithText(TextFormField, 'Password'),
|
||||
'pw-123456',
|
||||
);
|
||||
await tester.tap(find.text('Sign in'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Incorrect account or password'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
|
||||
group('页面 02 设置', () {
|
||||
setUp(() {
|
||||
session.session = Session(
|
||||
token: 'tok-live-1',
|
||||
expiresAt: DateTime.utc(2099, 1, 1),
|
||||
account: 'staff01',
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('账号摘要卡:首字母头像 + 账号(非编辑入口)', (tester) async {
|
||||
await pumpSettings(tester);
|
||||
|
||||
expect(find.text('staff01'), findsOneWidget);
|
||||
expect(find.text('Currently signed-in account'), findsOneWidget);
|
||||
// 首字母头像占位(staff01 → S)。
|
||||
final avatarText = find.descendant(
|
||||
of: find.byType(CircleAvatar),
|
||||
matching: find.text('S'),
|
||||
);
|
||||
expect(avatarText, findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('分组标题在场 + 版本来自 kAppVersion', (tester) async {
|
||||
await pumpSettings(tester);
|
||||
|
||||
expect(find.text('Account'), findsOneWidget);
|
||||
expect(find.text('General'), findsOneWidget);
|
||||
expect(find.text(kAppVersion), findsOneWidget, reason: '真实版本号');
|
||||
expect(find.text('Language'), findsOneWidget);
|
||||
expect(find.text('Change password'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('上传帮助 → 底部面板展示系统限制说明', (tester) async {
|
||||
await pumpSettings(tester);
|
||||
|
||||
await tester.tap(find.text('Upload help'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('How background uploads work'), findsOneWidget);
|
||||
expect(
|
||||
find.textContaining('system keeps uploads running'),
|
||||
findsOneWidget,
|
||||
reason: '帮助正文说明系统限制,不承诺后台持续',
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('有进行中任务 → 退出确认明确任务保留', (tester) async {
|
||||
await pumpSettings(tester);
|
||||
final task = await taskStore.create(makeDraft('t-1'));
|
||||
await taskStore.updateState(task.id, UploadTaskState.queued);
|
||||
await pumpCounts(tester);
|
||||
|
||||
await tester.ensureVisible(find.text('Sign out'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Sign out'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
find.text(
|
||||
'Local upload tasks are preserved on this device and will '
|
||||
'resume when you sign back in.',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.tap(find.text('Cancel'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(session.session, isNotNull, reason: '取消不登出');
|
||||
});
|
||||
|
||||
testWidgets('无任务 → 退出确认为常规文案', (tester) async {
|
||||
await pumpSettings(tester);
|
||||
|
||||
await tester.ensureVisible(find.text('Sign out'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Sign out'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
find.text('You will be signed out on this device.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('页面 03 修改密码', () {
|
||||
setUp(() {
|
||||
session.session = Session(
|
||||
token: 'tok-live-1',
|
||||
expiresAt: DateTime.utc(2099, 1, 1),
|
||||
account: 'staff01',
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('确认不匹配即时提示;修正新密码即清除', (tester) async {
|
||||
await pumpPasswordChange(
|
||||
tester,
|
||||
clientOf(FakeAdapter((o) => throw StateError('不应发起请求'))),
|
||||
);
|
||||
|
||||
await tester.enterText(
|
||||
find.widgetWithText(TextFormField, 'New password'),
|
||||
'brand-new-pass-9',
|
||||
);
|
||||
await tester.enterText(
|
||||
find.widgetWithText(TextFormField, 'Confirm new password'),
|
||||
'different-pass-9',
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('New passwords do not match'), findsOneWidget,
|
||||
reason: '输入即校验,不等提交');
|
||||
|
||||
// 修正新密码(与确认一致)→ 监听器复验清除错误。
|
||||
await tester.enterText(
|
||||
find.widgetWithText(TextFormField, 'New password'),
|
||||
'different-pass-9',
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.text('New passwords do not match'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('提交中按钮禁用(防重复提交)', (tester) async {
|
||||
final gate = Completer<void>();
|
||||
final adapter = FakeAdapter((o) async {
|
||||
await gate.future;
|
||||
return (204, null);
|
||||
});
|
||||
await pumpPasswordChange(tester, clientOf(adapter));
|
||||
|
||||
await tester.enterText(
|
||||
find.widgetWithText(TextFormField, 'Current password'),
|
||||
'old-pass-123',
|
||||
);
|
||||
await tester.enterText(
|
||||
find.widgetWithText(TextFormField, 'New password'),
|
||||
'brand-new-pass-9',
|
||||
);
|
||||
await tester.enterText(
|
||||
find.widgetWithText(TextFormField, 'Confirm new password'),
|
||||
'brand-new-pass-9',
|
||||
);
|
||||
await tester.tap(find.widgetWithText(FilledButton, 'Save password'));
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
|
||||
expect(find.byType(CircularProgressIndicator), findsOneWidget);
|
||||
await tester.tap(
|
||||
find.byType(FilledButton),
|
||||
warnIfMissed: false,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
expect(adapter.requests, hasLength(1), reason: '加载中不重复提交');
|
||||
|
||||
gate.complete();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('MARK'), findsOneWidget, reason: '成功后 pop 回上级');
|
||||
});
|
||||
});
|
||||
|
||||
group('页面 04 语言选择(共享面板)', () {
|
||||
setUp(() {
|
||||
session.session = Session(
|
||||
token: 'tok-live-1',
|
||||
expiresAt: DateTime.utc(2099, 1, 1),
|
||||
account: 'staff01',
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('各语言以自身语言书写 + Done 提交(持久化 + 即刻刷新)',
|
||||
(tester) async {
|
||||
final store = FakeLocaleStore();
|
||||
final container = await pumpSettings(
|
||||
tester,
|
||||
localeStore: store,
|
||||
initialLocale: AppLocaleChoice.system,
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Language'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// 各语言以自身语言书写(不随当前界面语言变化)。
|
||||
// 「Follow system」两次:语言行尾当前值 + 弹层选项。
|
||||
expect(find.text('Follow system'), findsNWidgets(2));
|
||||
expect(find.text('English'), findsOneWidget);
|
||||
expect(find.text('中文'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('中文'));
|
||||
await tester.pump();
|
||||
expect(store.writes, isEmpty, reason: 'Done 前不写持久层');
|
||||
await tester.tap(find.text('Done'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(container.read(localeSettingsProvider), AppLocaleChoice.zh);
|
||||
expect(store.writes, ['zh'], reason: 'Done 才写持久层');
|
||||
// 本 harness 的 MaterialApp 不随 provider 重接 locale(live 全 App
|
||||
// 重建在 app/locale_test.dart 覆盖);此处断言行尾当前值更新。
|
||||
expect(find.text('中文'), findsOneWidget, reason: '语言行尾更新为中文');
|
||||
expect(find.byType(IndexedStack), findsOneWidget,
|
||||
reason: '语言刷新不重建页签结构');
|
||||
});
|
||||
|
||||
testWidgets('取消(外部点击关闭)不改变语言偏好', (tester) async {
|
||||
final store = FakeLocaleStore();
|
||||
final container = await pumpSettings(
|
||||
tester,
|
||||
localeStore: store,
|
||||
initialLocale: AppLocaleChoice.system,
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Language'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('English'));
|
||||
await tester.pump();
|
||||
|
||||
// 点击面板外(屏障)关闭 = 取消。
|
||||
await tester.tapAt(const Offset(20, 20));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(container.read(localeSettingsProvider), AppLocaleChoice.system,
|
||||
reason: '未提交不改档位');
|
||||
expect(store.writes, isEmpty, reason: '取消不写持久层');
|
||||
expect(find.text('设置'), findsNothing, reason: '界面保持英文');
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -86,7 +86,7 @@ void main() {
|
||||
await pumpOverMarker(tester, clientOf(adapter));
|
||||
|
||||
await fill(tester, newPw: 'short7', confirmPw: 'short7');
|
||||
await tester.tap(find.widgetWithText(FilledButton, 'Change password'));
|
||||
await tester.tap(find.widgetWithText(FilledButton, 'Save password'));
|
||||
await tester.pump();
|
||||
|
||||
expect(
|
||||
@@ -102,7 +102,7 @@ void main() {
|
||||
await pumpOverMarker(tester, clientOf(adapter));
|
||||
|
||||
await fill(tester, confirmPw: 'different-pass-9');
|
||||
await tester.tap(find.widgetWithText(FilledButton, 'Change password'));
|
||||
await tester.tap(find.widgetWithText(FilledButton, 'Save password'));
|
||||
await tester.pump();
|
||||
|
||||
expect(
|
||||
@@ -122,7 +122,7 @@ void main() {
|
||||
await pumpOverMarker(tester, clientOf(adapter));
|
||||
|
||||
await fill(tester);
|
||||
await tester.tap(find.widgetWithText(FilledButton, 'Change password'));
|
||||
await tester.tap(find.widgetWithText(FilledButton, 'Save password'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Current password is incorrect'), findsOneWidget);
|
||||
@@ -141,7 +141,7 @@ void main() {
|
||||
await pumpOverMarker(tester, clientOf(adapter));
|
||||
|
||||
await fill(tester);
|
||||
await tester.tap(find.widgetWithText(FilledButton, 'Change password'));
|
||||
await tester.tap(find.widgetWithText(FilledButton, 'Save password'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final req = adapter.requests.single;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
/// 设置页 widget 测试(P3 计划 Task 3)。
|
||||
/// 设置页 widget 测试(P3 Task 3;UI-03 页面 02 重设计后更新)。
|
||||
///
|
||||
/// 覆盖:修改密码入口跳 /password-change;退出登录 → 调 api.logout
|
||||
/// (尽力而为)→ 清空本地会话 → 清栈回 /login。
|
||||
/// 覆盖:修改密码入口跳 /password-change;退出登录(有进行中任务 →
|
||||
/// 确认弹窗任务保留说明)→ 调 api.logout(尽力而为)→ 清空本地会话 →
|
||||
/// 清栈回 /login;账号摘要卡 + 通用分组 + 上传帮助面板 + 版本;
|
||||
/// 语言行打开共享面板 Done 提交。
|
||||
library;
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
@@ -11,6 +13,8 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:photo_live/app/locale_controller.dart';
|
||||
import 'package:photo_live/core/api_client.dart';
|
||||
import 'package:photo_live/core/session_store.dart';
|
||||
import 'package:photo_live/features/uploads/task_state.dart';
|
||||
import 'package:photo_live/features/uploads/task_store.dart';
|
||||
import 'package:photo_live/l10n/app_localizations.dart';
|
||||
import 'package:photo_live/pages/home_page.dart';
|
||||
import 'package:photo_live/pages/login_page.dart';
|
||||
@@ -39,6 +43,7 @@ void main() {
|
||||
Future<void> pumpHome(
|
||||
WidgetTester tester,
|
||||
ApiClient client, {
|
||||
TaskStore? taskStore,
|
||||
List<dynamic> extraOverrides = const <dynamic>[],
|
||||
}) async {
|
||||
await tester.pumpWidget(
|
||||
@@ -46,7 +51,11 @@ void main() {
|
||||
// Task 9 起主壳含队列页(触达 sessionAccountProvider/TaskStore),
|
||||
// 真实平台通道在测试环境挂起,必须注入替身。
|
||||
overrides: [
|
||||
...pageTestOverrides(session: store, client: client),
|
||||
...pageTestOverrides(
|
||||
session: store,
|
||||
taskStore: taskStore,
|
||||
client: client,
|
||||
),
|
||||
...extraOverrides,
|
||||
],
|
||||
child: MaterialApp(
|
||||
@@ -85,9 +94,26 @@ void main() {
|
||||
if (o.path == '/v1/albums') return (500, errorBody('INTERNAL_ERROR'));
|
||||
throw StateError('unexpected ${o.path}');
|
||||
});
|
||||
await pumpHome(tester, clientOf(adapter));
|
||||
// 一个排队中任务:退出确认走「任务保留」文案(UI-03 有任务分支)。
|
||||
final taskStore = TaskStore.memory();
|
||||
final task = await taskStore.create(UploadTaskDraft(
|
||||
id: 't-1',
|
||||
accountId: 'staff01',
|
||||
albumId: 'alb-1',
|
||||
clientTaskId: 'ct-t-1',
|
||||
sourceFilePath: '/tmp/t-1.jpg',
|
||||
filename: 't-1.jpg',
|
||||
bytes: 10,
|
||||
contentType: 'image/jpeg',
|
||||
));
|
||||
await taskStore.updateState(task.id, UploadTaskState.queued);
|
||||
await pumpHome(tester, clientOf(adapter), taskStore: taskStore);
|
||||
// 等任务计数防抖载入(未结束任务 → 退出确认带保留说明)。
|
||||
await tester.pump(const Duration(milliseconds: 450));
|
||||
|
||||
// 点列表项 → 先弹确认(§4.5:明确本机任务保留,不承诺后台继续)。
|
||||
// 点列表项 → 先弹确认(明确本机任务保留,不承诺后台继续)。
|
||||
await tester.ensureVisible(find.text('Sign out'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Sign out'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Sign out?'), findsOneWidget);
|
||||
@@ -116,46 +142,44 @@ void main() {
|
||||
expect(find.byType(HomePage), findsNothing, reason: '主壳已出栈');
|
||||
});
|
||||
|
||||
testWidgets('设置分组:账号/语言/安全/上传帮助/关于(UI-01 §4.5)',
|
||||
testWidgets('账号摘要卡 + 通用分组 + 上传帮助面板 + 版本(UI-03 页面 02)',
|
||||
(tester) async {
|
||||
final adapter = FakeAdapter((_) => throw StateError('不应发起请求'));
|
||||
// 分组列表长于默认 800×600 视口(「关于」在折叠线下不可建树)。
|
||||
tester.view.physicalSize = const Size(800, 1600);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await pumpHome(tester, clientOf(adapter));
|
||||
|
||||
// 五个分组标题(SectionHeader 文案)。
|
||||
for (final section in [
|
||||
'Account',
|
||||
'Language',
|
||||
'Security',
|
||||
'Upload help',
|
||||
'About',
|
||||
]) {
|
||||
// 两个分组标题(SectionHeader 文案)。
|
||||
for (final section in ['Account', 'General']) {
|
||||
expect(find.text(section), findsOneWidget, reason: '分组「$section」');
|
||||
}
|
||||
|
||||
// 账号分组:当前账号 + 说明副标题。
|
||||
// 账号摘要卡:当前账号 + 说明副标题(非编辑入口)。
|
||||
expect(find.text('staff01'), findsOneWidget);
|
||||
expect(find.text('Currently signed-in account'), findsOneWidget);
|
||||
expect(find.descendant(
|
||||
of: find.byType(CircleAvatar),
|
||||
matching: find.text('S'),
|
||||
), findsOneWidget, reason: '首字母头像占位');
|
||||
|
||||
// 上传帮助:展开后说明系统限制 / 强退 / 网络等待三分态(不承诺
|
||||
// 通用分组四行。
|
||||
expect(find.text('Language'), findsOneWidget);
|
||||
expect(find.text('Change password'), findsOneWidget);
|
||||
expect(find.text('Upload help'), findsOneWidget);
|
||||
expect(find.text('Version'), findsOneWidget);
|
||||
expect(find.text(kAppVersion), findsOneWidget);
|
||||
|
||||
// 上传帮助:底部面板说明系统限制 / 强退 / 网络等待(不承诺
|
||||
// 「后台上传已开启」)。
|
||||
await tester.tap(find.text('How background uploads work'));
|
||||
await tester.tap(find.text('Upload help'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('How background uploads work'), findsOneWidget);
|
||||
expect(find.textContaining('battery limits'), findsOneWidget);
|
||||
expect(
|
||||
find.textContaining('start automatically once a connection is available'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
// 关于分组:版本 tile。
|
||||
expect(find.text('Version'), findsOneWidget);
|
||||
expect(find.text(kAppVersion), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('语言切换:底部弹层三选一 → 更新档位 + 持久化(P3 Task 10)',
|
||||
testWidgets('语言切换:共享面板临时选中 + Done 提交 → 更新档位 + 持久化',
|
||||
(tester) async {
|
||||
final adapter = FakeAdapter((_) => throw StateError('不应发起请求'));
|
||||
final localeStore = FakeLocaleStore();
|
||||
@@ -171,23 +195,32 @@ void main() {
|
||||
|
||||
// 本 harness 的 MaterialApp 固定 en(live 全 App 重建在
|
||||
// app/locale_test.dart 的 PhotoLiveApp 用例覆盖)。
|
||||
expect(find.text('Language'), findsOneWidget, reason: '语言分组标题');
|
||||
expect(find.text('Follow system'), findsOneWidget, reason: '默认档位行标题');
|
||||
expect(find.text('Language'), findsOneWidget, reason: '语言行标题');
|
||||
expect(
|
||||
find.text('Follow system'),
|
||||
findsOneWidget,
|
||||
reason: '默认档位(行尾当前值)',
|
||||
);
|
||||
|
||||
// 行标题即当前档位,点它打开弹层。
|
||||
await tester.tap(find.text('Follow system'));
|
||||
// 点语言行打开共享弹层。
|
||||
await tester.tap(find.text('Language'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// 弹层三选项(语言名以自身语言书写,跨 locale 不变)。
|
||||
// 「Follow system」出现两次:主档行标题 + 弹层选项。
|
||||
// 「Follow system」出现两次:语言行尾当前值 + 弹层选项。
|
||||
expect(find.text('Follow system'), findsNWidgets(2));
|
||||
expect(find.text('中文'), findsOneWidget);
|
||||
expect(find.text('English'), findsOneWidget);
|
||||
expect(find.text('Done'), findsOneWidget);
|
||||
|
||||
// 临时选中 + Done 提交(未 Done 前不落档位)。
|
||||
await tester.tap(find.text('中文'));
|
||||
await tester.pump();
|
||||
expect(localeStore.writes, isEmpty, reason: 'Done 前不写持久层');
|
||||
await tester.tap(find.text('Done'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('中文'), findsOneWidget, reason: '行标题更新为当前档位');
|
||||
expect(find.text('中文'), findsOneWidget, reason: '行尾更新为当前档位');
|
||||
expect(localeStore.writes, ['zh'], reason: '选择写入 app.locale');
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user