1340b477a7
- pangolin_theme: PangolinFonts 加 useBundled 开关 + sora/manrope/jetBrainsMono/ manropeTextTheme 封装(生产走 google_fonts / 测试走 bundled family); PangolinText 与 _build 改调封装,移除散落的 GoogleFonts 直接调用 - test/flutter_test_config.dart: 全测试前置,FontLoader 注册 test/fonts 真实 Sora/Manrope/JetBrainsMono + Lucide 图标字体,置 useBundled=true - 启用 test/golden(去 @Skip):连接键三态+推荐卡+额度卡×明暗 12 基准图 - tool/visual-diff.md: 标注 golden 严格闸已落地 测试: flutter test 76 通过(原 64+1skip → 76 无 skip), analyze 0 error Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
90 lines
3.2 KiB
Dart
90 lines
3.2 KiB
Dart
// components_golden_test.dart — 关键组件 golden(明/暗两主题)
|
|
//
|
|
// 覆盖:连接键三态、智能选择推荐卡、免费额度卡。
|
|
// 重新生成基准图:`flutter test --update-goldens test/golden`。
|
|
// 字体由 test/flutter_test_config.dart 经 FontLoader 注册 + PangolinFonts.useBundled
|
|
// 提供真实 Sora/Manrope/JetBrainsMono,无需 google_fonts 运行时拉取。
|
|
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,
|
|
);
|
|
});
|
|
}
|
|
}
|