GC-UI:前后端分离,前端改用 Flutter(Windows/macOS)
- 新增 GC-UI/:backend(.NET 8 本地 HTTP API + 模型窗口宿主)与 frontend(Flutter 桌面应用) - 前端一套 Dart 代码 + windows/macos 两个原生 runner,共享全部界面逻辑 - 「关于」页新增「源码语言:C#」「前端:Flutter」两行,字段由 /api/about 下发 - 截图脚本覆盖首页/下载/设置/关于/外壳,需要真实后端时用 runAsync 等待请求 - README 补充平台选型理由、接口列表与截图用法
This commit is contained in:
1 parent
2f3a8682c9
commit
9ca99a1fe1
68 files changed
+7400
No files matched your search
@@ -0,0 +1,95 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:gc_ui/api_client.dart';
|
||||
|
||||
/// 前后端契约联调测试。
|
||||
///
|
||||
/// 需要 GC-UI 后端正在运行(`dotnet run --project GC-UI/backend/GC.UI.Server`)。
|
||||
/// 后端没起时整组跳过,不会让 CI 变红。
|
||||
///
|
||||
/// 注意:flutter_test 默认把所有 HTTP 请求拦成 400,这里显式放开真实网络。
|
||||
void main() {
|
||||
setUpAll(() {
|
||||
HttpOverrides.global = null;
|
||||
});
|
||||
|
||||
final api = GcApi(
|
||||
baseUrl: const String.fromEnvironment(
|
||||
'GC_UI_BASE_URL',
|
||||
defaultValue: 'http://127.0.0.1:17890',
|
||||
),
|
||||
);
|
||||
|
||||
Future<bool> backendUp() async {
|
||||
try {
|
||||
await api.health();
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
test('health / settings / models / sources / jobs 都能解析', () async {
|
||||
if (!await backendUp()) {
|
||||
markTestSkipped('后端未运行,跳过联调测试');
|
||||
return;
|
||||
}
|
||||
|
||||
final health = await api.health();
|
||||
expect(health.ok, isTrue);
|
||||
expect(health.version, isNotEmpty);
|
||||
expect(health.platform, isNotEmpty);
|
||||
|
||||
final settings = await api.settings();
|
||||
expect(settings.modelRoot, isNotEmpty);
|
||||
expect(settings.dataRoot, isNotEmpty);
|
||||
expect(settings.renderFps, greaterThan(0));
|
||||
expect(settings.memoryMb, greaterThan(0));
|
||||
expect(settings.languages, isNotEmpty);
|
||||
expect(settings.sources, isNotEmpty);
|
||||
|
||||
final models = await api.models();
|
||||
for (final model in models) {
|
||||
expect(model.id, isNotEmpty);
|
||||
expect(model.name, isNotEmpty);
|
||||
}
|
||||
|
||||
final sources = await api.sources();
|
||||
expect(sources, isNotEmpty);
|
||||
expect(sources.first.id, isNotEmpty);
|
||||
|
||||
final jobs = await api.jobs();
|
||||
expect(jobs, isA<List<JobInfo>>());
|
||||
});
|
||||
|
||||
test('设置补丁能写回并读出一致', () async {
|
||||
if (!await backendUp()) {
|
||||
markTestSkipped('后端未运行,跳过联调测试');
|
||||
return;
|
||||
}
|
||||
|
||||
final before = await api.settings();
|
||||
final updated = await api.saveSettings(
|
||||
SettingsPatch(renderFps: before.renderFps == 60 ? 90 : 60),
|
||||
);
|
||||
expect(updated.renderFps, before.renderFps == 60 ? 90 : 60);
|
||||
|
||||
final restored = await api.saveSettings(
|
||||
SettingsPatch(renderFps: before.renderFps),
|
||||
);
|
||||
expect(restored.renderFps, before.renderFps);
|
||||
});
|
||||
|
||||
test('越界路径被后端拒绝', () async {
|
||||
if (!await backendUp()) {
|
||||
markTestSkipped('后端未运行,跳过联调测试');
|
||||
return;
|
||||
}
|
||||
|
||||
await expectLater(
|
||||
api.openFolder('/etc'),
|
||||
throwsA(isA<ApiException>()),
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:gc_ui/api_client.dart';
|
||||
import 'package:gc_ui/i18n.dart';
|
||||
import 'package:gc_ui/theme.dart';
|
||||
|
||||
void main() {
|
||||
group('I18n', () {
|
||||
test('resolves auto to a supported language', () {
|
||||
expect(I18n.supported.contains(I18n.resolve('auto')), isTrue);
|
||||
expect(I18n.resolve('en-US'), 'en');
|
||||
expect(I18n.resolve('zh-CN'), 'zh-CN');
|
||||
});
|
||||
|
||||
test('translates keys and fills placeholders', () {
|
||||
I18n.language.value = 'zh-CN';
|
||||
expect(T('nav.home'), '主页');
|
||||
expect(T('home.count', <Object?>[3]), '3 个模型');
|
||||
|
||||
I18n.language.value = 'en';
|
||||
expect(T('nav.home'), 'Home');
|
||||
expect(T('home.count', <Object?>[3]), '3 models');
|
||||
});
|
||||
|
||||
test('falls back to the key for unknown entries', () {
|
||||
expect(T('does.not.exist'), 'does.not.exist');
|
||||
});
|
||||
});
|
||||
|
||||
group('SettingsPatch', () {
|
||||
test('only serialises the fields that were set', () {
|
||||
const patch = SettingsPatch(renderFps: 60, memoryAuto: false);
|
||||
expect(patch.toJson(), <String, dynamic>{
|
||||
'renderFps': 60,
|
||||
'memoryAuto': false,
|
||||
});
|
||||
});
|
||||
|
||||
test('empty patch serialises to an empty map', () {
|
||||
expect(const SettingsPatch().toJson(), isEmpty);
|
||||
});
|
||||
});
|
||||
|
||||
group('GcApi', () {
|
||||
test('builds model preview urls from the base url', () {
|
||||
final api = GcApi(baseUrl: 'http://127.0.0.1:17890');
|
||||
final model = ModelInfo.fromJson(<String, dynamic>{
|
||||
'id': 'solar-system',
|
||||
'name': '太阳系',
|
||||
'previewUrl': '/api/models/solar-system/preview',
|
||||
});
|
||||
expect(api.previewUrl(model),
|
||||
'http://127.0.0.1:17890/api/models/solar-system/preview');
|
||||
});
|
||||
|
||||
test('parses a model payload', () {
|
||||
final model = ModelInfo.fromJson(<String, dynamic>{
|
||||
'id': 'earth',
|
||||
'name': '地球',
|
||||
'version': '1.2.0',
|
||||
'sizeBytes': 1048576,
|
||||
'sizeText': '1.0 MB',
|
||||
'tags': <dynamic>['天文', '地球'],
|
||||
'hasPreview': true,
|
||||
});
|
||||
expect(model.id, 'earth');
|
||||
expect(model.tags, <String>['天文', '地球']);
|
||||
expect(model.metaText, 'v1.2.0 · 1.0 MB');
|
||||
});
|
||||
});
|
||||
|
||||
group('theme', () {
|
||||
testWidgets('renders a card with its child', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: buildGcTheme(),
|
||||
home: const Scaffold(
|
||||
body: GcCard(child: Text('hello')),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.text('hello'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user