b461a476a2
四端共享 Dart 实现,配合 #21 后端账户级卡控: - me.dart: 加 quota_cap_min(当日总额度 = daily + 看广告 bonus,进度条分母)。 - quota_provider: total 取 quotaCapMin;isExhausted;markExhausted(倒计时归零本地置耗尽 + 登录态拉 me 校准);watchAd() async 调 /ads/unlock(占位 ad_token=uuid)→ 刷新 me,返回 granted。 - connection_provider: 连接时锁定 _freeRemainingSec(会员 null 不倒计时);复用 elapsed 计时器 每 tick 算 freeCountdown,归零 → _onFreeQuotaExhausted(主动切断不报节点异常 + markExhausted); 倒计时用墙上时钟(后台漏跳回前台补上、准时切);连接遇后端 QUOTA_EXHAUSTED 兜底置耗尽。 - connect_button: enabled/onDisabledTap —— 额度耗尽 off 态灰化(锁图标),点击弹加时。 - quota_card: 三态(连接倒计时 mm:ss / 未连接剩余分钟 / 耗尽今日已用完);移动「看广告加时」、桌面「升级会员」。 - ad_reward_dialog(新): 移动端占位广告(播放中→3s→加时→奖励);桌面版硬 10 分钟提示去移动端/升级。 - l10n(zh/en): 倒计时/已用完/看广告加时/占位广告/桌面升级 双语。 - 测试: quota isExhausted/markExhausted;连接倒计时归零自动切断+置耗尽(注入时钟); 额度卡三态 widget;/me 契约含 quota_cap_min;golden 更新(Linux 权威基线 quota_low/exhausted)。 - 文档: docs/free-quota-ad.html + 登记 docs/index.html。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
64 lines
2.3 KiB
Dart
64 lines
2.3 KiB
Dart
// 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);
|
|
});
|
|
}
|