Files
openchamber-android-native/test/settings_screen_test.dart
T
blumia 2185054aab feat: split settings into category pages and add an about page
- the settings screen is now an index: 通用 → 聊天, 外观 → 主题 / 宠物,
  帮助与关于 → 关于; each row opens its own page, the controls moved
  there unchanged
- 关于 shows the app version, the server's OpenCode (/api/info) and
  OpenChamber (/api/version) versions with a refresh, and the open-source
  licenses, listed per package with their full text on tap
- the app version is read from the platform at startup
  (package_info_plus), so pubspec.yaml is the only place it is written;
  the pairing/relay handshake now sends it too instead of a constant that
  had drifted
2026-11-25 12:39:48 +08:00

91 lines
3.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);
// The category pages keep their controls off the index.
expect(find.text('主题模式'), findsNothing);
expect(find.byType(Switch), findsNothing);
});
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);
});
}