// 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.watchAd), findsOneWidget);
    await tester.tap(find.text(t.watchAd));
    expect(watched, 1);
  });

  testWidgets('额度卡:已解锁显示已解锁文案', (tester) async {
    await tester.pumpWidget(wrapThemed(
      QuotaCard(quota: const FreeQuotaState(adUnlocked: true), t: t, onWatchAd: () {}),
    ));
    await tester.pump();
    expect(find.text(t.adUnlocked), findsOneWidget);
    expect(find.byIcon(PangolinIcons.checkCircle), findsOneWidget);
  });

  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);
  });
}
