P0 - GC-SAVEDOG:更新改为整目录替换(旧文件备份到 .GC/update/backup, 失败可完整回滚),不再只搬一个 exe;回滚会删掉新包独有文件 - GC-SAVEDOG:包名校验放宽为单文件名模式,Linux 启动器(无扩展名)可更新 - GC-DOWNLOAD:测速全失败时不再回退 GitCode,改为返回「不可用」并保留上次可用源 - GC-DOWNLOAD:识别并赋予 Linux 无扩展名启动器可执行位;兼容脚本清理旧版时 也覆盖无扩展名产物 - CI:删除 nightly-prerelease(绕开 build.sh,产出无前端空壳);alpha 工作流 去掉非法 cron,只保留手动触发 P1 - 前端:主题设置真正生效(深色/浅色/跟随系统 + 持久化),去掉死字段 - 前端:下载页轮询改为自适应单次链,页面不可见或任务结束后降频/停止 - 前端:下载完成 / 删除模型后首页列表自动刷新 - 前端:复用 http.Client,不再每次轮询新建连接 - 后端:/api/models 走缓存,不再每次全盘递归统计体积 - 设置页:外部改动能同步进表单,不再只同步一次 P2 - 错误响应统一为 ErrorDto,不再复用 LaunchResultDto - 限流桶定期清理,避免无限增长 - 播放器窗口去重,避免同一模型重复开窗 - 封面按实际格式返回,去掉错误的 image/png 与 no-store - 端口集中到 GcUiContract,前端可用 GC_UI_PORT 或 ui-backend.json 发现后端 - 构建:Windows 包改为散开发布,与后端共用运行时(体积约 109MB -> 72MB) - 文档:更新仓库地址与更新流程说明 测试:dotnet build 全绿;GC.Tests 更新链路全通过;flutter analyze 无问题; flutter test 11 项全通过。
318 lines
11 KiB
Dart
318 lines
11 KiB
Dart
import 'dart:io';
|
|
import 'dart:ui' as ui;
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/rendering.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:gc_ui/api_client.dart';
|
|
import 'package:gc_ui/controller.dart';
|
|
import 'package:gc_ui/i18n.dart';
|
|
import 'package:gc_ui/pages.dart';
|
|
import 'package:gc_ui/shell.dart';
|
|
import 'package:gc_ui/theme.dart';
|
|
|
|
/// 视觉检查:把真实页面渲染成 PNG 写到 test/shots/。
|
|
///
|
|
/// 用 RepaintBoundary 直接取像素,不走 golden 比较器(避免网络图片阻塞)。
|
|
/// 测试环境默认用 Ahem 占位字体,这里显式加载系统中文字体,否则中文全是方块。
|
|
///
|
|
/// 运行(需要后端已在 127.0.0.1:17890 上跑起来):
|
|
/// flutter test tool/render_shots_test.dart
|
|
void main() {
|
|
setUpAll(() async {
|
|
HttpOverrides.global = null;
|
|
|
|
const candidates = <String>[
|
|
'/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc',
|
|
'/usr/share/fonts/truetype/noto/NotoSansCJK-Regular.ttc',
|
|
];
|
|
for (final path in candidates) {
|
|
final file = File(path);
|
|
if (!file.existsSync()) continue;
|
|
final bytes = file.readAsBytesSync();
|
|
final loader = FontLoader('Noto Sans CJK SC')
|
|
..addFont(Future<ByteData>.value(ByteData.view(bytes.buffer)));
|
|
await loader.load();
|
|
break;
|
|
}
|
|
});
|
|
|
|
SettingsInfo sampleSettings() => SettingsInfo.fromJson(<String, dynamic>{
|
|
'language': 'zh-CN',
|
|
'theme': 'dark',
|
|
'renderFps': 120,
|
|
'memoryMb': 2048,
|
|
'memoryAuto': true,
|
|
'autoUpdateOnStartup': true,
|
|
'requireSignedManifest': true,
|
|
'updateRepository': 'https://git.xhmcl.com/Morris/GC',
|
|
'memoryBudgetMb': 2048,
|
|
'memoryUsageText': '512 MB / 2048 MB',
|
|
'modelRoot': '/Users/morris/.GC/model',
|
|
'dataRoot': '/Users/morris/.GC/data',
|
|
'settingsFile': '/Users/morris/.GC/settings.json',
|
|
'version': '1.0.7',
|
|
'platform': 'osx-arm64',
|
|
'sources': <dynamic>[
|
|
<String, dynamic>{
|
|
'id': 'github',
|
|
'name': 'GitHub',
|
|
'url': 'https://github.com/Morris-GC/GC',
|
|
'enabled': true,
|
|
'builtIn': true,
|
|
'host': 'github.com',
|
|
},
|
|
<String, dynamic>{
|
|
'id': 'gitee',
|
|
'name': 'Gitee',
|
|
'url': 'https://gitee.com/morris/gc',
|
|
'enabled': true,
|
|
'builtIn': true,
|
|
'host': 'gitee.com',
|
|
},
|
|
],
|
|
'languages': <dynamic>[
|
|
<String, dynamic>{'code': 'zh-CN', 'label': '简体中文'},
|
|
<String, dynamic>{'code': 'en', 'label': 'English'},
|
|
],
|
|
});
|
|
|
|
List<ModelInfo> sampleModels() => <ModelInfo>[
|
|
ModelInfo.fromJson(<String, dynamic>{
|
|
'id': 'contour-map',
|
|
'name': '等高线地图',
|
|
'description': '把三维地形与等高线对应起来,识别山峰、山脊、山谷、鞍部与陡崖。',
|
|
'version': '1.0',
|
|
'author': 'Morris GC',
|
|
'sizeBytes': 147351,
|
|
'sizeText': '143.9 KB',
|
|
'tags': <dynamic>['地理', '地图', '等高线', '地形'],
|
|
'hasPreview': false,
|
|
}),
|
|
ModelInfo.fromJson(<String, dynamic>{
|
|
'id': 'solar-system',
|
|
'name': '太阳系',
|
|
'description': '观察八大行星的公转轨道与相对大小,理解日地月系统的尺度关系。',
|
|
'version': '1.2',
|
|
'author': 'Morris GC',
|
|
'sizeBytes': 2411724,
|
|
'sizeText': '2.3 MB',
|
|
'tags': <dynamic>['天文', '太阳系', '公转'],
|
|
'hasPreview': false,
|
|
}),
|
|
ModelInfo.fromJson(<String, dynamic>{
|
|
'id': 'earth-rotation',
|
|
'name': '地球自转',
|
|
'description': '用可交互的三维地球演示自转方向、昼夜交替与地方时差。',
|
|
'version': '1.1',
|
|
'author': 'Morris GC',
|
|
'sizeBytes': 1887436,
|
|
'sizeText': '1.8 MB',
|
|
'tags': <dynamic>['天文', '地球', '自转'],
|
|
'hasPreview': false,
|
|
}),
|
|
];
|
|
|
|
ShellController sampleController() => ShellController(api: GcApi())
|
|
..settings = sampleSettings()
|
|
..health = HealthInfo.fromJson(<String, dynamic>{
|
|
'ok': true,
|
|
'version': '1.0.7',
|
|
'platform': 'osx-arm64',
|
|
'uiAvailable': true,
|
|
});
|
|
|
|
Future<void> shoot(WidgetTester tester, String name, Widget page,
|
|
{Brightness brightness = Brightness.dark}) async {
|
|
tester.view.physicalSize = const Size(1280, 820);
|
|
tester.view.devicePixelRatio = 1.0;
|
|
addTearDown(tester.view.reset);
|
|
|
|
// GcColors 是静态取值,截图前先按目标亮度绑定,否则浅色截图仍是深色配色。
|
|
GcColors.bind(brightness);
|
|
|
|
final key = GlobalKey();
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
debugShowCheckedModeBanner: false,
|
|
theme: buildGcTheme(brightness).copyWith(
|
|
textTheme: buildGcTheme(brightness).textTheme.apply(
|
|
fontFamily: 'Noto Sans CJK SC',
|
|
),
|
|
),
|
|
home: RepaintBoundary(
|
|
key: key,
|
|
child: Scaffold(backgroundColor: GcColors.appBg, body: page),
|
|
),
|
|
),
|
|
);
|
|
await tester.pump(const Duration(milliseconds: 200));
|
|
// 页面里的数据来自真实后端(/api/about、/api/sources 等)。
|
|
// flutter_test 默认用假时钟,真实 HTTP 永远不会完成,所以这里用 runAsync
|
|
// 让出真实时间,等请求回来后再 pump 出最终画面。
|
|
await tester.runAsync(() async {
|
|
await Future<void>.delayed(const Duration(milliseconds: 1200));
|
|
});
|
|
await tester.pump(const Duration(milliseconds: 300));
|
|
await tester.runAsync(() async {
|
|
await Future<void>.delayed(const Duration(milliseconds: 600));
|
|
});
|
|
await tester.pump(const Duration(milliseconds: 300));
|
|
|
|
final boundary =
|
|
key.currentContext!.findRenderObject()! as RenderRepaintBoundary;
|
|
final image = await boundary.toImage(pixelRatio: 1.0);
|
|
final bytes = await image.toByteData(format: ui.ImageByteFormat.png);
|
|
|
|
final dir = Directory('test/shots')..createSync(recursive: true);
|
|
File('${dir.path}/$name.png').writeAsBytesSync(bytes!.buffer.asUint8List());
|
|
}
|
|
|
|
testWidgets('home', (tester) async {
|
|
I18n.language.value = 'zh-CN';
|
|
await shoot(
|
|
tester,
|
|
'home',
|
|
HomePageView(controller: sampleController(), initialModels: sampleModels()),
|
|
);
|
|
});
|
|
|
|
testWidgets('download', (tester) async {
|
|
I18n.language.value = 'zh-CN';
|
|
await shoot(
|
|
tester,
|
|
'download',
|
|
DownloadPageView(
|
|
controller: sampleController(),
|
|
initialSources: <SourceInfo>[
|
|
SourceInfo.fromJson(<String, dynamic>{
|
|
'id': 'github',
|
|
'name': 'GitHub',
|
|
'url': 'https://github.com/Morris-GC/GC',
|
|
'enabled': true,
|
|
'builtIn': true,
|
|
'host': 'github.com',
|
|
}),
|
|
SourceInfo.fromJson(<String, dynamic>{
|
|
'id': 'gitee',
|
|
'name': 'Gitee',
|
|
'url': 'https://gitee.com/morris/gc',
|
|
'enabled': true,
|
|
'builtIn': true,
|
|
'host': 'gitee.com',
|
|
}),
|
|
],
|
|
initialIndex: SourceIndexInfo.fromJson(<String, dynamic>{
|
|
'sourceId': 'github',
|
|
'root': 'https://github.com/Morris-GC/GC',
|
|
'fromCache': false,
|
|
'resolvedFrom': 'version.json',
|
|
'models': <dynamic>[
|
|
<String, dynamic>{
|
|
'id': 'solar-system',
|
|
'name': '太阳系',
|
|
'description': '观察八大行星的公转轨道与相对大小。',
|
|
'version': '1.2',
|
|
'sizeBytes': 2411724,
|
|
'sizeText': '2.3 MB',
|
|
'sourceId': 'github',
|
|
'installed': true,
|
|
'installedVersion': '1.2',
|
|
},
|
|
<String, dynamic>{
|
|
'id': 'earth-revolution',
|
|
'name': '地球公转',
|
|
'description': '演示公转轨道、四季成因与太阳直射点移动。',
|
|
'version': '1.0',
|
|
'sizeBytes': 2097152,
|
|
'sizeText': '2.0 MB',
|
|
'sourceId': 'github',
|
|
'installed': false,
|
|
},
|
|
<String, dynamic>{
|
|
'id': 'earth-geography',
|
|
'name': '地球地理',
|
|
'description': '经纬网、海陆分布与大洲大洋的交互式讲解。',
|
|
'version': '1.1',
|
|
'sizeBytes': 3145728,
|
|
'sizeText': '3.0 MB',
|
|
'sourceId': 'github',
|
|
'installed': false,
|
|
},
|
|
],
|
|
}),
|
|
initialJobs: <JobInfo>[
|
|
JobInfo.fromJson(<String, dynamic>{
|
|
'id': 'job-1',
|
|
'modelId': 'earth-revolution',
|
|
'name': '地球公转',
|
|
'version': '1.0',
|
|
'state': 'Downloading',
|
|
'progress': 0.42,
|
|
'statusText': '正在下载 42%',
|
|
'detailText': '860 KB / 2.0 MB',
|
|
'isActive': true,
|
|
}),
|
|
],
|
|
),
|
|
);
|
|
});
|
|
|
|
testWidgets('settings', (tester) async {
|
|
I18n.language.value = 'zh-CN';
|
|
await shoot(tester, 'settings', SettingsPageView(controller: sampleController()));
|
|
});
|
|
|
|
testWidgets('about', (tester) async {
|
|
I18n.language.value = 'zh-CN';
|
|
await shoot(
|
|
tester,
|
|
'about',
|
|
AboutPageView(
|
|
controller: sampleController(),
|
|
initialAbout: AboutInfo.fromJson(<String, dynamic>{
|
|
'appName': 'Morris GC',
|
|
'version': '1.0.7',
|
|
'platform': 'osx-arm64',
|
|
'repository': 'https://git.xhmcl.com/Morris/GC',
|
|
'sourceLanguage': 'C#',
|
|
'frontend': 'Flutter',
|
|
'contributors': <dynamic>[
|
|
<String, dynamic>{
|
|
'name': 'Morris',
|
|
'contributions': 25,
|
|
'avatarUrl': null,
|
|
},
|
|
],
|
|
}),
|
|
),
|
|
);
|
|
});
|
|
|
|
testWidgets('shell', (tester) async {
|
|
I18n.language.value = 'zh-CN';
|
|
await shoot(tester, 'shell', ShellPage(controller: sampleController()));
|
|
});
|
|
|
|
testWidgets('home-light', (tester) async {
|
|
I18n.language.value = 'zh-CN';
|
|
await shoot(
|
|
tester,
|
|
'home-light',
|
|
HomePageView(controller: sampleController(), initialModels: sampleModels()),
|
|
brightness: Brightness.light,
|
|
);
|
|
});
|
|
|
|
testWidgets('settings-light', (tester) async {
|
|
I18n.language.value = 'zh-CN';
|
|
await shoot(
|
|
tester,
|
|
'settings-light',
|
|
SettingsPageView(controller: sampleController()),
|
|
brightness: Brightness.light,
|
|
);
|
|
});
|
|
}
|