Files
pipelines/app/test/features/chat/stack/chat_stack_screen_test.dart
T
alan fba3b924f1 Chat stack: hold and drag to reorder the open chats, or onto x to remove
A 300 ms hold lifts a chat in the open column; dragging opens a gap and
dropping commits through ChatWorkspaceController.movePane, the pane order
the server syncs. An x comes in at the bottom while dragging; dropping on
it removes the chat with Undo, which restores its place. Escape, a
cancelled pointer or a drop away from the column put it back. Move up,
Move down and Remove are semantic actions. Repaint-only motion; reduced
motion swaps at once. Also keep floating-layout tracking out of
initState, and let the capture kit hold a press before a drag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 21:17:51 +00:00

128 lines
4.5 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/screen.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_entry.dart';
import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.dart';
import 'package:pipelines_app/features/chat/workspace/chat_peek_header.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../conversation/chat_thread_fixtures.dart';
const _rows = <JsonMap>[
{'id': 'a', 'title': 'Alpha', 'directory': '/w', 'color': 'teal'},
{'id': 'b', 'title': 'Beta', 'directory': '/w'},
{'id': 'c', 'title': 'Gamma', 'directory': '/v'},
];
class _Gateway extends FakeChatGateway {
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type == 'chat_sessions') {
return Future.value({
'chat_sessions': [
for (final row in _rows) {...row},
],
});
}
if (type == 'chat_shells') return Future.value({'chat_shells': []});
return super.call(type, fields);
}
}
Future<void> _pump(WidgetTester tester, Size size) async {
SharedPreferences.setMockInitialValues({});
unawaited(
MobileChatNavigationController.instance.setValue(
MobileChatNavigation.chatStack,
),
);
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final gateway = _Gateway()..history = (_) async => chatPage(const []);
addTearDown(gateway.close);
final route = ValueNotifier<String?>(null);
addTearDown(route.dispose);
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) => ValueListenableBuilder<String?>(
valueListenable: route,
builder: (context, id, _) => ChatScreen(
gateway: gateway,
initialSessionId: id,
onSessionSelected: (next) => route.value = next,
onBack: () => route.value = null,
),
),
},
),
),
);
await tester.pumpAndSettle();
}
Finder _thread(String id) => find.byKey(ValueKey('chat-thread-$id'));
final _stack = find.byKey(const Key('chat-stack'));
void main() {
final navigation = MobileChatNavigationController.instance;
tearDown(() {
unawaited(navigation.setValue(MobileChatNavigation.quickSwitch));
});
testWidgets('the setting swaps the peek for the stack, live', (tester) async {
await _pump(tester, const Size(390, 844));
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
expect(_thread('a'), findsOneWidget);
expect(_stack.hitTestable(), findsOneWidget);
expect(find.bySemanticsLabel(chatStackLabel(1)), findsOneWidget);
// Add chat picks a chat that is not open and opens it.
await tester.tap(_stack);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const ValueKey('chat-stack-button-add')));
await tester.pumpAndSettle();
await tester.tap(find.text('Beta').last);
await tester.pumpAndSettle();
expect(_thread('b').hitTestable(), findsOneWidget);
expect(find.bySemanticsLabel(chatStackLabel(2)), findsOneWidget);
// The stack replaces the peek.
expect(find.byType(ChatPeekHeader), findsNothing);
// A chat in the column opens as its list row would.
await tester.tap(_stack);
await tester.pumpAndSettle();
await tester.tap(find.text('Alpha').last);
await tester.pumpAndSettle();
expect(_thread('a').hitTestable(), findsOneWidget);
expect(_stack.hitTestable(), findsOneWidget);
// Back to Quick switch: the peek returns, the stack leaves.
unawaited(navigation.setValue(MobileChatNavigation.quickSwitch));
await tester.pumpAndSettle();
expect(_stack, findsNothing);
expect(find.byType(ChatPeekHeader), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('a wide window keeps its panes and shows no stack', (
tester,
) async {
await _pump(tester, const Size(1280, 800));
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
expect(_thread('a'), findsOneWidget);
expect(_stack, findsNothing);
await tester.pumpWidget(const SizedBox.shrink());
});
}