Chat: hide the chat list entirely (Ctrl+B / Cmd+B), per device
ListDetailPanes takes listHidden and slides the list to zero width (at once with reduced motion), keeping its expanded or compact mode for when it comes back. A wide chat offers Hide chat list in the list's bar and the pane menu, Ctrl+B (Cmd+B on Apple; a focused terminal keeps Ctrl+B) and, while hidden, a Show chat list button at the start of the top-left pane's bar. The choice is device-local (pipelines.chat.listHidden.v1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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,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,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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user