Merge main into open in chat

This commit is contained in:
2026-11-13 12:38:27 +00:00
14 changed files with 203 additions and 79 deletions
@@ -12,12 +12,17 @@ import 'package:pipelines_app/shell/destination.dart';
import 'conversation/chat_thread_fixtures.dart';
class _Gateway extends FakeChatGateway {
_Gateway({this.rows = const ['a', 'b', 'c']});
final List<String> rows;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type == 'chat_sessions') {
return Future.value({
'chat_sessions': [
for (final id in ['a', 'b', 'c']) {'id': id, 'title': 'Chat $id'},
for (final id in rows)
{'id': id, 'title': 'Chat $id', if (id == 'closed') 'closed_at': 1},
],
});
}
@@ -57,12 +62,16 @@ Future<void> _chord(
await tester.pumpAndSettle();
}
Future<void> _setup(WidgetTester tester, {bool open = true}) async {
Future<void> _setup(
WidgetTester tester, {
bool open = true,
List<String> rows = const ['a', 'b', 'c'],
}) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = const Size(1800, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final gateway = _Gateway()..history = (_) async => chatPage([]);
final gateway = _Gateway(rows: rows)..history = (_) async => chatPage([]);
addTearDown(gateway.close);
await tester.pumpWidget(
MaterialApp(
@@ -133,20 +142,44 @@ void main() {
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('single pane with no shown window does nothing; empty workspace '
'does not consume', (tester) async {
await _setup(tester, open: false);
await _chord(tester);
expect(find.byType(ChatWorkspace), findsNothing);
testWidgets(
'single pane cycles list chats; empty workspace does not consume',
(tester) async {
await _setup(tester, open: false);
await _chord(tester);
expect(find.byType(ChatWorkspace), findsNothing);
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
_focusSidebar(tester);
await tester.pumpAndSettle();
await _chord(tester);
expect(find.byType(ChatWorkspace), findsOneWidget);
expect(_workspace(tester).paneCount, 1);
expect(_workspace(tester).activePane?.sessionId, 'b');
expect(_editable(tester, 'b').focusNode.hasPrimaryFocus, isTrue);
await tester.pumpWidget(const SizedBox.shrink());
},
);
testWidgets('single pane skips closed and hidden-on-this-device chats', (
tester,
) async {
await _setup(tester, open: false, rows: ['a', 'hidden', 'c', 'closed']);
await tester.tap(_actions('hidden'));
await tester.pumpAndSettle();
await tester.tap(find.text('Hide on this device'));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
_focusSidebar(tester);
await tester.pumpAndSettle();
await _chord(tester);
expect(find.byType(ChatWorkspace), findsOneWidget);
expect(_workspace(tester).paneCount, 1);
expect(_editable(tester, 'a').focusNode.hasPrimaryFocus, isFalse);
expect(_editable(tester, 'a').controller.text, isEmpty);
expect(_workspace(tester).activePane?.sessionId, 'c');
await _chord(tester);
expect(_workspace(tester).activePane?.sessionId, 'a');
await _chord(tester, reverse: true);
expect(_workspace(tester).activePane?.sessionId, 'c');
await tester.pumpWidget(const SizedBox.shrink());
});
@@ -592,10 +592,8 @@ void main() {
await app.stop(tester);
});
testWidgets('with the tiling focused Ctrl+Tab goes to the top-most shown '
'window, and cycles the panes only when no window is shown', (
tester,
) async {
testWidgets('with the tiling focused Ctrl+Tab cycles the single pane chat '
'list and cycles panes when there are multiple panes', (tester) async {
await _saved('a', 'b', 'c');
final app = _App(_Store());
await app.start(tester);
@@ -603,20 +601,20 @@ void main() {
expect(app.floating, ['c']);
final controller = _workspace(tester);
// A window is shown: from the tiling, Ctrl+Tab takes the keyboard to it
// and the panes stay where they are.
// A shown floating chat is skipped while the single tiled pane cycles the
// remaining open chats.
await tester.tapAt(tester.getCenter(_input('a')));
await tester.pump();
expect(controller.activePane?.sessionId, 'a');
await _tab(tester);
expect(controller.activePane?.sessionId, 'a');
expect(_composerFocused(tester, 'c'), isTrue);
expect(controller.activePane?.sessionId, 'b');
expect(_composerFocused(tester, 'b'), isTrue);
expect(app.floating, ['c']);
// A single shown window has nothing to cycle to.
// It wraps back to the other non-floating chat.
await _tab(tester);
expect(controller.activePane?.sessionId, 'a');
expect(_composerFocused(tester, 'c'), isTrue);
expect(_composerFocused(tester, 'a'), isTrue);
expect(app.floating, ['c']);
// No window shown: the panes cycle and the hidden window stays hidden.
@@ -150,28 +150,25 @@ void main() {
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('Control Tab over one pane does nothing: it never brings up '
'another chat', (tester) async {
testWidgets('Control Tab over one pane cycles the sidebar chats in both '
'directions', (tester) async {
await _setup(tester);
await _openRow(tester, 'a');
final workspace = _workspace(tester);
await _controlTab(tester);
expect(workspace.activePane?.sessionId, 'a');
expect(_editable(tester, 'a').focusNode.hasPrimaryFocus, isFalse);
// Opening b replaces the lone pane; a is no longer shown anywhere.
await _openRow(tester, 'b');
await tester.enterText(_input('b'), 'Draft B');
await _focusSidebar(tester);
for (final shift in [false, true]) {
await _controlTab(tester, shift: shift);
expect(workspace.paneCount, 1);
expect(workspace.activePane?.sessionId, 'b');
expect(_editable(tester, 'b').focusNode.hasPrimaryFocus, isFalse);
expect(_editable(tester, 'b').controller.text, 'Draft B');
for (final id in ['b', 'c', 'a']) {
await _controlTab(tester);
expect(workspace.activePane?.sessionId, id);
expect(_editable(tester, id).focusNode.hasPrimaryFocus, isTrue);
}
await _focusSidebar(tester);
for (final id in ['c', 'b', 'a']) {
await _controlTab(tester, shift: true);
expect(workspace.activePane?.sessionId, id);
expect(_editable(tester, id).focusNode.hasPrimaryFocus, isTrue);
}
// Two panes cycle the panes, not the history.
// Two panes still cycle panes, not the chat list.
await _openRow(tester, 'c');
await tester.tap(_actions('a'));
await tester.pumpAndSettle();
@@ -85,6 +85,7 @@ void main() {
activeSessionId: null,
visibleSessionIds: const {'a'},
onOpen: (_) {},
onNewChat: () {},
onExpand: () {},
navigation: const Text('Destinations'),
),
@@ -139,6 +140,7 @@ void main() {
activeSessionId: 'a',
visibleSessionIds: const {'a', 'b'},
onOpen: (_) {},
onNewChat: () {},
onExpand: () {},
),
),
@@ -107,6 +107,7 @@ void main() {
await controller.refresh();
final folds = ChatSectionFolds();
addTearDown(folds.dispose);
var newChatPressed = false;
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
@@ -116,12 +117,16 @@ void main() {
activeSessionId: 'a',
visibleSessionIds: const {'a', 'b'},
onOpen: (_) {},
onNewChat: () => newChatPressed = true,
onExpand: () {},
),
),
),
);
await tester.pumpAndSettle();
expect(find.byTooltip('New chat'), findsOneWidget);
await tester.tap(find.byTooltip('New chat'));
expect(newChatPressed, isTrue);
expect(find.byTooltip('Expand chat list'), findsOneWidget);
expect(edge(tester, 'a').width, 10);
expect(edge(tester, 'b').width, 3);
@@ -18,7 +18,7 @@ const _implemented = [
'Stop a running chat',
'Focus the neighbouring chat pane',
'Move the active chat pane',
'Cycle chat panes and floating chats',
'Cycle chats and floating chat panes',
'Resize panes with a focused divider',
'Scroll a wide transcript block',
'Show or hide floating chats',