fix(client): 补提交 stats-overhaul 漏掉的 account_api/kernel_process WIP
同 device_usage:account_api.dart(deviceUsage/usage 方法)、kernel_process.dart 及对应测试一直未提交,本地有→analyze/test 过,但不在 git→Windows 构建报 「deviceUsage isn't defined」。补齐使提交树自洽可构建。 孤儿组件 device_stat_row/metric_card 已无人引用,不提交。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -240,6 +240,53 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
// ── URLTest 延迟/组名提取 ─────────────────────────────────────
|
||||
group('URLTest extraction', () {
|
||||
final proxies = <String, dynamic>{
|
||||
'proxies': {
|
||||
'auto': {
|
||||
'type': 'URLTest',
|
||||
'all': ['reality-out', 'hy2-out'],
|
||||
},
|
||||
'reality-out': {
|
||||
'type': 'Vless',
|
||||
'history': [
|
||||
{'time': 't1', 'delay': 30},
|
||||
{'time': 't2', 'delay': 42},
|
||||
],
|
||||
},
|
||||
'hy2-out': {
|
||||
'type': 'Hysteria2',
|
||||
'history': [
|
||||
{'time': 't1', 'delay': 88},
|
||||
],
|
||||
},
|
||||
'direct': {'type': 'Direct'},
|
||||
},
|
||||
};
|
||||
|
||||
test('extractUrltestGroups 返回 URLTest/Fallback 组名', () {
|
||||
expect(ClashApiClient.extractUrltestGroups(proxies), ['auto']);
|
||||
});
|
||||
|
||||
test('extractUrltestResults 取成员最新 history delay', () {
|
||||
final r = ClashApiClient.extractUrltestResults(proxies);
|
||||
final byTag = {for (final e in r) e.tag: e.delayMs};
|
||||
expect(byTag['reality-out'], 42); // history.last
|
||||
expect(byTag['hy2-out'], 88);
|
||||
});
|
||||
|
||||
test('无 URLTest 组时返回空', () {
|
||||
final empty = {
|
||||
'proxies': {
|
||||
'direct': {'type': 'Direct'},
|
||||
},
|
||||
};
|
||||
expect(ClashApiClient.extractUrltestGroups(empty), isEmpty);
|
||||
expect(ClashApiClient.extractUrltestResults(empty), isEmpty);
|
||||
});
|
||||
});
|
||||
|
||||
// ── 2. 随机生成工具函数 ───────────────────────────────────────
|
||||
group('Port and secret generators', () {
|
||||
test('generateClashApiPort is in range 49152–65535', () {
|
||||
|
||||
@@ -11,6 +11,7 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pangolin_vpn/bridge/vpn_bridge_mock.dart';
|
||||
import 'package:pangolin_vpn/bridge/vpn_bridge_provider.dart';
|
||||
import 'package:pangolin_vpn/l10n/app_text.dart';
|
||||
import 'package:pangolin_vpn/models/device_usage.dart';
|
||||
import 'package:pangolin_vpn/models/me.dart';
|
||||
import 'package:pangolin_vpn/models/node.dart';
|
||||
import 'package:pangolin_vpn/models/usage_point.dart';
|
||||
@@ -73,6 +74,13 @@ final List<UsagePoint> _demoUsage = List.generate(30, (i) {
|
||||
);
|
||||
});
|
||||
|
||||
// 分设备用量演示数据(统计页「设备明细」section):三台设备,流量递减以验证占比条。
|
||||
const List<DeviceUsage> _demoDeviceUsage = [
|
||||
DeviceUsage(uuid: 'd1', name: 'iPhone 15', platform: 'ios', bytesUp: 1500 * 1024 * 1024, bytesDown: 9800 * 1024 * 1024, minutesUsed: 312),
|
||||
DeviceUsage(uuid: 'd2', name: 'MacBook Pro', platform: 'macos', bytesUp: 800 * 1024 * 1024, bytesDown: 5200 * 1024 * 1024, minutesUsed: 188),
|
||||
DeviceUsage(uuid: 'd3', name: 'Pixel 8', platform: 'android', bytesUp: 200 * 1024 * 1024, bytesDown: 1400 * 1024 * 1024, minutesUsed: 64),
|
||||
];
|
||||
|
||||
class _FakeNodesNotifier extends NodesNotifier {
|
||||
@override
|
||||
Future<List<Node>> build() async => _demoNodes;
|
||||
@@ -108,6 +116,7 @@ Future<void> _shoot(
|
||||
nodesProvider.overrideWith(_FakeNodesNotifier.new),
|
||||
meProvider.overrideWith(_FakeMeNotifier.new),
|
||||
usageProvider(30).overrideWith((ref) async => _demoUsage),
|
||||
deviceUsageProvider(30).overrideWith((ref) async => _demoDeviceUsage),
|
||||
],
|
||||
child: MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
|
||||
Reference in New Issue
Block a user