Label machine provenance and choose server before chat harness
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/servers/server_catalog.dart';
|
||||
import 'package:pipelines_app/core/servers/server_catalog_store.dart';
|
||||
import 'package:pipelines_app/core/servers/server_context.dart';
|
||||
import 'package:pipelines_app/features/settings/server_connections.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart';
|
||||
import 'fake_chat_gateway.dart';
|
||||
import 'chat_test_harness.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'machine choice precedes harness discovery and target resumes once',
|
||||
(tester) async {
|
||||
final old = FakeChatGateway();
|
||||
final target = FakeChatGateway()
|
||||
..backendsHandler = () async => {
|
||||
'chat_backends': ['claude'],
|
||||
};
|
||||
final machines = ServerConnections(
|
||||
store: MemoryServerCatalogStore(
|
||||
catalog: ServerCatalog(
|
||||
servers: [
|
||||
SavedServer.validated(
|
||||
id: 'mac',
|
||||
name: 'My Mac',
|
||||
endpoints: ['ws://mac.test/ws'],
|
||||
),
|
||||
SavedServer.validated(
|
||||
id: 'linux',
|
||||
name: 'Linux',
|
||||
endpoints: ['ws://linux.test/ws'],
|
||||
),
|
||||
],
|
||||
selectedId: 'mac',
|
||||
),
|
||||
),
|
||||
onSelected: (_) async {},
|
||||
);
|
||||
await machines.load();
|
||||
Widget app(String id, FakeChatGateway gateway) => ServerContext(
|
||||
connections: machines,
|
||||
serverId: id,
|
||||
child: MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: ChatSessionsScreen(
|
||||
key: ValueKey(id),
|
||||
gateway: gateway,
|
||||
onOpen: (_) {},
|
||||
localStore: MemoryChatSessionLocalStore(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(app('mac', old));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('chat-new-chat')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('New chat on…'), findsOneWidget);
|
||||
expect(old.count('chat_backends'), 0);
|
||||
await tester.tap(find.text('Linux'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(machines.catalog.active?.id, 'linux');
|
||||
expect(old.count('chat_backends'), 0);
|
||||
expect(old.count('chat_create'), 0);
|
||||
expect(find.byKey(const Key('chat-create-confirm')), findsNothing);
|
||||
// Equivalent to Root constructing the connected target app after activation.
|
||||
await tester.pumpWidget(app('linux', target));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Linux · Start a chat'), findsOneWidget);
|
||||
expect(target.count('chat_backends'), 1);
|
||||
expect(old.count('chat_backends'), 0);
|
||||
expect(machines.newChatServerId, isNull);
|
||||
await tester.tap(find.text('Cancel'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pumpWidget(app('linux', target));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-create-confirm')), findsNothing);
|
||||
expect(target.count('chat_backends'), 1);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
machines.dispose();
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user