Files
pipelines/app/test/features/terminal/terminal_chat_tab_test.dart
T
alan 214bbbc54f Remove Cupertino branches from terminal chat shell
Keep the existing Material terminal and chat-shell behavior while removing live Cupertino widgets, icon metadata, and alternate-host branches. Retain only the documented optional compatibility parameters until remaining callers migrate.
2026-11-11 20:05:55 +00:00

117 lines
4.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/screen.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_actions.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
import 'package:pipelines_app/features/terminal/terminal_hub.dart';
import 'package:pipelines_app/features/terminal/terminal_layout.dart';
import 'package:pipelines_app/features/terminal/terminal_surface.dart';
import 'package:pipelines_app/features/terminal/terminal_tab.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
import '../chat/conversation/chat_thread_fixtures.dart';
import 'terminal_app.dart';
import 'terminal_fixtures.dart';
class _Chats extends FakeChatGateway {
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type == 'chat_sessions') {
return Future.value({
'chat_sessions': [
for (final id in ['a', 'b']) {'id': id, 'title': 'Chat $id'},
],
});
}
if (type == 'chat_shells') return Future.value({'chat_shells': []});
return super.call(type, fields);
}
}
EditableText _composer(WidgetTester tester, String id) =>
tester.widget<EditableText>(
find.descendant(
of: find.byKey(ValueKey('chat-composer-$id')),
matching: find.byType(EditableText),
),
);
void main() {
testWidgets('Ctrl+Tab cycles chat panes while the terminal is hidden and '
'terminal tabs while it is shown; hiding returns to the composer', (
tester,
) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = const Size(1800, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final chats = _Chats()..history = (_) async => chatPage([]);
addTearDown(chats.close);
final mac = TerminalGateway()
..add('term_a', cwd: '/Users/op/src')
..add('term_b', cwd: '/Users/op/docs');
addTearDown(mac.close);
final hub = TerminalHub(TestMachines([machine('mac', mac)]));
addTearDown(hub.dispose);
final layout = TerminalLayout(store: MemoryLayoutStore());
await tester.pumpWidget(
MaterialApp(
home: TerminalSurface(
hub: hub,
layout: layout,
child: AdaptiveShell(
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) => ChatScreen(gateway: chats),
},
),
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
await tester.tap(
find.byWidgetPredicate(
(widget) =>
widget is SessionActionsButton && widget.session['id'] == 'b',
),
);
await tester.pumpAndSettle();
await tester.tap(find.text('Open to the right'));
await tester.pumpAndSettle();
final workspace = tester
.widget<ChatWorkspace>(find.byType(ChatWorkspace))
.controller;
expect(workspace.activePane?.sessionId, 'b');
// Hidden: Ctrl+Tab is the chat's.
await ctrlTab(tester);
expect(workspace.activePane?.sessionId, 'a');
expect(_composer(tester, 'a').focusNode.hasPrimaryFocus, isTrue);
// Shown: it moves between terminal tabs instead.
await altT(tester);
expect(terminalFocused(terminalKey('mac', 'term_a')), isTrue);
await ctrlTab(tester);
expect(hub.selected!.info.id, 'term_b');
expect(terminalFocused(terminalKey('mac', 'term_b')), isTrue);
expect(workspace.activePane?.sessionId, 'a');
await ctrlTab(tester, reverse: true);
expect(hub.selected!.info.id, 'term_a');
expect(workspace.activePane?.sessionId, 'a');
// Hidden again: the composer that had the keyboard gets it back, and
// Ctrl+Tab is the chat's once more.
await altT(tester);
expect(_composer(tester, 'a').focusNode.hasPrimaryFocus, isTrue);
await ctrlTab(tester);
expect(workspace.activePane?.sessionId, 'b');
expect(hub.selected!.info.id, 'term_a');
await tester.pumpWidget(const SizedBox.shrink());
});
}