Merge branch 'main' into worktree-agent-a5b6d89690dfcde6b
This commit is contained in:
@@ -0,0 +1,345 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_center_stage_controller.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_center_stage_keys.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_center_stage_layout.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_center_stage_strip.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_motion_viewport.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace_geometry.dart';
|
||||
|
||||
class _MemoryStore implements ChatCenterStageStore {
|
||||
_MemoryStore();
|
||||
bool? saved;
|
||||
@override
|
||||
Future<bool?> load() async => saved;
|
||||
@override
|
||||
Future<bool> save(bool on) async {
|
||||
saved = on;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class _Draft extends StatefulWidget {
|
||||
const _Draft({super.key, required this.name});
|
||||
final String name;
|
||||
@override
|
||||
State<_Draft> createState() => _DraftState();
|
||||
}
|
||||
|
||||
class _DraftState extends State<_Draft> {
|
||||
final text = TextEditingController();
|
||||
@override
|
||||
void dispose() {
|
||||
text.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) =>
|
||||
TextField(key: ValueKey('input-${widget.name}'), controller: text);
|
||||
}
|
||||
|
||||
Widget host(
|
||||
ChatWorkspaceController workspace,
|
||||
ChatCenterStageController stage, {
|
||||
double width = 1368,
|
||||
bool singlePane = false,
|
||||
bool reduceMotion = false,
|
||||
List<KeyEvent>? fieldKeys,
|
||||
}) => MaterialApp(
|
||||
home: MediaQuery(
|
||||
data: MediaQueryData(disableAnimations: reduceMotion),
|
||||
child: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
height: 800,
|
||||
child: ChatCenterStageKeys(
|
||||
controller: stage,
|
||||
enabled: () => !singlePane,
|
||||
child: ChatWorkspace(
|
||||
controller: workspace,
|
||||
centerStage: stage,
|
||||
singlePane: singlePane,
|
||||
paneTitle: (pane) => pane.sessionId,
|
||||
paneBuilder: (_, pane, active) => Focus(
|
||||
onKeyEvent: (_, event) {
|
||||
fieldKeys?.add(event);
|
||||
return KeyEventResult.ignored;
|
||||
},
|
||||
child: _Draft(
|
||||
key: ValueKey(pane.sessionId),
|
||||
name: pane.sessionId,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
ChatWorkspaceController threePanes() => ChatWorkspaceController()
|
||||
..open('one')
|
||||
..splitActive('two', ChatSplitAxis.horizontal)
|
||||
..splitActive('three', ChatSplitAxis.horizontal);
|
||||
|
||||
void wide(WidgetTester tester) {
|
||||
tester.view
|
||||
..physicalSize = const Size(1600, 1000)
|
||||
..devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
}
|
||||
|
||||
double widthOf(WidgetTester tester, String session) =>
|
||||
tester.getSize(find.byKey(ValueKey('input-$session'))).width;
|
||||
|
||||
void main() {
|
||||
group('layout', () {
|
||||
test(
|
||||
'stage is the reading width plus a quarter, others share the rest',
|
||||
() {
|
||||
final layout = ChatCenterStageLayout.of(const Size(1368, 800), [
|
||||
'a',
|
||||
'b',
|
||||
'c',
|
||||
], 'b')!;
|
||||
expect(chatCenterStageWidth, 950);
|
||||
expect(layout.rects['b'], const Rect.fromLTWH(209, 0, 950, 800));
|
||||
expect(layout.rects['a'], const Rect.fromLTWH(0, 0, 197, 800));
|
||||
expect(layout.rects['c']!.right, 1368);
|
||||
expect(layout.strips, {'a', 'c'});
|
||||
expect(layout.neighbor('b', ChatPaneDirection.left), 'a');
|
||||
expect(layout.neighbor('b', ChatPaneDirection.right), 'c');
|
||||
expect(layout.neighbor('b', ChatPaneDirection.up), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
test('a narrow workspace caps the stage to leave every strip', () {
|
||||
final layout = ChatCenterStageLayout.of(const Size(700, 800), [
|
||||
'a',
|
||||
'b',
|
||||
'c',
|
||||
], 'a')!;
|
||||
expect(layout.rects['a']!.width, 700 - 24 - 2 * 56);
|
||||
expect(layout.rects['c']!.right, 700);
|
||||
expect(
|
||||
ChatCenterStageLayout.of(const Size(300, 800), ['a', 'b'], 'a'),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
|
||||
test('a very wide workspace keeps the stage and shows live columns', () {
|
||||
final layout = ChatCenterStageLayout.of(const Size(2560, 800), [
|
||||
'a',
|
||||
'b',
|
||||
], 'a')!;
|
||||
expect(layout.rects['a']!.width, 950);
|
||||
expect(layout.strips, isEmpty);
|
||||
expect(
|
||||
ChatCenterStageLayout.of(const Size(2560, 800), ['a'], 'a'),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('toggling stages the active chat, keeps drafts and split sizes', (
|
||||
tester,
|
||||
) async {
|
||||
wide(tester);
|
||||
final workspace = threePanes();
|
||||
final stage = ChatCenterStageController(store: _MemoryStore());
|
||||
addTearDown(workspace.dispose);
|
||||
addTearDown(stage.dispose);
|
||||
final split = (workspace.root! as ChatWorkspaceSplit).id;
|
||||
workspace.resize(split, .3);
|
||||
await tester.pumpWidget(host(workspace, stage));
|
||||
await tester.enterText(find.byKey(const ValueKey('input-three')), 'draft');
|
||||
final before = {
|
||||
for (final id in ['one', 'two', 'three']) id: widthOf(tester, id),
|
||||
};
|
||||
|
||||
stage.value = true;
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 40));
|
||||
// Mid-flight the stage's painted rectangle is on its way, while its chat
|
||||
// is laid out once, at its destination width.
|
||||
final painted = tester
|
||||
.getSize(
|
||||
find.ancestor(
|
||||
of: find.byKey(const ValueKey('input-three')),
|
||||
matching: find.byType(ChatMotionViewport),
|
||||
),
|
||||
)
|
||||
.width;
|
||||
expect(painted, inExclusiveRange(before['three']!, 950));
|
||||
expect(widthOf(tester, 'three'), 950);
|
||||
await tester.pumpAndSettle();
|
||||
expect(widthOf(tester, 'three'), 950);
|
||||
expect(find.byType(ChatCenterStageStrip), findsNWidgets(2));
|
||||
expect(find.text('draft'), findsOneWidget);
|
||||
|
||||
stage.value = false;
|
||||
await tester.pumpAndSettle();
|
||||
for (final id in before.keys) {
|
||||
expect(widthOf(tester, id), before[id]);
|
||||
}
|
||||
expect((workspace.root! as ChatWorkspaceSplit).ratio, .3);
|
||||
expect(find.byType(ChatCenterStageStrip), findsNothing);
|
||||
expect(find.text('draft'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('the stage follows the active chat and strip presses', (
|
||||
tester,
|
||||
) async {
|
||||
wide(tester);
|
||||
final workspace = threePanes();
|
||||
final stage = ChatCenterStageController(store: _MemoryStore())
|
||||
..value = true;
|
||||
addTearDown(workspace.dispose);
|
||||
addTearDown(stage.dispose);
|
||||
await tester.pumpWidget(host(workspace, stage));
|
||||
await tester.enterText(find.byKey(const ValueKey('input-three')), 'kept');
|
||||
expect(widthOf(tester, 'three'), 950);
|
||||
|
||||
workspace.activate(workspace.panes.first.id);
|
||||
await tester.pumpAndSettle();
|
||||
expect(widthOf(tester, 'one'), 950);
|
||||
expect(widthOf(tester, 'three'), chatPaneMinimumWidth);
|
||||
|
||||
await tester.tap(find.bySemanticsLabel('Show two on center stage'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(workspace.activePane?.sessionId, 'two');
|
||||
expect(widthOf(tester, 'two'), 950);
|
||||
expect(find.text('kept'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'the floating chat is not staged; a docked chat takes the stage',
|
||||
(tester) async {
|
||||
wide(tester);
|
||||
final workspace = threePanes();
|
||||
final stage = ChatCenterStageController(store: _MemoryStore())
|
||||
..value = true;
|
||||
addTearDown(workspace.dispose);
|
||||
addTearDown(stage.dispose);
|
||||
await tester.pumpWidget(host(workspace, stage));
|
||||
workspace.float(workspace.panes.first.id);
|
||||
await tester.pumpAndSettle();
|
||||
expect(workspace.activePane?.sessionId, 'three');
|
||||
expect(widthOf(tester, 'three'), 950);
|
||||
// One chat beside the stage has room to stay a live column.
|
||||
expect(widthOf(tester, 'two'), 1368 - 12 - 950);
|
||||
expect(find.byType(ChatCenterStageStrip), findsNothing);
|
||||
|
||||
workspace.dock();
|
||||
await tester.pumpAndSettle();
|
||||
expect(workspace.activePane?.sessionId, 'one');
|
||||
expect(widthOf(tester, 'one'), 950);
|
||||
expect(find.byType(ChatCenterStageStrip), findsNWidgets(2));
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('reduced motion stages at once', (tester) async {
|
||||
wide(tester);
|
||||
final workspace = threePanes();
|
||||
final stage = ChatCenterStageController(store: _MemoryStore());
|
||||
addTearDown(workspace.dispose);
|
||||
addTearDown(stage.dispose);
|
||||
await tester.pumpWidget(host(workspace, stage, reduceMotion: true));
|
||||
stage.value = true;
|
||||
await tester.pump();
|
||||
expect(widthOf(tester, 'three'), 950);
|
||||
});
|
||||
|
||||
testWidgets('phones keep their one-chat layout', (tester) async {
|
||||
final workspace = threePanes();
|
||||
final stage = ChatCenterStageController(store: _MemoryStore())
|
||||
..value = true;
|
||||
addTearDown(workspace.dispose);
|
||||
addTearDown(stage.dispose);
|
||||
await tester.pumpWidget(
|
||||
host(workspace, stage, width: 400, singlePane: true),
|
||||
);
|
||||
expect(widthOf(tester, 'three'), 400);
|
||||
expect(find.byType(ChatCenterStageStrip), findsNothing);
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyE);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
||||
expect(stage.value, isTrue);
|
||||
});
|
||||
|
||||
for (final mac in [false, true]) {
|
||||
testWidgets(
|
||||
'${mac ? 'Cmd' : 'Ctrl'}+E toggles; a plain e reaches the field',
|
||||
(tester) async {
|
||||
wide(tester);
|
||||
debugDefaultTargetPlatformOverride = mac
|
||||
? TargetPlatform.macOS
|
||||
: TargetPlatform.linux;
|
||||
final workspace = threePanes();
|
||||
final store = _MemoryStore();
|
||||
final stage = ChatCenterStageController(store: store);
|
||||
addTearDown(workspace.dispose);
|
||||
addTearDown(stage.dispose);
|
||||
final keys = <KeyEvent>[];
|
||||
await tester.pumpWidget(host(workspace, stage, fieldKeys: keys));
|
||||
await tester.tap(find.byKey(const ValueKey('input-three')));
|
||||
await tester.pump();
|
||||
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyE);
|
||||
expect(stage.value, isFalse);
|
||||
expect(keys.whereType<KeyDownEvent>(), hasLength(1));
|
||||
|
||||
final modifier = mac
|
||||
? LogicalKeyboardKey.metaLeft
|
||||
: LogicalKeyboardKey.controlLeft;
|
||||
final other = mac
|
||||
? LogicalKeyboardKey.controlLeft
|
||||
: LogicalKeyboardKey.metaLeft;
|
||||
keys.clear();
|
||||
await tester.sendKeyDownEvent(modifier);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyE);
|
||||
await tester.sendKeyUpEvent(modifier);
|
||||
expect(stage.value, isTrue);
|
||||
expect(store.saved, isTrue);
|
||||
expect(
|
||||
keys.whereType<KeyDownEvent>().map((e) => e.logicalKey),
|
||||
isNot(contains(LogicalKeyboardKey.keyE)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(widthOf(tester, 'three'), 950);
|
||||
|
||||
// The other platform's chord stays with the field (Ctrl+E on a Mac is
|
||||
// its end of line).
|
||||
await tester.sendKeyDownEvent(other);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyE);
|
||||
await tester.sendKeyUpEvent(other);
|
||||
expect(stage.value, isTrue);
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
test('the choice is remembered', () async {
|
||||
final store = _MemoryStore();
|
||||
final first = ChatCenterStageController(store: store)..toggle();
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
expect(store.saved, isTrue);
|
||||
first.dispose();
|
||||
final next = ChatCenterStageController(store: store);
|
||||
await next.restore();
|
||||
expect(next.value, isTrue);
|
||||
next.dispose();
|
||||
});
|
||||
|
||||
test('labels name the platform chord', () {
|
||||
expect(chatCenterStageShortcutLabel(TargetPlatform.macOS), 'Cmd+E');
|
||||
expect(chatCenterStageShortcutLabel(TargetPlatform.windows), 'Ctrl+E');
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user