Merge branch 'main' into ws-files-panel

This commit is contained in:
2026-11-07 01:06:30 +00:00
19 changed files with 933 additions and 39 deletions
@@ -0,0 +1,190 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.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/ui/sessions/session_actions.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.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';
class _Gateway 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', 'c']) {'id': id, 'title': 'Chat $id'},
],
});
}
if (type == 'chat_shells') return Future.value({'chat_shells': []});
return super.call(type, fields);
}
}
Finder _input(String id) => find.descendant(
of: find.byKey(ValueKey('chat-composer-$id')),
matching: find.byType(EditableText),
);
EditableText _editable(WidgetTester tester, String id) =>
tester.widget<EditableText>(_input(id));
Finder _actions(String id) => find.byWidgetPredicate(
(widget) => widget is SessionActionsButton && widget.session['id'] == id,
);
ChatWorkspaceController _workspace(WidgetTester tester) =>
tester.widget<ChatWorkspace>(find.byType(ChatWorkspace)).controller;
Future<void> _setup(WidgetTester tester) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = const Size(1800, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final gateway = _Gateway()..history = (_) async => chatPage([]);
addTearDown(gateway.close);
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) => ChatScreen(gateway: gateway),
},
),
),
);
await tester.pumpAndSettle();
}
Future<void> _openRow(WidgetTester tester, String id) async {
await tester.tap(find.byKey(Key('chat-row-$id')));
await tester.pumpAndSettle();
}
/// Puts focus on a sidebar control, outside every text field.
Future<void> _focusSidebar(WidgetTester tester) async {
final icon = find
.descendant(of: _actions('a'), matching: find.byType(Icon))
.first;
Focus.of(tester.element(icon)).requestFocus();
await tester.pumpAndSettle();
}
Future<bool> _slash(WidgetTester tester) async {
final handled = await tester.sendKeyEvent(LogicalKeyboardKey.slash);
await tester.pumpAndSettle();
return handled;
}
Future<void> _controlTab(WidgetTester tester, {bool shift = false}) async {
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
if (shift) await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
if (shift) await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pumpAndSettle();
}
void main() {
testWidgets('slash outside a text field focuses the composer, untyped', (
tester,
) async {
await _setup(tester);
await _openRow(tester, 'a');
await _focusSidebar(tester);
expect(_editable(tester, 'a').focusNode.hasPrimaryFocus, isFalse);
expect(await _slash(tester), isTrue);
expect(_editable(tester, 'a').focusNode.hasPrimaryFocus, isTrue);
expect(_editable(tester, 'a').controller.text, isEmpty);
// Inside the composer a slash is an ordinary character for the field.
expect(await _slash(tester), isFalse);
expect(_editable(tester, 'a').focusNode.hasPrimaryFocus, isTrue);
// Shift+/ (a question mark) and Alt+/ are not the shortcut; Ctrl+/ is
// the shell's own Search chord.
await _focusSidebar(tester);
await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.slash, character: '?');
await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.slash);
await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft);
await tester.pumpAndSettle();
expect(_editable(tester, 'a').focusNode.hasPrimaryFocus, isFalse);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('slash leaves a dialog text field and a popup alone', (
tester,
) async {
await _setup(tester);
await _openRow(tester, 'a');
await tester.tap(_actions('a'));
await tester.pumpAndSettle();
expect(await _slash(tester), isFalse);
expect(find.text('Rename…'), findsOneWidget);
await tester.tap(find.text('Rename…'));
await tester.pumpAndSettle();
final dialogField = find.descendant(
of: find.byType(Dialog),
matching: find.byType(EditableText),
);
expect(dialogField, findsOneWidget);
await tester.tap(dialogField);
await tester.pumpAndSettle();
expect(await _slash(tester), isFalse);
expect(find.byType(Dialog), findsOneWidget);
expect(_editable(tester, 'a').focusNode.hasPrimaryFocus, isFalse);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('Control Tab over one pane returns to the previous chat', (
tester,
) async {
await _setup(tester);
await _openRow(tester, 'a');
final workspace = _workspace(tester);
// Nothing shown before: the chord only focuses the composer.
await _controlTab(tester);
expect(workspace.activePane?.sessionId, 'a');
expect(_editable(tester, 'a').focusNode.hasPrimaryFocus, isTrue);
await _openRow(tester, 'b');
await tester.enterText(_input('b'), 'Draft B');
await _focusSidebar(tester);
for (final id in ['a', 'b', 'a']) {
await _controlTab(tester);
expect(workspace.paneCount, 1);
expect(workspace.activePane?.sessionId, id);
expect(_editable(tester, id).focusNode.hasPrimaryFocus, isTrue);
}
await _controlTab(tester, shift: true);
expect(workspace.activePane?.sessionId, 'b');
expect(_editable(tester, 'b').controller.text, 'Draft B');
// A third chat makes the pair c and b; a is no longer one step away.
await _openRow(tester, 'c');
await _controlTab(tester);
expect(workspace.activePane?.sessionId, 'b');
await _controlTab(tester);
expect(workspace.activePane?.sessionId, 'c');
// Two panes cycle the panes as before, not the history.
await tester.tap(_actions('a'));
await tester.pumpAndSettle();
await tester.tap(find.text('Open to the right'));
await tester.pumpAndSettle();
expect(workspace.paneCount, 2);
expect(workspace.activePane?.sessionId, 'a');
await _controlTab(tester);
expect(workspace.activePane?.sessionId, 'c');
await _controlTab(tester);
expect(workspace.activePane?.sessionId, 'a');
expect(workspace.paneCount, 2);
await tester.pumpWidget(const SizedBox.shrink());
});
}
@@ -0,0 +1,68 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/conversation/chat_composer_bar.dart';
import 'chat_composer_bar_fixtures.dart';
/// The phones: Fuchsia counts as a keyboard host (Enter sends), like desktop.
final _phones = TargetPlatformVariant({
TargetPlatform.android,
TargetPlatform.iOS,
});
double _bottomMargin(WidgetTester tester) {
final padding = tester.widget<Padding>(
find.byKey(const Key('chat-composer')),
);
return (padding.padding as EdgeInsetsDirectional).bottom;
}
void main() {
test('phones keep the close bottom margin, desktops a wider one', () {
expect(
chatComposerBottomMargin(TargetPlatform.android),
kChatComposerBottomMargin,
);
expect(
chatComposerBottomMargin(TargetPlatform.iOS),
kChatComposerBottomMargin,
);
for (final desktop in [
TargetPlatform.macOS,
TargetPlatform.windows,
TargetPlatform.linux,
]) {
expect(
chatComposerBottomMargin(desktop),
kChatComposerDesktopBottomMargin,
);
}
expect(
kChatComposerDesktopBottomMargin,
greaterThan(kChatComposerBottomMargin),
);
});
group('rendered composer', () {
late ComposerBarGateway gateway;
setUp(() => gateway = ComposerBarGateway()..page = fixtureTurn());
tearDown(() => gateway.close());
testWidgets(
'keeps more room from a desktop window bottom',
(tester) async {
await tester.pumpWidget(composerThread(gateway));
await tester.pumpAndSettle();
expect(_bottomMargin(tester), kChatComposerDesktopBottomMargin);
},
variant: TargetPlatformVariant.desktop(),
);
testWidgets('stays close to a phone bottom', (tester) async {
await tester.pumpWidget(composerThread(gateway));
await tester.pumpAndSettle();
expect(_bottomMargin(tester), kChatComposerBottomMargin);
}, variant: _phones);
});
}
@@ -0,0 +1,109 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/conversation/composer_focus_ring.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_color_palette.dart';
import 'chat_composer_bar_fixtures.dart';
/// The focus ring wrapping the composer pill: its outer glow and inner ring.
({Color glow, BorderSide side}) _ring(WidgetTester tester) {
final container = tester.widget<AnimatedContainer>(
find.byKey(const Key('chat-composer-focus-ring')),
);
final glow = (container.decoration! as ShapeDecoration).shadows!.single;
final shape = (container.foregroundDecoration! as ShapeDecoration).shape;
return (glow: glow.color, side: (shape as RoundedRectangleBorder).side);
}
Future<void> _focusField(WidgetTester tester) async {
await tester.tap(find.byKey(const Key('chat-composer-field')));
await tester.pumpAndSettle();
}
void main() {
late ComposerBarGateway gateway;
setUp(() => gateway = ComposerBarGateway()..page = fixtureTurn());
tearDown(() => gateway.close());
testWidgets('unfocused composer draws no ring or glow', (tester) async {
await tester.pumpWidget(composerThread(gateway));
await tester.pumpAndSettle();
final ring = _ring(tester);
expect(ring.side.color.a, 0);
expect(ring.glow.a, 0);
expect(ring.side.width, ComposerFocusRing.ringWidth);
});
testWidgets('focused composer takes the primary colour as its ring', (
tester,
) async {
await tester.pumpWidget(composerThread(gateway));
await tester.pumpAndSettle();
await _focusField(tester);
final primary = Theme.of(
tester.element(find.byKey(const Key('chat-composer-field'))),
).colorScheme.primary;
final ring = _ring(tester);
expect(
ring.side.color,
primary.withValues(alpha: ComposerFocusRing.ringOpacity),
);
expect(ring.glow, primary.withValues(alpha: ComposerFocusRing.glowOpacity));
expect(ring.side.width, ComposerFocusRing.ringWidth);
});
testWidgets('a coloured chat lends its own shade to the ring', (
tester,
) async {
await tester.pumpWidget(
composerThread(gateway, session: {'id': 's', 'color': 'teal'}),
);
await tester.pumpAndSettle();
await _focusField(tester);
final teal = chatColorShade(
tester.element(find.byKey(const Key('chat-composer-field'))),
'teal',
)!;
expect(
_ring(tester).side.color,
teal.withValues(alpha: ComposerFocusRing.ringOpacity),
);
});
testWidgets('the ring fades out again when focus leaves', (tester) async {
await tester.pumpWidget(composerThread(gateway));
await tester.pumpAndSettle();
await _focusField(tester);
expect(_ring(tester).side.color.a, greaterThan(0));
FocusManager.instance.primaryFocus?.unfocus();
// One frame applies the focus change, the next rebuilds the ring towards
// its unfocused decoration, which the container then animates into.
await tester.pump();
await tester.pump();
expect(_ring(tester).side.color.a, 0);
await tester.pumpAndSettle();
expect(_ring(tester).glow.a, 0);
});
testWidgets('Cupertino composer rings in the theme primary colour', (
tester,
) async {
await tester.pumpWidget(composerThread(gateway, cupertino: true));
await tester.pumpAndSettle();
await _focusField(tester);
final primary = CupertinoTheme.of(
tester.element(find.byKey(const Key('chat-composer-field'))),
).primaryColor;
expect(
_ring(tester).side.color,
primary.withValues(alpha: ComposerFocusRing.ringOpacity),
);
});
}