f97ae8186b
对照 design/ui_kits mobile+tablet 原型逐屏补齐 Flutter 客户端: - l10n 资源层(strings_zh/en,单显)+ Riverpod 状态层(连接状态机/免费额度/ 节点选择/语言/主题),UI 与数据解耦,mock 数据接 API 不动 UI。 - 连接键严格三态(off 虚线轨道环 / connecting 旋转弧 / on 满环+计时+光晕), 状态来自 connectionProvider,点击只派发事件——禁止乐观显示。 - 节点页置顶「智能选择」推荐卡(clay 渐变 zap + 推荐胶囊,默认选中); 免费额度卡(剩余分钟+进度条 ≤3 分钟切 warning + 看广告解锁变绿)。 - Tab 左右滑动切换(手势竞技场仲裁,子页滚动不误触发,200ms 方向感知滑入)。 - iPad/宽屏 ≥900 LayoutBuilder 切侧栏分栏(导航行高 ≥48,连接页双栏/节点双列网格), 复用同一批原子组件,不 fork 页面。 - 语义 token 零硬编码;文案全部走 l10n;套餐数字对齐 §7;无支付表单/emoji 国旗。 - CI 红线词扫描扩展到 client/lib;新增 Flutter analyze+test CI 任务。 - 测试:连接状态机/额度/节点单测、连接键三态与卡片组件测试、 golden(连接键三态/推荐卡/额度卡 × 明暗)。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
72 lines
2.3 KiB
Dart
72 lines
2.3 KiB
Dart
// connection_controller_test.dart — 连接状态机:严格三态、禁乐观显示
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pangolin_vpn/state/connection_provider.dart';
|
|
|
|
void main() {
|
|
// 注入极短握手时长,用真实计时器走完状态流转。
|
|
ConnectionController make() => ConnectionController(handshake: const Duration(milliseconds: 20));
|
|
|
|
test('初始为 off', () {
|
|
final ctl = make();
|
|
expect(ctl.state.phase, VpnPhase.off);
|
|
ctl.dispose();
|
|
});
|
|
|
|
test('connect: off → connecting → on', () async {
|
|
final ctl = make();
|
|
ctl.connect();
|
|
expect(ctl.state.phase, VpnPhase.connecting);
|
|
await Future<void>.delayed(const Duration(milliseconds: 60));
|
|
expect(ctl.state.phase, VpnPhase.on);
|
|
ctl.dispose();
|
|
});
|
|
|
|
test('握手中再次 toggle 被忽略(禁止乐观回退)', () async {
|
|
final ctl = make();
|
|
ctl.toggle(); // off → connecting
|
|
expect(ctl.state.phase, VpnPhase.connecting);
|
|
ctl.toggle(); // connecting 中点击 → 仍 connecting
|
|
expect(ctl.state.phase, VpnPhase.connecting);
|
|
await Future<void>.delayed(const Duration(milliseconds: 60));
|
|
expect(ctl.state.phase, VpnPhase.on);
|
|
ctl.dispose();
|
|
});
|
|
|
|
test('on 态 toggle → off', () async {
|
|
final ctl = make();
|
|
ctl.connect();
|
|
await Future<void>.delayed(const Duration(milliseconds: 60));
|
|
expect(ctl.state.phase, VpnPhase.on);
|
|
ctl.toggle();
|
|
expect(ctl.state.phase, VpnPhase.off);
|
|
ctl.dispose();
|
|
});
|
|
|
|
test('已连接时切换节点 → 重连(回到 connecting)', () async {
|
|
final ctl = make();
|
|
ctl.connect();
|
|
await Future<void>.delayed(const Duration(milliseconds: 60));
|
|
expect(ctl.state.phase, VpnPhase.on);
|
|
ctl.onNodeChanged();
|
|
expect(ctl.state.phase, VpnPhase.connecting);
|
|
ctl.dispose();
|
|
});
|
|
|
|
test('on 态计时累加', () async {
|
|
final ctl = make();
|
|
ctl.connect();
|
|
await Future<void>.delayed(const Duration(milliseconds: 60));
|
|
expect(ctl.state.elapsed, Duration.zero);
|
|
await Future<void>.delayed(const Duration(milliseconds: 1100));
|
|
expect(ctl.state.elapsed.inSeconds, greaterThanOrEqualTo(1));
|
|
ctl.dispose();
|
|
});
|
|
|
|
test('off 态切换节点不会自动连接', () {
|
|
final ctl = make();
|
|
ctl.onNodeChanged();
|
|
expect(ctl.state.phase, VpnPhase.off);
|
|
ctl.dispose();
|
|
});
|
|
}
|