feat(mobile): UI-03 photos and share pages (17-20)
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
/// 照片管理网格 widget 测试(UI-01 §4.3)。
|
||||
/// 照片管理网格 widget 测试(UI-01 §4.3;UI-03 §4 页面 17 回归)。
|
||||
///
|
||||
/// 覆盖:网格列数(极窄 2 / 默认 3 / 宽屏 5)、状态角标(处理中/失败/
|
||||
/// 隐藏/删除)、scope 自适应(all 403 → own + 协作者提示)、游标加载第二
|
||||
/// 页、筛选 chips(服务端 visibility 重载 / 本地 processing 过滤)、空态。
|
||||
/// 覆盖:标题(计数 + 相册副标题)、网格列数(极窄 2 / 默认 3 / 宽屏 5)、
|
||||
/// 状态角标(处理中/失败/隐藏/删除,每张至多一个)、筛选 chips(选中=
|
||||
/// 主色蓝;服务端 visibility 重载 / 本地 processing 过滤)、scope 自适应
|
||||
/// (all 403 → own + 协作者提示)、游标加载第二页、尾格失败重试、空态、
|
||||
/// 点开大图查看器。
|
||||
library;
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
@@ -52,6 +54,32 @@ void main() {
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
}
|
||||
|
||||
testWidgets('标题:计数随筛选条目数 + 相册名做副标题', (tester) async {
|
||||
setSurface(tester, const Size(390, 844));
|
||||
final adapter = FakeAdapter((o) {
|
||||
if (o.path != '/v1/albums/alb-1/photos') {
|
||||
throw StateError('unexpected ${o.method} ${o.path}');
|
||||
}
|
||||
return (
|
||||
200,
|
||||
cursorPageBody(<Map<String, dynamic>>[
|
||||
adminPhotoJson(photoId: 'ph-t1', preview: photoPreviewJson()),
|
||||
adminPhotoJson(photoId: 'ph-t2', preview: photoPreviewJson()),
|
||||
adminPhotoJson(photoId: 'ph-t3', preview: photoPreviewJson()),
|
||||
]),
|
||||
);
|
||||
});
|
||||
await pumpPhotos(tester, clientOf(adapter));
|
||||
|
||||
// 计数 = 当前筛选下已加载条目数(游标接口无总量,不伪造总数)。
|
||||
expect(find.text('3 photos'), findsOneWidget);
|
||||
// 副标题 = 相册展示名(en 回退)。
|
||||
expect(find.text('Opening Gala'), findsOneWidget);
|
||||
|
||||
tester.view.resetPhysicalSize();
|
||||
tester.view.resetDevicePixelRatio();
|
||||
});
|
||||
|
||||
testWidgets('网格列数:350→2 / 390→3 / 800→5(平板按格宽扩列)', (tester) async {
|
||||
final adapter = FakeAdapter((o) {
|
||||
if (o.path != '/v1/albums/alb-1/photos') {
|
||||
@@ -224,6 +252,63 @@ void main() {
|
||||
'published',
|
||||
reason: 'Published 筛选下发服务端 visibility 参数',
|
||||
);
|
||||
// 选中 chip = 主色蓝底(UI-03 页面 17)。
|
||||
final chip = tester.widget<FilterChip>(
|
||||
find.widgetWithText(FilterChip, 'Published'),
|
||||
);
|
||||
expect(chip.selected, isTrue);
|
||||
expect(chip.selectedColor, Theme.of(tester.element(find.byType(FilterChip).first)).colorScheme.primary);
|
||||
|
||||
tester.view.resetPhysicalSize();
|
||||
tester.view.resetDevicePixelRatio();
|
||||
});
|
||||
|
||||
testWidgets('尾格:加载更多失败 → 可点重试 → 补齐第二页', (tester) async {
|
||||
setSurface(tester, const Size(390, 844));
|
||||
final page1 = List<Map<String, dynamic>>.generate(
|
||||
20,
|
||||
(i) => adminPhotoJson(
|
||||
photoId: 'ph-r${(i + 1).toString().padLeft(2, '0')}',
|
||||
preview: photoPreviewJson(),
|
||||
),
|
||||
);
|
||||
var cursorCalls = 0;
|
||||
final adapter = FakeAdapter((o) {
|
||||
if (o.path != '/v1/albums/alb-1/photos') {
|
||||
throw StateError('unexpected ${o.method} ${o.path}');
|
||||
}
|
||||
final cursor = o.uri.queryParameters['cursor'];
|
||||
if (cursor == null) {
|
||||
return (200, cursorPageBody(page1, nextCursor: 'rc1'));
|
||||
}
|
||||
cursorCalls++;
|
||||
// 第一次翻页失败(保留已加载条目),重试成功。
|
||||
if (cursorCalls == 1) {
|
||||
return (500, errorBody(ErrorCodes.internalError));
|
||||
}
|
||||
return (
|
||||
200,
|
||||
cursorPageBody(<Map<String, dynamic>>[
|
||||
adminPhotoJson(photoId: 'ph-r-page2', preview: photoPreviewJson()),
|
||||
]),
|
||||
);
|
||||
});
|
||||
await pumpPhotos(tester, clientOf(adapter));
|
||||
|
||||
// 滚到底触发翻页 → 失败 → 已加载条目保留 + 尾格显示重试入口。
|
||||
await tester.drag(find.byType(GridView), const Offset(0, -4000));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Failed to load more. Tap to retry'), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('grid-photo-ph-r20')), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('grid-photo-ph-r-page2')), findsNothing);
|
||||
|
||||
// 点重试 → 第二页补齐(重试入口消失、第二页条目可滚动到位)。
|
||||
await tester.tap(find.text('Failed to load more. Tap to retry'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Failed to load more. Tap to retry'), findsNothing);
|
||||
await tester.drag(find.byType(GridView), const Offset(0, -4000));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('grid-photo-ph-r-page2')), findsOneWidget);
|
||||
|
||||
tester.view.resetPhysicalSize();
|
||||
tester.view.resetDevicePixelRatio();
|
||||
|
||||
Reference in New Issue
Block a user