- 将资料编辑页重构为可交互表单,支持昵称、签名编辑与头像更换 - 新增 DioClient 本地缓存读取与写入方法,支持离线读取策略快照 - 设备策略切换后自动使本地缓存失效,避免数据不一致 - Home Tab 切换时选中态跟随可见页面,滑动过程中实时更新底栏高亮 - 系统设置页引入 loading 遮罩层,防止切换开关时重复操作 - 个人资料页接入 profileController 展示真实用户信息与加载状态 - 适配深色模式,修正 home_tab 中头像与文字颜色硬编码问题
110 lines
3.9 KiB
Dart
110 lines
3.9 KiB
Dart
import 'package:cupertino_ui/cupertino_ui.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:liquid_glass_widgets/liquid_glass_widgets.dart'
|
|
show GlassTabBar;
|
|
import 'package:ttstd_family_care/app/app.dart';
|
|
import 'package:ttstd_family_care/features/home/presentation/home_page.dart';
|
|
import 'package:ttstd_family_care/features/home/presentation/home_tab_pager.dart';
|
|
|
|
void main() {
|
|
testWidgets('content and bottom bar drags move the page before release', (
|
|
tester,
|
|
) async {
|
|
final router = GoRouter(
|
|
initialLocation: '/home',
|
|
routes: [
|
|
StatefulShellRoute(
|
|
builder: (_, _, shell) => HomePage(navigationShell: shell),
|
|
navigatorContainerBuilder: (_, shell, children) =>
|
|
HomeTabPager(navigationShell: shell, children: children),
|
|
branches: [
|
|
for (final tab in ['home', 'manage', 'profile'])
|
|
StatefulShellBranch(
|
|
preload: true,
|
|
routes: [
|
|
GoRoute(
|
|
path: '/$tab',
|
|
builder: (_, _) => Center(child: Text(tab)),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
await tester.pumpWidget(buildApp(router));
|
|
await tester.pumpAndSettle();
|
|
|
|
final home = find.text('home');
|
|
final initialX = tester.getCenter(home).dx;
|
|
final gesture = await tester.startGesture(
|
|
tester.getCenter(home) + const Offset(200, 0),
|
|
);
|
|
await gesture.moveBy(const Offset(-30, 0));
|
|
await gesture.moveBy(const Offset(-460, 0));
|
|
await tester.pump();
|
|
expect(tester.getCenter(home).dx, lessThan(initialX));
|
|
expect(router.routeInformationProvider.value.uri.path, '/home');
|
|
expect(
|
|
tester.widget<GlassTabBar>(find.byType(GlassTabBar)).selectedIndex,
|
|
1,
|
|
);
|
|
|
|
// Reversing an unfinished swipe must restore the bar immediately.
|
|
await gesture.moveBy(const Offset(200, 0));
|
|
await tester.pump();
|
|
expect(
|
|
tester.widget<GlassTabBar>(find.byType(GlassTabBar)).selectedIndex,
|
|
0,
|
|
);
|
|
await gesture.moveBy(const Offset(-200, 0));
|
|
await tester.pump();
|
|
expect(
|
|
tester.widget<GlassTabBar>(find.byType(GlassTabBar)).selectedIndex,
|
|
1,
|
|
);
|
|
|
|
await gesture.up();
|
|
await tester.pumpAndSettle();
|
|
expect(router.routeInformationProvider.value.uri.path, '/manage');
|
|
expect(tester.getCenter(find.text('manage')).dx, closeTo(initialX, 1));
|
|
|
|
router.go('/profile');
|
|
await tester.pumpAndSettle();
|
|
expect(tester.getCenter(find.text('profile')).dx, closeTo(initialX, 1));
|
|
|
|
final profile = find.text('profile');
|
|
final bar = tester.getRect(find.byType(GlassTabBar));
|
|
final tabWidth = (bar.width - 40) / 3;
|
|
final tabDrag = await tester.startGesture(bar.center + Offset(tabWidth, 0));
|
|
await tabDrag.moveBy(const Offset(-24, 0));
|
|
await tabDrag.moveBy(Offset(24 - tabWidth * 0.7, 0));
|
|
await tester.pump();
|
|
expect(tester.getCenter(profile).dx, greaterThan(initialX));
|
|
expect(router.routeInformationProvider.value.uri.path, '/profile');
|
|
expect(
|
|
tester.widget<GlassTabBar>(find.byType(GlassTabBar)).selectedIndex,
|
|
1,
|
|
);
|
|
|
|
await tester.pump(const Duration(milliseconds: 200));
|
|
await tabDrag.up();
|
|
await tester.pumpAndSettle();
|
|
expect(router.routeInformationProvider.value.uri.path, '/manage');
|
|
expect(tester.getCenter(find.text('manage')).dx, closeTo(initialX, 1));
|
|
|
|
final tabBarBottom = tester.getRect(find.byType(GlassTabBar)).bottom;
|
|
addTearDown(tester.view.resetViewInsets);
|
|
tester.view.viewInsets = const FakeViewPadding(bottom: 280);
|
|
await tester.pumpAndSettle();
|
|
expect(tester.getRect(find.byType(GlassTabBar)).bottom, tabBarBottom);
|
|
tester.view.resetViewInsets();
|
|
await tester.pumpAndSettle();
|
|
expect(tester.getRect(find.byType(GlassTabBar)).bottom, tabBarBottom);
|
|
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
router.dispose();
|
|
});
|
|
}
|