// quota_controller_test.dart — 免费额度状态机
import 'package:flutter_test/flutter_test.dart';
import 'package:pangolin_vpn/state/quota_provider.dart';

void main() {
  test('默认值:10 分钟总额 / 6 分钟剩余 / 未解锁', () {
    final ctl = QuotaController();
    expect(ctl.state.totalMinutes, 10);
    expect(ctl.state.remainingMinutes, 6);
    expect(ctl.state.adUnlocked, false);
  });

  test('progress = 剩余/总额', () {
    final ctl = QuotaController(const FreeQuotaState(totalMinutes: 10, remainingMinutes: 5));
    expect(ctl.state.progress, closeTo(0.5, 1e-9));
  });

  test('isLow:剩余 ≤3 分钟为真', () {
    expect(const FreeQuotaState(remainingMinutes: 3).isLow, true);
    expect(const FreeQuotaState(remainingMinutes: 4).isLow, false);
  });

  test('watchAd 解锁今日使用', () {
    final ctl = QuotaController();
    expect(ctl.state.adUnlocked, false);
    ctl.watchAd();
    expect(ctl.state.adUnlocked, true);
  });

  test('reset 回到未解锁初始态', () {
    final ctl = QuotaController()..watchAd();
    ctl.reset();
    expect(ctl.state.adUnlocked, false);
    expect(ctl.state.remainingMinutes, 6);
  });
}
