- 常规 now holds two pages: 通用 (the agent's tools and what it may know, as the web client's General page) and 聊天 (the follow-up behavior) - 通用 covers diagrams/prototypes, images with their model, secrets, notifications, memory with its background tidying (model and thinking level), project knowledge and usage limits - every switch reads and writes /api/config/settings, the same keys the web UI uses; keys the server does not store take its defaults - image models come from /api/model?types=image and the tidying model from the chat model list, both chosen in a sheet and clearable - bump to 0.5.0
119 lines
4.2 KiB
Dart
119 lines
4.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:openchamber/screens/settings_screen.dart';
|
|
import 'package:openchamber/state.dart';
|
|
|
|
void main() {
|
|
Future<AppState> pumpSettings(WidgetTester tester) async {
|
|
final app = AppState();
|
|
addTearDown(app.dispose);
|
|
await tester.pumpWidget(MaterialApp(home: SettingsScreen(app: app)));
|
|
return app;
|
|
}
|
|
|
|
testWidgets('settings is an index of categories, not one long page',
|
|
(tester) async {
|
|
await pumpSettings(tester);
|
|
|
|
expect(find.text('常规'), findsOneWidget);
|
|
expect(find.text('通用'), findsOneWidget);
|
|
expect(find.text('外观'), findsOneWidget);
|
|
expect(find.text('帮助与关于'), findsOneWidget);
|
|
expect(find.text('聊天'), findsOneWidget);
|
|
expect(find.text('主题'), findsOneWidget);
|
|
expect(find.text('宠物'), findsOneWidget);
|
|
expect(find.text('关于'), findsOneWidget);
|
|
|
|
// The category pages keep their controls off the index.
|
|
expect(find.text('主题模式'), findsNothing);
|
|
expect(find.byType(Switch), findsNothing);
|
|
});
|
|
|
|
testWidgets('通用 opens the agent-tool page with the web defaults',
|
|
(tester) async {
|
|
final app = await pumpSettings(tester);
|
|
app.memoryToolsAvailable = true;
|
|
await tester.pump();
|
|
|
|
await tester.tap(find.text('通用'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('在聊天中'), findsOneWidget);
|
|
expect(find.text('图表和原型'), findsOneWidget);
|
|
expect(find.text('密钥'), findsOneWidget);
|
|
expect(find.text('项目知识'), findsOneWidget);
|
|
expect(find.text('用量限额'), findsOneWidget);
|
|
|
|
SwitchListTile tile(String title) => tester
|
|
.widget<SwitchListTile>(find.widgetWithText(SwitchListTile, title));
|
|
// The same defaults the web client starts from.
|
|
expect(tile('图表和原型').value, isTrue);
|
|
expect(tile('图像').value, isFalse);
|
|
expect(tile('密钥').value, isTrue);
|
|
expect(tile('通知').value, isFalse);
|
|
expect(tile('记忆').value, isFalse);
|
|
expect(tile('项目知识').value, isTrue);
|
|
expect(tile('用量限额').value, isFalse);
|
|
});
|
|
|
|
testWidgets('聊天 opens the follow-up behavior page', (tester) async {
|
|
final app = await pumpSettings(tester);
|
|
|
|
await tester.tap(find.text('聊天'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('追问处理行为'), findsOneWidget);
|
|
ChoiceChip chip(String label) =>
|
|
tester.widget<ChoiceChip>(find.widgetWithText(ChoiceChip, label));
|
|
expect(chip('排队').selected, isTrue);
|
|
|
|
await tester.tap(find.text('转向'));
|
|
await tester.pumpAndSettle();
|
|
expect(app.followUpBehavior, 'steer');
|
|
expect(chip('转向').selected, isTrue);
|
|
expect(chip('排队').selected, isFalse);
|
|
});
|
|
|
|
testWidgets('主题 opens the theme page', (tester) async {
|
|
await pumpSettings(tester);
|
|
|
|
await tester.tap(find.text('主题'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('主题模式'), findsOneWidget);
|
|
expect(find.text('主题色'), findsOneWidget);
|
|
expect(find.text('跟随系统'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('宠物 opens the pet page', (tester) async {
|
|
await pumpSettings(tester);
|
|
|
|
await tester.tap(find.text('宠物'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('尚未导入宠物'), findsOneWidget);
|
|
expect(find.text('导入宠物包'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('关于 shows the app version, the server versions and licenses',
|
|
(tester) async {
|
|
await pumpSettings(tester);
|
|
|
|
await tester.tap(find.text('关于'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('版本'), findsOneWidget);
|
|
expect(find.text('未知'), findsOneWidget); // no platform version in a test
|
|
expect(find.text('开源许可'), findsOneWidget);
|
|
expect(find.widgetWithText(ListTile, 'OpenCode'), findsOneWidget);
|
|
// The header carries the name too, so look for the server row itself.
|
|
expect(find.widgetWithText(ListTile, 'OpenChamber'), findsOneWidget);
|
|
// No client: both server rows say so instead of showing a dash.
|
|
expect(find.text('未连接'), findsNWidgets(2));
|
|
|
|
await tester.tap(find.text('开源许可'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.textContaining('第三方组件'), findsOneWidget);
|
|
});
|
|
}
|