Merge branch 'main' into worktree-agent-a1b6c249e2bec6658

This commit is contained in:
2026-12-03 22:00:26 +00:00
50 changed files with 3378 additions and 188 deletions
@@ -6,6 +6,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/pipelines_app.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/features/chat/workspace/chat_list_hidden_controller.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
import 'chat_registration_test.dart'
@@ -269,4 +270,31 @@ void main() {
},
variant: TargetPlatformVariant.only(TargetPlatform.macOS),
);
testWidgets('with the chat list hidden the switcher still opens and '
'switches', (tester) async {
final hidden = ChatListHiddenController.instance;
hidden.value = true;
addTearDown(() => hidden.value = false);
final provider = _provider();
final channel = await _mountOnChat(tester, provider);
expect(find.byKey(const Key('chat-show-list')), findsOneWidget);
await _chord(tester, LogicalKeyboardKey.controlLeft);
expect(_field, findsOneWidget);
await tester.enterText(_field, 'second');
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pump();
await replySubscribe(tester, channel, index: 1);
await replyHistory(tester, channel, index: 1);
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/chat/s2');
expect(_composerFocused(tester, 's2'), isTrue);
// Switching leaves the list hidden.
expect(hidden.value, isTrue);
expect(find.byKey(const Key('chat-show-list')), findsOneWidget);
expect(tester.takeException(), isNull);
await _teardown(tester);
});
}
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
@@ -18,6 +19,8 @@ import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dar
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
import '../native_back.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
import 'package:pipelines_app/ui/theme/app_design.dart';
import 'package:pipelines_app/ui/theme/app_design_controller.dart';
ServerEndpoint webServer() => ServerEndpoint.resolve(
base: Uri.parse('http://127.0.0.1:8096/'),
@@ -300,6 +303,15 @@ void main() {
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
// The Classic design's transcript (its activity summary line); the
// app starts on Terminal when no design is stored.
// The choice applies at once; its save need not finish here.
unawaited(AppDesignController.instance.select(AppDesign.standard));
addTearDown(
() => unawaited(
AppDesignController.instance.select(AppDesign.defaultDesign),
),
);
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(
@@ -0,0 +1,147 @@
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/workspace/chat_list_hidden_controller.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:pipelines_app/shell/list_pane_divider.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar_overflow.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': [
{'id': 'a', 'title': 'First chat'},
{'id': 'b', 'title': 'Second chat'},
{'id': 'c', 'title': 'Third chat'},
],
});
}
if (type == 'chat_shells') return Future.value({'chat_shells': []});
return super.call(type, fields);
}
}
final _body = find.byKey(const ValueKey('list-detail-body'));
final _show = find.byKey(const Key('chat-show-list'));
Future<ChatListHiddenController> _open(
WidgetTester tester, {
bool hidden = false,
}) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = const Size(1280, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final listHidden = ChatListHiddenController(
store: MemoryChatListHiddenStore(hidden),
);
addTearDown(listHidden.dispose);
final gateway = _Gateway()..history = (_) async => chatPage(const []);
addTearDown(gateway.close);
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) =>
ChatScreen(gateway: gateway, listHidden: listHidden),
},
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.text('First chat'));
await tester.pumpAndSettle();
return listHidden;
}
Future<void> _chord(WidgetTester tester, LogicalKeyboardKey key) async {
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(key);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pumpAndSettle();
}
double _railRight(WidgetTester tester) =>
tester.getRect(find.byType(NavigationRail)).right;
String? _active(WidgetTester tester) => tester
.widget<ChatWorkspace>(find.byType(ChatWorkspace))
.controller
.activePane
?.sessionId;
void main() {
testWidgets('Ctrl+B hides the list entirely and Show chat list brings it '
'back', (tester) async {
final listHidden = await _open(tester);
final shown = tester.getRect(_body).left;
expect(shown, greaterThan(_railRight(tester) + 100));
expect(_show, findsNothing);
// The list's own bar offers hiding too.
expect(find.byKey(const Key('chat-hide-list')), findsOneWidget);
await _chord(tester, LogicalKeyboardKey.keyB);
expect(listHidden.value, isTrue);
// The open chat takes the whole width beside the rail; no divider is
// left to drag.
expect(tester.getRect(_body).left, closeTo(_railRight(tester), 1));
expect(find.byType(ListPaneDivider), findsNothing);
expect(find.text('Second chat').hitTestable(), findsNothing);
// The chat's top bar starts with the way back.
expect(_show, findsOneWidget);
final bar = tester.getRect(find.byKey(const Key('chat-thread-header')));
expect(tester.getRect(_show).left - bar.left, lessThan(24));
await tester.tap(_show);
await tester.pumpAndSettle();
expect(listHidden.value, isFalse);
expect(tester.getRect(_body).left, closeTo(shown, 1));
expect(_show, findsNothing);
expect(find.text('Second chat').hitTestable(), findsOneWidget);
// Ctrl+B again hides, and again shows.
await _chord(tester, LogicalKeyboardKey.keyB);
expect(listHidden.value, isTrue);
await _chord(tester, LogicalKeyboardKey.keyB);
expect(listHidden.value, isFalse);
expect(tester.takeException(), isNull);
});
testWidgets('the pane menu names the toggle and its shortcut', (
tester,
) async {
final listHidden = await _open(tester);
await tester.tap(find.byKey(segmentedMoreKey).first);
await tester.pumpAndSettle();
await tester.tap(find.text('Hide chat list (Ctrl+B)'));
await tester.pumpAndSettle();
expect(listHidden.value, isTrue);
await tester.tap(find.byKey(segmentedMoreKey).first);
await tester.pumpAndSettle();
expect(find.text('Show chat list (Ctrl+B)'), findsOneWidget);
});
testWidgets('a stored hidden list stays hidden, and Ctrl+Tab still cycles '
'the chats', (tester) async {
await _open(tester, hidden: true);
expect(tester.getRect(_body).left, closeTo(_railRight(tester), 1));
expect(_show, findsOneWidget);
expect(_active(tester), 'a');
await _chord(tester, LogicalKeyboardKey.tab);
expect(_active(tester), 'b');
await _chord(tester, LogicalKeyboardKey.tab);
expect(_active(tester), 'c');
// Still hidden.
expect(tester.getRect(_body).left, closeTo(_railRight(tester), 1));
});
}
@@ -0,0 +1,219 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_column.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_entry.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_fab.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_pose.dart';
List<ChatStackEntry> _entries(int count, {int current = 0}) => [
for (var i = 0; i < count; i++)
ChatStackEntry(
paneId: 'pane-$i',
session: {
'id': 's$i',
'title': 'Chat $i',
if (i == 1) 'color': 'teal',
if (i == 2) 'running': true,
if (i == 3) 'awaiting_operator': 1,
},
current: i == current,
),
];
class _Harness {
final opened = <String>[];
final removed = <String>[];
var added = 0;
}
Future<_Harness> _pump(
WidgetTester tester, {
int count = 5,
bool reduced = false,
}) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final harness = _Harness();
await tester.pumpWidget(
MaterialApp(
home: Builder(
builder: (context) => MediaQuery(
data: MediaQuery.of(context).copyWith(disableAnimations: reduced),
child: Scaffold(
body: Stack(
children: [
const Center(child: Text('Transcript')),
Positioned(
right: 16,
bottom: 96,
child: ChatStackFab(
entries: _entries(count),
onOpen: (entry) => harness.opened.add(entry.sessionId),
onAdd: (_) => harness.added++,
onRemove: (entry) => harness.removed.add(entry.sessionId),
),
),
],
),
),
),
),
),
);
return harness;
}
/// The working and waiting badges animate for as long as they show.
Future<void> _settle(WidgetTester tester) async {
for (var i = 0; i < 4; i++) {
await tester.pump(const Duration(milliseconds: 150));
}
}
ChatStackFabState _state(WidgetTester tester) =>
tester.state<ChatStackFabState>(find.byType(ChatStackFab));
void main() {
testWidgets('collapsed: a labelled pile of at most four layers', (
tester,
) async {
final semantics = tester.ensureSemantics();
await _pump(tester, count: 6);
expect(find.bySemanticsLabel(chatStackLabel(6)), findsOneWidget);
expect(find.byType(ChatStackPoseTransition), findsNWidgets(4));
// More chats than layers: the count shows.
expect(find.text('6'), findsOneWidget);
expect(find.byType(ChatStackColumn), findsNothing);
semantics.dispose();
});
testWidgets('tap fans out a column; tap outside folds it back', (
tester,
) async {
final harness = await _pump(tester);
final slot = tester.getRect(find.byKey(const Key('chat-stack')));
await tester.tap(find.byKey(const Key('chat-stack')));
await tester.pump();
expect(_state(tester).expanded, isTrue);
// Mid-way the column is still rising.
await tester.pump(const Duration(milliseconds: 100));
await _settle(tester);
expect(find.text('Chat 0'), findsOneWidget);
expect(find.text('Chat 4'), findsOneWidget);
expect(find.text(ChatStackColumn.addLabel), findsOneWidget);
// Item 0 sits on the stack; each further item rises one pitch.
final first = tester.getCenter(
find.byKey(const ValueKey('chat-stack-button-pane-0')),
);
final second = tester.getCenter(
find.byKey(const ValueKey('chat-stack-button-pane-1')),
);
final add = tester.getCenter(
find.byKey(const ValueKey('chat-stack-button-add')),
);
expect(first.dx, closeTo(slot.center.dx, .5));
expect(first.dy, closeTo(slot.center.dy, .5));
expect(second.dy, lessThan(first.dy));
expect(add.dy, lessThan(second.dy));
// Outside the column.
await tester.tapAt(const Offset(40, 120));
await tester.pump();
expect(_state(tester).expanded, isFalse);
await _settle(tester);
expect(find.byType(ChatStackColumn), findsNothing);
expect(harness.opened, isEmpty);
});
testWidgets('tapping a chat opens it and folds the column', (tester) async {
final harness = await _pump(tester);
await tester.tap(find.byKey(const Key('chat-stack')));
await _settle(tester);
await tester.tap(find.text('Chat 3'));
await _settle(tester);
expect(harness.opened, ['s3']);
expect(find.byType(ChatStackColumn), findsNothing);
// The chat on screen only folds the column.
await tester.tap(find.byKey(const Key('chat-stack')));
await _settle(tester);
await tester.tap(
find.byKey(const ValueKey('chat-stack-button-pane-0')),
warnIfMissed: false,
);
await _settle(tester);
expect(harness.opened, ['s3']);
});
testWidgets('add opens the picker; long press removes', (tester) async {
final harness = await _pump(tester);
await tester.tap(find.byKey(const Key('chat-stack')));
await _settle(tester);
await tester.longPress(find.text('Chat 2'));
await _settle(tester);
expect(harness.removed, ['s2']);
// Removing folds the column, so a snack bar's Undo is in reach.
expect(find.byType(ChatStackColumn), findsNothing);
await tester.tap(find.byKey(const Key('chat-stack')));
await _settle(tester);
await tester.tap(find.byKey(const ValueKey('chat-stack-button-add')));
await _settle(tester);
expect(harness.added, 1);
expect(find.byType(ChatStackColumn), findsNothing);
});
testWidgets('Back and Escape fold the column', (tester) async {
await _pump(tester);
await tester.tap(find.byKey(const Key('chat-stack')));
await _settle(tester);
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await _settle(tester);
expect(find.byType(ChatStackColumn), findsNothing);
await tester.tap(find.byKey(const Key('chat-stack')));
await _settle(tester);
final handled = await tester.binding.handlePopRoute();
await _settle(tester);
expect(handled, isTrue);
expect(find.byType(ChatStackColumn), findsNothing);
expect(find.byType(ChatStackFab), findsOneWidget);
});
testWidgets('reduced motion only fades, in place', (tester) async {
await _pump(tester, reduced: true);
final slot = tester.getRect(find.byKey(const Key('chat-stack')));
await tester.tap(find.byKey(const Key('chat-stack')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 40));
// Already at its final place while fading in.
final second = tester.getCenter(
find.byKey(const ValueKey('chat-stack-button-pane-1')),
);
expect(second.dy, lessThan(slot.center.dy - 40));
final fades = tester.widgetList<FadeTransition>(
find.ancestor(
of: find.byKey(const ValueKey('chat-stack-button-pane-1')),
matching: find.byType(FadeTransition),
),
);
expect(
fades.map((fade) => fade.opacity.value),
contains(inExclusiveRange(0, 1)),
);
await _settle(tester);
expect(find.text('Chat 1'), findsOneWidget);
});
testWidgets('the on-screen keyboard hides the stack', (tester) async {
await _pump(tester);
expect(find.byKey(const Key('chat-stack')).hitTestable(), findsOneWidget);
tester.view.viewInsets = const FakeViewPadding(bottom: 300);
await _settle(tester);
expect(find.byKey(const Key('chat-stack')).hitTestable(), findsNothing);
await tester.tap(find.byKey(const Key('chat-stack')), warnIfMissed: false);
await tester.pump();
expect(_state(tester).expanded, isFalse);
tester.view.resetViewInsets();
await _settle(tester);
expect(find.byKey(const Key('chat-stack')).hitTestable(), findsOneWidget);
});
}
@@ -0,0 +1,152 @@
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('long press removes a chat, Undo restores it', (tester) async {
await _pump(tester, const Size(390, 844));
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
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('Gamma').last);
await tester.pumpAndSettle();
expect(find.bySemanticsLabel(chatStackLabel(2)), findsOneWidget);
await tester.tap(_stack);
await tester.pumpAndSettle();
await tester.longPress(find.text('Alpha').last);
await tester.pumpAndSettle();
expect(find.text('Removed Alpha from open chats'), findsOneWidget);
expect(find.bySemanticsLabel(chatStackLabel(1)), findsOneWidget);
await tester.tap(find.text('Undo'));
await tester.pumpAndSettle();
// Gamma stays on screen; Alpha is back in the stack.
expect(_thread('c').hitTestable(), findsOneWidget);
expect(find.bySemanticsLabel(chatStackLabel(2)), 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());
});
}
@@ -0,0 +1,82 @@
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/workspace/chat_list_hidden_controller.dart';
import 'package:shared_preferences/shared_preferences.dart';
KeyDownEvent _b() => const KeyDownEvent(
physicalKey: PhysicalKeyboardKey.keyB,
logicalKey: LogicalKeyboardKey.keyB,
timeStamp: Duration.zero,
);
void main() {
test('the choice is kept per device and restored', () async {
SharedPreferences.setMockInitialValues({});
final first = ChatListHiddenController();
expect(first.value, isFalse);
first.toggle();
expect(first.value, isTrue);
await Future<void>.delayed(Duration.zero);
expect(
(await SharedPreferences.getInstance()).getBool(
chatListHiddenPreferenceKey,
),
isTrue,
);
final next = ChatListHiddenController();
await next.restore();
expect(next.value, isTrue);
});
test('a choice made while restoring wins', () async {
final store = MemoryChatListHiddenStore(true);
final controller = ChatListHiddenController(store: store);
final restoring = controller.restore();
controller.value = false;
await restoring;
expect(controller.value, isFalse);
});
testWidgets('Ctrl+B elsewhere, Cmd+B on Apple; no other chord', (
tester,
) async {
final keyboard = HardwareKeyboard.instance;
Future<bool> matches(
List<LogicalKeyboardKey> modifiers,
TargetPlatform platform,
) async {
for (final key in modifiers) {
await tester.sendKeyDownEvent(key);
}
final result = chatListToggleShortcut(_b(), keyboard, platform: platform);
for (final key in modifiers.reversed) {
await tester.sendKeyUpEvent(key);
}
return result;
}
const linux = TargetPlatform.linux;
const mac = TargetPlatform.macOS;
expect(await matches([LogicalKeyboardKey.controlLeft], linux), isTrue);
expect(await matches([LogicalKeyboardKey.metaLeft], mac), isTrue);
expect(await matches([LogicalKeyboardKey.controlLeft], mac), isFalse);
expect(await matches([LogicalKeyboardKey.metaLeft], linux), isFalse);
expect(
await matches([
LogicalKeyboardKey.controlLeft,
LogicalKeyboardKey.shiftLeft,
], linux),
isFalse,
);
expect(
await matches([
LogicalKeyboardKey.controlLeft,
LogicalKeyboardKey.altLeft,
], linux),
isFalse,
);
expect(await matches(const [], linux), isFalse);
expect(chatListToggleLabel(true, linux), 'Show chat list (Ctrl+B)');
expect(chatListToggleLabel(false, mac), 'Hide chat list (Cmd+B)');
});
}
@@ -0,0 +1,64 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.dart';
import 'package:pipelines_app/features/settings/settings_chat_navigation_section.dart';
class _Store implements MobileChatNavigationStore {
String? saved;
bool success = true;
@override
Future<String?> load() async => saved;
@override
Future<bool> save(String value) async {
saved = value;
return success;
}
}
void main() {
testWidgets('chooses, saves and restores the phone chat navigation', (
tester,
) async {
final store = _Store();
final controller = MobileChatNavigationController(store: store);
addTearDown(controller.dispose);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: SingleChildScrollView(
child: SettingsChatNavigationSection(controller: controller),
),
),
),
);
expect(find.text(SettingsChatNavigationSection.title), findsOneWidget);
expect(controller.value, MobileChatNavigation.quickSwitch);
expect(
find.text(MobileChatNavigation.quickSwitch.description),
findsOneWidget,
);
await tester.tap(
find.byKey(const ValueKey('settings-chat-navigation-chatStack')),
);
await tester.pumpAndSettle();
expect(controller.value, MobileChatNavigation.chatStack);
expect(store.saved, 'chatStack');
expect(
find.text(MobileChatNavigation.chatStack.description),
findsOneWidget,
);
// A new controller (the next launch) restores the saved choice.
final next = MobileChatNavigationController(store: store);
addTearDown(next.dispose);
await next.restore();
expect(next.value, MobileChatNavigation.chatStack);
store.success = false;
await tester.tap(
find.byKey(const ValueKey('settings-chat-navigation-quickSwitch')),
);
await tester.pumpAndSettle();
expect(find.text('Could not save; applies until reload.'), findsOneWidget);
});
}
@@ -29,7 +29,7 @@ AppDesignTokens _tokens(WidgetTester tester) =>
AppDesignTokens.of(tester.element(find.text(designSectionTitle)));
void main() {
testWidgets('every design is a radio row; Default is chosen at first', (
testWidgets('every design is a radio row; Terminal is chosen at first', (
tester,
) async {
final designs = AppDesignController(store: MemoryAppDesignStore());
@@ -43,40 +43,43 @@ void main() {
final group = tester.widget<RadioGroup<AppDesign>>(
find.byType(RadioGroup<AppDesign>),
);
expect(group.groupValue, AppDesign.standard);
expect(_tokens(tester).terminal, isFalse);
expect(group.groupValue, AppDesign.terminal);
expect(_tokens(tester).terminal, isTrue);
// The Material look is called Classic, so no row reads "Default".
expect(find.text('Classic'), findsOneWidget);
expect(find.text('Default'), findsNothing);
});
testWidgets('choosing Terminal stores it and restyles the page live', (
testWidgets('choosing Classic stores it and restyles the page live', (
tester,
) async {
final store = MemoryAppDesignStore();
final designs = AppDesignController(store: store);
await _pump(tester, designs);
await tester.tap(find.text(AppDesign.terminal.label));
await tester.pumpAndSettle();
expect(store.id, AppDesign.terminal.id);
expect(designs.design, AppDesign.terminal);
expect(_tokens(tester).terminal, isTrue);
expect(find.text(designSaveFailedText), findsNothing);
await tester.tap(find.text(AppDesign.standard.label));
await tester.pumpAndSettle();
expect(store.id, AppDesign.standard.id);
expect(designs.design, AppDesign.standard);
expect(_tokens(tester).terminal, isFalse);
expect(find.text(designSaveFailedText), findsNothing);
await tester.tap(find.text(AppDesign.terminal.label));
await tester.pumpAndSettle();
expect(store.id, AppDesign.terminal.id);
expect(_tokens(tester).terminal, isTrue);
});
testWidgets('a stored choice is restored into the picker', (tester) async {
final designs = AppDesignController(
store: MemoryAppDesignStore(AppDesign.terminal.id),
store: MemoryAppDesignStore(AppDesign.standard.id),
);
await designs.restore();
await _pump(tester, designs);
final group = tester.widget<RadioGroup<AppDesign>>(
find.byType(RadioGroup<AppDesign>),
);
expect(group.groupValue, AppDesign.terminal);
expect(group.groupValue, AppDesign.standard);
});
testWidgets('a failed save says the choice lasts until reload', (
@@ -86,10 +89,10 @@ void main() {
store: MemoryAppDesignStore()..failSaves = true,
);
await _pump(tester, designs);
await tester.tap(find.text(AppDesign.terminal.label));
await tester.tap(find.text(AppDesign.paper.label));
await tester.pumpAndSettle();
expect(find.text(designSaveFailedText), findsOneWidget);
expect(designs.design, AppDesign.terminal);
expect(designs.design, AppDesign.paper);
});
testWidgets('choosing Paper stores it, restyles the page live and is '
+73
View File
@@ -0,0 +1,73 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/list_detail.dart';
import 'package:pipelines_app/shell/list_pane_divider.dart';
final _body = find.byKey(const ValueKey('list-detail-body'));
Widget _panes({required bool hidden, bool reduceMotion = false}) => MaterialApp(
home: Builder(
builder: (context) => MediaQuery(
data: MediaQuery.of(context).copyWith(disableAnimations: reduceMotion),
child: Scaffold(
body: ListDetailPanes(
listHidden: hidden,
list: const Focus(
autofocus: true,
child: Text('The list', key: Key('list-text')),
),
detail: const SizedBox.expand(),
),
),
),
),
);
void _size(WidgetTester tester) {
tester.view.physicalSize = const Size(1200, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
}
void main() {
testWidgets('a hidden list slides to zero width and comes back as it was', (
tester,
) async {
_size(tester);
await tester.pumpWidget(_panes(hidden: false));
await tester.pumpAndSettle();
final shown = tester.getRect(_body).left;
expect(shown, greaterThan(200));
expect(find.byType(ListPaneDivider), findsOneWidget);
await tester.pumpWidget(_panes(hidden: true));
await tester.pump(const Duration(milliseconds: 60));
final sliding = tester.getRect(_body).left;
expect(sliding, inExclusiveRange(0, shown), reason: 'animates');
// The handle is not offered while the list slides or is hidden.
expect(find.byType(ListPaneDivider), findsNothing);
await tester.pumpAndSettle();
expect(tester.getRect(_body).left, 0);
expect(tester.getRect(_body).width, 1200);
// Nothing in the hidden list keeps the keyboard.
final listFocus = Focus.of(
tester.element(find.byKey(const Key('list-text'))),
);
expect(listFocus.hasFocus, isFalse);
await tester.pumpWidget(_panes(hidden: false));
await tester.pumpAndSettle();
expect(tester.getRect(_body).left, shown);
expect(find.byType(ListPaneDivider), findsOneWidget);
});
testWidgets('with reduced motion the list hides at once', (tester) async {
_size(tester);
await tester.pumpWidget(_panes(hidden: false, reduceMotion: true));
await tester.pumpAndSettle();
await tester.pumpWidget(_panes(hidden: true, reduceMotion: true));
await tester.pump();
await tester.pump();
expect(tester.getRect(_body).left, 0);
});
}
@@ -0,0 +1,208 @@
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_header.dart';
import 'package:pipelines_app/ui/adaptive/app_popups.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_adaptive.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar_overflow.dart';
/// An unfolded foldable: 884x1104 dp, a status bar and a cutout above the
/// app (Android draws edge to edge), a gesture bar below it, and the fold
/// down the middle.
void _foldable(WidgetTester tester, {bool halfOpened = false}) {
tester.view.physicalSize = const Size(884, 1104);
tester.view.devicePixelRatio = 1;
tester.view.padding = const FakeViewPadding(top: 52, bottom: 24);
tester.view.viewPadding = const FakeViewPadding(top: 52, bottom: 24);
tester.view.displayFeatures = [
DisplayFeature(
bounds: halfOpened
? const Rect.fromLTWH(436, 0, 12, 1104)
: const Rect.fromLTWH(442, 0, 0, 1104),
type: halfOpened ? DisplayFeatureType.hinge : DisplayFeatureType.fold,
state: halfOpened
? DisplayFeatureState.postureHalfOpened
: DisplayFeatureState.postureFlat,
),
];
addTearDown(tester.view.reset);
}
Widget _choices(BuildContext menu) => Column(
mainAxisSize: MainAxisSize.min,
children: [
for (final choice in const ['Opus', 'Sonnet', 'Haiku'])
ListTile(title: Text(choice), onTap: () => Navigator.of(menu).pop()),
],
);
Widget _menuButton(String label) => Builder(
builder: (anchor) => TextButton(
onPressed: () => showAppChoiceMenu<void>(anchor, builder: _choices),
child: Text(label),
),
);
/// A chat pane's top bar the way the app lays it out: the app's own top
/// bar under the status bar, the selectors in the pane header, and the
/// overflow menu at its end.
Widget _app({required double listWidth}) => MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: Scaffold(
body: SafeArea(
child: Row(
children: [
SizedBox(width: listWidth, child: const Placeholder()),
Expanded(
child: Column(
children: [
ChatThreadHeader(
title: 'Chat',
folder: 'demo',
onInfo: () {},
controls: [
_menuButton('Model'),
_menuButton('Permission'),
_menuButton('Thinking'),
],
moreActions: [
ChatBarAction(
label: 'Rename chat',
onPressed: () {},
materialIcon: Icons.edit_outlined,
),
],
),
const Expanded(child: SizedBox.expand()),
],
),
),
],
),
),
),
);
final _menu = find.byKey(const ValueKey('app-choice-menu'));
Future<void> _expectUnder(
WidgetTester tester,
Finder button,
Finder panel, {
double slack = 16,
}) async {
final anchor = tester.getRect(button);
await tester.tap(button);
await tester.pumpAndSettle();
final menu = tester.getRect(panel);
expect(menu.top, greaterThanOrEqualTo(anchor.bottom - 1));
expect(
menu.top - anchor.bottom,
lessThan(slack),
reason: 'the menu opens right under its anchor, not an inset lower',
);
await tester.tapAt(const Offset(200, 900));
await tester.pumpAndSettle();
}
void main() {
testWidgets('unfolded foldable, wide pane: every top bar menu opens '
'under its control', (tester) async {
_foldable(tester);
await tester.pumpWidget(_app(listWidth: 200));
await tester.pumpAndSettle();
for (final label in const ['Model', 'Thinking', 'Permission']) {
final button = find.widgetWithText(TextButton, label);
await _expectUnder(tester, button, _menu);
}
// The overflow menu is a MenuAnchor in the root overlay.
await _expectUnder(
tester,
find.byKey(segmentedMoreKey).first,
find.text('Rename chat').hitTestable(),
// The first item's label, inside the panel's and the item's padding.
slack: 32,
);
});
testWidgets('unfolded foldable, narrow pane: the settings panel opens '
'under the bar and each selector menu under its control', (tester) async {
_foldable(tester);
await tester.pumpWidget(_app(listWidth: 360));
await tester.pumpAndSettle();
final bar = tester.getRect(find.byType(ChatThreadHeader));
await tester.tap(find.byKey(segmentedMoreKey).first);
await tester.pumpAndSettle();
await tester.tap(find.text('Chat settings'));
await tester.pumpAndSettle();
final settings = tester.getRect(_menu);
expect(settings.top - bar.bottom, inInclusiveRange(-1, 16));
for (final label in const ['Model', 'Thinking', 'Permission']) {
final button = find.widgetWithText(TextButton, label);
final anchor = tester.getRect(button);
await tester.tap(button);
await tester.pumpAndSettle();
final menu = tester.getRect(_menu.last);
expect(
menu.top - anchor.bottom,
inInclusiveRange(-1, 16),
reason: '$label menu right under its control',
);
await tester.tap(find.text('Opus').last);
await tester.pumpAndSettle();
}
});
testWidgets('a menu stays inside the safe area and above when needed', (
tester,
) async {
_foldable(tester);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Align(
alignment: Alignment.bottomRight,
child: _menuButton('Low'),
),
),
),
);
final anchor = tester.getRect(find.widgetWithText(TextButton, 'Low'));
await tester.tap(find.text('Low'));
await tester.pumpAndSettle();
final menu = tester.getRect(_menu);
// No room below: above the anchor, close to it, inside the app.
expect(menu.bottom, lessThanOrEqualTo(anchor.top));
expect(anchor.top - menu.bottom, lessThan(16));
expect(menu.right, lessThanOrEqualTo(884 - 8));
});
testWidgets('a half opened hinge keeps the menu on its anchor side', (
tester,
) async {
_foldable(tester, halfOpened: true);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.only(left: 340),
child: Align(
alignment: Alignment.topLeft,
child: _menuButton('Across'),
),
),
),
),
),
);
final anchor = tester.getRect(find.widgetWithText(TextButton, 'Across'));
await tester.tap(find.text('Across'));
await tester.pumpAndSettle();
final menu = tester.getRect(_menu);
expect(menu.top - anchor.bottom, inInclusiveRange(-1, 16));
// The anchor's centre is left of the hinge: the panel stays left of it.
expect(menu.right, lessThanOrEqualTo(436));
});
}
@@ -4,34 +4,52 @@ import 'package:pipelines_app/ui/theme/app_design_controller.dart';
import 'package:shared_preferences/shared_preferences.dart';
void main() {
test('restore applies the stored design; unknown ids keep Default', () async {
final stored = AppDesignController(store: MemoryAppDesignStore('terminal'));
var notified = 0;
stored.addListener(() => notified++);
await stored.restore();
expect(stored.design, AppDesign.terminal);
expect(notified, 1);
final unknown = AppDesignController(store: MemoryAppDesignStore('neon'));
await unknown.restore();
expect(unknown.design, AppDesign.standard);
test('an unset device starts on Terminal and keeps it', () async {
final unset = AppDesignController(store: MemoryAppDesignStore());
expect(unset.design, AppDesign.terminal);
await unset.restore();
expect(unset.design, AppDesign.terminal);
});
test(
'restore applies the stored design; unknown ids are the default',
() async {
// An explicit Classic choice, stored as `default` back when Classic was
// the default, is respected.
final stored = AppDesignController(
store: MemoryAppDesignStore('default'),
);
var notified = 0;
stored.addListener(() => notified++);
await stored.restore();
expect(stored.design, AppDesign.standard);
expect(notified, 1);
final paper = AppDesignController(store: MemoryAppDesignStore('paper'));
await paper.restore();
expect(paper.design, AppDesign.paper);
final unknown = AppDesignController(store: MemoryAppDesignStore('neon'));
await unknown.restore();
expect(unknown.design, AppDesign.terminal);
},
);
test('select applies at once and stores the id', () async {
final store = MemoryAppDesignStore();
final designs = AppDesignController(store: store);
final pending = designs.select(AppDesign.terminal);
expect(designs.design, AppDesign.terminal);
final pending = designs.select(AppDesign.standard);
expect(designs.design, AppDesign.standard);
await pending;
expect(store.id, 'terminal');
expect(store.id, 'default');
expect(designs.saveFailed, isFalse);
});
test('a failed save is reported and the choice still applies', () async {
final store = MemoryAppDesignStore()..failSaves = true;
final designs = AppDesignController(store: store);
await designs.select(AppDesign.terminal);
expect(designs.design, AppDesign.terminal);
await designs.select(AppDesign.paper);
expect(designs.design, AppDesign.paper);
expect(designs.saveFailed, isTrue);
store.failSaves = false;
await designs.select(AppDesign.standard);
+12 -8
View File
@@ -11,16 +11,19 @@ import 'package:pipelines_app/ui/theme/app_font_store.dart';
import 'package:pipelines_app/ui/theme/app_theme.dart';
void main() {
test('ids round-trip and an unknown id is the Default design', () {
test('ids round-trip and a missing or unknown id is Terminal', () {
for (final design in AppDesign.values) {
expect(AppDesign.fromId(design.id), design);
}
expect(AppDesign.fromId(null), AppDesign.standard);
expect(AppDesign.fromId('neon'), AppDesign.standard);
expect(AppDesign.defaultDesign, AppDesign.terminal);
expect(AppDesign.fromId(null), AppDesign.terminal);
expect(AppDesign.fromId('neon'), AppDesign.terminal);
// Classic keeps the id it was stored under when it was the default.
expect(AppDesign.standard.id, 'default');
expect(AppDesign.standard.label, 'Classic');
});
test('the Default design builds exactly the existing themes', () {
test('the Classic design builds exactly the existing themes', () {
expect(AppDesign.standard.light(), appLightTheme());
expect(AppDesign.standard.dark(), appDarkTheme());
expect(
@@ -97,14 +100,15 @@ void main() {
},
),
);
expect(tokens.terminal, isFalse);
expect(family, isNot(appMonospaceFamily));
await designs.select(AppDesign.terminal);
await tester.pumpAndSettle();
// Terminal until the device chooses.
expect(tokens.terminal, isTrue);
expect(family, appMonospaceFamily);
await designs.select(AppDesign.standard);
await tester.pumpAndSettle();
expect(tokens.terminal, isFalse);
expect(family, isNot(appMonospaceFamily));
await designs.select(AppDesign.terminal);
await tester.pumpAndSettle();
expect(tokens.terminal, isTrue);
});
}
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/app.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/ui/theme/app_design_controller.dart';
import 'package:pipelines_app/ui/theme/app_font.dart';
import 'package:pipelines_app/ui/theme/app_font_controller.dart';
import 'package:pipelines_app/ui/theme/app_font_store.dart';
@@ -36,10 +37,14 @@ void main() {
store: MemoryAppFontStore(),
loader: (family, assets) async {},
);
// Classic follows the interface font (Terminal keeps its monospace).
final designs = AppDesignController(store: MemoryAppDesignStore('default'));
await designs.restore();
String? family;
await tester.pumpWidget(
MyApp(
fonts: fonts,
designs: designs,
destination: AppDestination.settings,
destinationBodies: <AppDestination, WidgetBuilder>{
AppDestination.settings: (context) => Builder(