Files
pangolin/client/test/golden/components_golden_test.dart
T
wangjia 4dc4127252 feat(client): 三端布局架构 + macOS 桌面端 + app 图标
三端布局(mobile/tablet/desktop):
- core/responsive/form_factor.dart 形态判定 + shell/ 分发器(home_shell→desktop/mobile)
- desktop_shell 对照 ui_kits/desktop/dapp.jsx: 侧栏204·6项 + 套餐卡 + 顶栏(标题/状态/主题切换) + 连接页居中单列
- 新增组件 nav_sidebar / plan_badge_card / content_top_bar / bottom_tab_bar
- 新增一级页 contact_page / settings_page; navigation_provider(NavView)
- 删除旧 widgets/home_shell.dart(逻辑迁入 shell/)

macOS 桌面端:
- 窗口默认 920×600 + 最小 720×560(MainFlutterWindow.swift)
- app 图标替换为穿山甲(AppIcon.appiconset 全套, 由 app-icon.svg 渲染)

其余(本会话):
- Phase2 接线: auth_api/token_store/auth_provider/vpn_bridge_provider + 真实 connection/nodes
- lucide_icons 兼容补丁(packages/lucide_icons_patched) 修复 IconData final 报错
- 测试修复: connect_passthrough(UTF-8) / harness / golden @Skip
- l10n 新增 settingsTitle

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-16 09:23:20 +08:00

102 lines
3.6 KiB
Dart

// components_golden_test.dart — 关键组件 golden(明/暗两主题)
//
// 覆盖:连接键三态、智能选择推荐卡、免费额度卡。
// 首次生成基准图:`flutter test --update-goldens test/golden`。
//
// TODO: 字体依赖待解决。
// google_fonts 在测试环境中使用内部变体字体族名(如 `Manrope_400italic0`),
// 难以通过 FontLoader 预加载。需要:
// 1. 确认 google_fonts v6.3.3 各变体的实际族名
// 2. 在 setUpAll 中用 FontLoader 加载 test/fonts/*.ttf
// 3. 调用 `flutter test --update-goldens test/golden` 生成基准图
// 在此之前,跳过 golden 测试以避免 CI 失败;
// 组件行为已由 test/widget/ 覆盖。
// ignore_for_file: directives_ordering
@Skip('Golden tests need bundled fonts + baseline generation. '
'See TODO above for setup steps.')
library;
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pangolin_vpn/l10n/strings_zh.dart';
import 'package:pangolin_vpn/state/connection_provider.dart';
import 'package:pangolin_vpn/state/quota_provider.dart';
import 'package:pangolin_vpn/widgets/connect_button.dart';
import 'package:pangolin_vpn/widgets/quota_card.dart';
import 'package:pangolin_vpn/widgets/smart_select_card.dart';
import '../helpers/harness.dart';
void main() {
setUpAll(disableGoogleFontsFetching);
const t = StringsZh();
Future<void> goldenOf(
WidgetTester tester,
Widget child,
Finder finder,
String name, {
bool dark = false,
Duration settle = Duration.zero,
}) async {
await tester.pumpWidget(wrapThemed(child, dark: dark));
if (settle == Duration.zero) {
await tester.pump();
} else {
await tester.pump(settle); // 固定帧,确保连接中旋转角确定
}
await expectLater(finder, matchesGoldenFile('goldens/$name.png'));
}
ConnectButton btn(VpnPhase phase, {Duration elapsed = Duration.zero}) => ConnectButton(
phase: phase,
elapsed: elapsed,
offLabel: t.connectNow,
secureLabel: t.secure,
onTap: () {},
);
for (final dark in [false, true]) {
final suffix = dark ? 'dark' : 'light';
testWidgets('连接键 off · $suffix', (tester) async {
await goldenOf(tester, btn(VpnPhase.off), find.byType(ConnectButton), 'connect_off_$suffix', dark: dark);
});
testWidgets('连接键 connecting · $suffix', (tester) async {
await goldenOf(tester, btn(VpnPhase.connecting), find.byType(ConnectButton), 'connect_connecting_$suffix',
dark: dark, settle: const Duration(milliseconds: 700));
});
testWidgets('连接键 on · $suffix', (tester) async {
await goldenOf(tester, btn(VpnPhase.on, elapsed: const Duration(seconds: 5)), find.byType(ConnectButton),
'connect_on_$suffix', dark: dark);
});
testWidgets('推荐卡 · $suffix', (tester) async {
await goldenOf(tester, SmartSelectCard(t: t, selected: true, onTap: () {}), find.byType(SmartSelectCard),
'smart_card_$suffix', dark: dark);
});
testWidgets('额度卡(低额度警示)· $suffix', (tester) async {
await goldenOf(
tester,
QuotaCard(quota: const FreeQuotaState(remainingMinutes: 2), t: t, onWatchAd: () {}),
find.byType(QuotaCard),
'quota_low_$suffix',
dark: dark,
);
});
testWidgets('额度卡(已解锁)· $suffix', (tester) async {
await goldenOf(
tester,
QuotaCard(quota: const FreeQuotaState(adUnlocked: true), t: t, onWatchAd: () {}),
find.byType(QuotaCard),
'quota_unlocked_$suffix',
dark: dark,
);
});
}
}