Drag chats at once with a mouse and mark only the receiving zone
The list rows used a long-press drag, which a mouse rarely triggers; they now drag immediately with the chip at the pointer. The drop indicator outlines just the area that will receive the chat (the pane, or the right or bottom half) with a label saying what happens.
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace_drop.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace_nodes.dart';
|
||||
|
||||
void main() {
|
||||
Future<List<ChatWorkspaceDropZone>> pumpPane(WidgetTester tester) async {
|
||||
tester.view.physicalSize = const Size(1200, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final drops = <ChatWorkspaceDropZone>[];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Row(
|
||||
children: [
|
||||
const SizedBox(
|
||||
width: 200,
|
||||
child: Draggable<String>(
|
||||
data: 'b',
|
||||
// As the chat list does: the feedback sits at the pointer.
|
||||
dragAnchorStrategy: pointerDragAnchorStrategy,
|
||||
feedback: Text('chat b'),
|
||||
child: Text('source'),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 800,
|
||||
height: 600,
|
||||
child: ChatWorkspaceDropTarget(
|
||||
pane: const ChatWorkspacePane('pane-a', 'a'),
|
||||
rect: const Rect.fromLTWH(0, 0, 800, 600),
|
||||
onDrop: (_, _, zone) => drops.add(zone),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return drops;
|
||||
}
|
||||
|
||||
// The pane occupies x 200..1000, y 0..600.
|
||||
for (final (name, point, zone) in [
|
||||
('centre', const Offset(500, 250), ChatWorkspaceDropZone.replace),
|
||||
('right edge', const Offset(950, 250), ChatWorkspaceDropZone.right),
|
||||
('bottom edge', const Offset(500, 560), ChatWorkspaceDropZone.bottom),
|
||||
]) {
|
||||
testWidgets('a mouse drag over the $name marks only that zone and drops '
|
||||
'there', (tester) async {
|
||||
final drops = await pumpPane(tester);
|
||||
final gesture = await tester.startGesture(
|
||||
tester.getCenter(find.text('source')),
|
||||
);
|
||||
// No long press: a plain drag starts at once.
|
||||
await gesture.moveBy(const Offset(20, 0));
|
||||
await gesture.moveTo(point);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(
|
||||
find.byKey(ValueKey('chat-drop-zone-${zone.name}')),
|
||||
findsOneWidget,
|
||||
);
|
||||
for (final other in ChatWorkspaceDropZone.values) {
|
||||
if (other == zone) continue;
|
||||
expect(
|
||||
find.byKey(ValueKey('chat-drop-zone-${other.name}')),
|
||||
findsNothing,
|
||||
);
|
||||
}
|
||||
await gesture.up();
|
||||
await tester.pump();
|
||||
expect(drops, [zone]);
|
||||
expect(find.byKey(ValueKey('chat-drop-zone-${zone.name}')), findsNothing);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user