Resize chat list into compact rail and animate visible chat markers
This commit is contained in:
@@ -172,42 +172,51 @@ void main() {
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('compact and hidden sidebar preserve panes and drafts', (
|
||||
tester,
|
||||
) async {
|
||||
await _setup(tester);
|
||||
await _split(tester, 'b', 'Open to the right');
|
||||
final stateA = tester.state(_thread('a'));
|
||||
final stateB = tester.state(_thread('b'));
|
||||
await tester.enterText(_input('a'), 'Keep this draft');
|
||||
final originalWidth = tester.getSize(_thread('a')).width;
|
||||
Future<void> choose(String label) async {
|
||||
testWidgets(
|
||||
'drag compacts and expands sidebar without losing panes or drafts',
|
||||
(tester) async {
|
||||
await _setup(tester);
|
||||
await _split(tester, 'b', 'Open to the right');
|
||||
final stateA = tester.state(_thread('a'));
|
||||
final stateB = tester.state(_thread('b'));
|
||||
await tester.enterText(_input('a'), 'Keep this draft');
|
||||
final divider = find.byKey(const ValueKey('list-detail-divider'));
|
||||
final originalLeft = tester.getRect(_thread('a')).left;
|
||||
final gesture = await tester.startGesture(tester.getCenter(divider));
|
||||
await gesture.moveBy(const Offset(-250, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byTooltip('Expand chat list'), findsOneWidget);
|
||||
expect(tester.getRect(_thread('a')).left, lessThan(originalLeft));
|
||||
expect(tester.state(_thread('a')), same(stateA));
|
||||
expect(tester.state(_thread('b')), same(stateB));
|
||||
// The same drag can reverse across the threshold without dropping capture.
|
||||
await gesture.moveBy(const Offset(250, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byTooltip('Expand chat list'), findsNothing);
|
||||
expect(tester.getRect(_thread('a')).left, closeTo(originalLeft, 1));
|
||||
await gesture.up();
|
||||
await tester.drag(divider, const Offset(-500, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byTooltip('Expand chat list'), findsOneWidget);
|
||||
await tester.tap(find.byTooltip('Expand chat list'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byTooltip('Expand chat list'), findsNothing);
|
||||
expect(
|
||||
tester.widget<EditableText>(_input('a')).controller.text,
|
||||
'Keep this draft',
|
||||
);
|
||||
await tester.drag(divider, const Offset(-500, 0));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.drag(divider, const Offset(250, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byTooltip('Expand chat list'), findsNothing);
|
||||
expect(tester.state(_thread('b')), same(stateB));
|
||||
await tester.tap(find.byTooltip('More actions').hitTestable().first);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Chat list layout'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text(label));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
await choose('Compact chat list');
|
||||
expect(find.byTooltip('Expand chat list'), findsOneWidget);
|
||||
expect(tester.getSize(_thread('a')).width, greaterThan(originalWidth));
|
||||
expect(tester.state(_thread('a')), same(stateA));
|
||||
expect(tester.state(_thread('b')), same(stateB));
|
||||
await choose('Hide chat list');
|
||||
expect(find.byTooltip('Expand chat list'), findsNothing);
|
||||
expect(tester.getRect(_thread('a')).left, 0);
|
||||
expect(tester.state(_thread('a')), same(stateA));
|
||||
expect(
|
||||
tester.widget<EditableText>(_input('a')).controller.text,
|
||||
'Keep this draft',
|
||||
);
|
||||
await choose('Expanded chat list');
|
||||
expect(tester.getSize(_thread('a')).width, closeTo(originalWidth, 1));
|
||||
expect(tester.state(_thread('b')), same(stateB));
|
||||
});
|
||||
expect(find.text('Chat list layout'), findsNothing);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'nested splits preserve drafts, resize, collapse and narrow restore',
|
||||
|
||||
@@ -5,7 +5,6 @@ import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/core/servers/server_scope.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_sidebar_controls.dart';
|
||||
import 'package:pipelines_app/features/chat/screen.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace_store.dart';
|
||||
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
||||
@@ -89,19 +88,8 @@ void main() {
|
||||
findsOneWidget,
|
||||
);
|
||||
}
|
||||
expect(
|
||||
(tester
|
||||
.widget<ChatThreadView>(find.byType(ChatThreadView).first)
|
||||
.sidebarControl!
|
||||
as ChatSidebarButton)
|
||||
.mode,
|
||||
ChatSidebarMode.hidden,
|
||||
);
|
||||
(tester
|
||||
.widget<ChatThreadView>(find.byType(ChatThreadView).first)
|
||||
.sidebarControl!
|
||||
as ChatSidebarButton)
|
||||
.onChanged(ChatSidebarMode.compact);
|
||||
expect(find.byTooltip('Expand chat list'), findsOneWidget);
|
||||
expect(find.byType(ChatSidebarButton), findsNothing);
|
||||
} else {
|
||||
expect(find.byType(ChatSidebarButton), findsNothing);
|
||||
}
|
||||
@@ -113,20 +101,13 @@ void main() {
|
||||
);
|
||||
final persisted = (await store.read())!;
|
||||
expect((persisted.root as ChatWorkspaceSplit).ratio, .42);
|
||||
expect(persisted.sidebarMode, width > 1000 ? 'compact' : 'hidden');
|
||||
expect(persisted.sidebarMode, 'compact');
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pumpAndSettle();
|
||||
await _mount(tester, gateway);
|
||||
expect((_workspace(tester).root as ChatWorkspaceSplit).ratio, .42);
|
||||
if (width > 1000) {
|
||||
expect(
|
||||
(tester
|
||||
.widget<ChatThreadView>(find.byType(ChatThreadView).first)
|
||||
.sidebarControl!
|
||||
as ChatSidebarButton)
|
||||
.mode,
|
||||
ChatSidebarMode.compact,
|
||||
);
|
||||
expect(find.byTooltip('Expand chat list'), findsOneWidget);
|
||||
}
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
@@ -66,16 +66,15 @@ Future<void> _pump(
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Finder _accent(String id) => find.descendant(
|
||||
of: find.byKey(Key('chat-row-$id')),
|
||||
matching: find.byKey(appListRowAccentKey),
|
||||
Finder _accent(String id) => find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is AppListRow &&
|
||||
widget.key == Key('chat-row-$id') &&
|
||||
widget.accent != null,
|
||||
);
|
||||
|
||||
Color _accentColor(WidgetTester tester, String id) {
|
||||
final box = tester.widget<DecoratedBox>(_accent(id));
|
||||
final border = (box.decoration as BoxDecoration).border as BorderDirectional;
|
||||
return border.start.color;
|
||||
}
|
||||
Color _accentColor(WidgetTester tester, String id) =>
|
||||
tester.widget<AppListRow>(_accent(id)).accent!;
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
@@ -214,7 +213,8 @@ void main() {
|
||||
AppListRow.selectedColor(context, cupertino: false),
|
||||
reason: 'The selected fill, not the tint, marks the open row',
|
||||
);
|
||||
expect(find.byKey(appListRowAccentKey), findsOneWidget);
|
||||
expect(find.byKey(appListRowAccentKey), findsNothing);
|
||||
expect(find.byKey(const ValueKey('chat-visibility-s1')), findsOneWidget);
|
||||
});
|
||||
|
||||
group('controller', () {
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart';
|
||||
import 'package:pipelines_app/ui/layout/app_list_row.dart';
|
||||
import 'package:pipelines_app/features/chat/data/chat_repository.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_compact_sidebar.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_body.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_controller.dart';
|
||||
import 'chat_test_harness.dart' show MemoryChatSessionLocalStore;
|
||||
import 'fake_chat_gateway.dart';
|
||||
|
||||
BorderSide edge(WidgetTester tester, String id) {
|
||||
final box = tester.widget<DecoratedBox>(
|
||||
find
|
||||
.descendant(
|
||||
of: find.byKey(ValueKey('chat-visibility-$id')),
|
||||
matching: find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is DecoratedBox &&
|
||||
widget.position == DecorationPosition.foreground,
|
||||
),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
return ((box.decoration as BoxDecoration).border as BorderDirectional).start;
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'only visible chats have an edge; active edge widens continuously',
|
||||
(tester) async {
|
||||
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
||||
const FakeAccessibilityFeatures(disableAnimations: false);
|
||||
addTearDown(
|
||||
tester.platformDispatcher.clearAccessibilityFeaturesTestValue,
|
||||
);
|
||||
var active = false;
|
||||
late StateSetter update;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
update = setState;
|
||||
return Column(
|
||||
children: [
|
||||
ChatSessionRow(
|
||||
selected: true,
|
||||
session: const {
|
||||
'id': 'off',
|
||||
'title': 'Not visible',
|
||||
'color': 'teal',
|
||||
},
|
||||
onOpen: (_) {},
|
||||
onAction: (_) {},
|
||||
),
|
||||
ChatSessionRow(
|
||||
session: const {
|
||||
'id': 'on',
|
||||
'title': 'Visible',
|
||||
'color': 'red',
|
||||
},
|
||||
visible: true,
|
||||
selected: active,
|
||||
onOpen: (_) {},
|
||||
onAction: (_) {},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(edge(tester, 'off').style, BorderStyle.none);
|
||||
expect(edge(tester, 'on').width, 3);
|
||||
expect(find.byKey(appListRowAccentKey), findsNothing);
|
||||
update(() => active = true);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
expect(edge(tester, 'on').width, greaterThan(3));
|
||||
expect(edge(tester, 'on').width, lessThan(7));
|
||||
await tester.pumpAndSettle();
|
||||
expect(edge(tester, 'on').width, 7);
|
||||
update(() => active = false);
|
||||
await tester.pumpAndSettle();
|
||||
expect(edge(tester, 'on').width, 3);
|
||||
},
|
||||
);
|
||||
testWidgets('compact chats keep identity colours and visible/active edges', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeChatGateway()
|
||||
..sessionsHandler = () async => {
|
||||
'chat_sessions': [
|
||||
{'id': 'a', 'title': 'Amber', 'color': 'red'},
|
||||
{'id': 'b', 'title': 'Beta', 'color': 'teal'},
|
||||
{'id': 'c', 'title': 'Charlie', 'color': 'blue'},
|
||||
],
|
||||
};
|
||||
addTearDown(gateway.pushed.close);
|
||||
final controller = ChatSessionsController(
|
||||
ChatRepository(gateway),
|
||||
localStore: MemoryChatSessionLocalStore(),
|
||||
);
|
||||
addTearDown(controller.dispose);
|
||||
await controller.refresh();
|
||||
final folds = ChatSectionFolds();
|
||||
addTearDown(folds.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ChatCompactSidebar(
|
||||
controller: controller,
|
||||
folds: folds,
|
||||
activeSessionId: 'a',
|
||||
visibleSessionIds: const {'a', 'b'},
|
||||
onOpen: (_) {},
|
||||
onExpand: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byTooltip('Expand chat list'), findsOneWidget);
|
||||
expect(edge(tester, 'a').width, 7);
|
||||
expect(edge(tester, 'b').width, 3);
|
||||
expect(edge(tester, 'c').style, BorderStyle.none);
|
||||
final avatars = tester
|
||||
.widgetList<CircleAvatar>(find.byType(CircleAvatar))
|
||||
.toList();
|
||||
expect(avatars, hasLength(3));
|
||||
expect(avatars.map((a) => a.foregroundColor).toSet(), hasLength(3));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
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_widths.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('compact rail remains draggable in a tight desktop layout', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(600, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final widths = ListPaneWidths(store: MemoryListPaneWidthStore());
|
||||
addTearDown(widths.dispose);
|
||||
var compact = false;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(
|
||||
width: 544,
|
||||
child: ListPaneWidthsScope(
|
||||
widths: widths,
|
||||
child: StatefulBuilder(
|
||||
builder: (context, update) => ListDetailPanes(
|
||||
list: const Text('List'),
|
||||
detail: const Text('Detail'),
|
||||
compactListWidth: 72,
|
||||
listWidthOverride: compact ? 72 : null,
|
||||
onListCompactChanged: (value) =>
|
||||
update(() => compact = value),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final divider = find.byKey(const ValueKey('list-detail-divider'));
|
||||
expect(divider, findsOneWidget);
|
||||
final gesture = await tester.startGesture(tester.getCenter(divider));
|
||||
await gesture.moveBy(const Offset(-90, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(compact, isTrue);
|
||||
expect(
|
||||
tester.getTopLeft(find.byKey(const ValueKey('list-detail-body'))).dx,
|
||||
73,
|
||||
);
|
||||
await gesture.moveBy(const Offset(110, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(compact, isFalse);
|
||||
await gesture.up();
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user