// cards_test.dart — 额度卡 / 智能选择推荐卡 行为 import 'package:flutter_test/flutter_test.dart'; import 'package:pangolin_vpn/l10n/strings_zh.dart'; import 'package:pangolin_vpn/state/quota_provider.dart'; import 'package:pangolin_vpn/widgets/pangolin_icons.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(); testWidgets('额度卡(移动·有余额):显示看广告加时按钮,点击回调', (tester) async { var watched = 0; await tester.pumpWidget(wrapThemed( QuotaCard(quota: const FreeQuotaState(), t: t, onWatchAd: () => watched++), )); await tester.pump(); expect(find.text(t.watchAdMore), findsOneWidget); await tester.tap(find.text(t.watchAdMore)); expect(watched, 1); }); testWidgets('额度卡(耗尽):显示今日已用完 + 看广告加时', (tester) async { await tester.pumpWidget(wrapThemed( QuotaCard(quota: const FreeQuotaState(remainingMinutes: 0), t: t, onWatchAd: () {}), )); await tester.pump(); expect(find.text(t.quotaUsedUp), findsOneWidget); expect(find.text(t.watchAdMore), findsOneWidget); }); testWidgets('额度卡(桌面·有余额):不显示加时按钮', (tester) async { await tester.pumpWidget(wrapThemed( QuotaCard(quota: const FreeQuotaState(), t: t, isDesktop: true, onWatchAd: () {}), )); await tester.pump(); expect(find.text(t.watchAdMore), findsNothing); }); testWidgets('推荐卡:展示推荐胶囊与文案,选中显示对勾', (tester) async { await tester.pumpWidget(wrapThemed( SmartSelectCard(t: t, selected: true, onTap: () {}), )); await tester.pump(); expect(find.text(t.smartSelect), findsOneWidget); expect(find.text(t.recommended), findsOneWidget); expect(find.text(t.smartSub), findsOneWidget); expect(find.byIcon(PangolinIcons.check), findsOneWidget); }); testWidgets('推荐卡:点击回调', (tester) async { var picked = 0; await tester.pumpWidget(wrapThemed( SmartSelectCard(t: t, selected: false, onTap: () => picked++), )); await tester.pump(); await tester.tap(find.text(t.smartSelect)); expect(picked, 1); }); }