Chat stack: groups of open chats, synced with the open-chat set
A chat dropped onto the middle of another makes a named group (asked at once, "Group N" by default); onto a group it joins, a group dropped onto a chat takes it in, groups merge. The top level shows each group as a small pile with its name and count; a tap opens it in place under a header that leads back (also the scrim, Back and Escape). In a group, dropping a chat on the header leaves the group; a group of one dissolves. The close button ungroups a dropped group with Undo. Rename, Ungroup, Close all (with Undo), Move to group and Remove from group are in the group menu and as semantic actions. Each open-chat entry carries its group name (protocol field "group", omitted when ungrouped; older clients ignore it), stored and pushed by the server like the order; names are trimmed, printable, at most 80 characters. Needs a server restart to keep groups. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/stack/chat_stack_drop_target.dart';
|
||||
import 'package:pipelines_app/features/chat/stack/chat_stack_entry.dart';
|
||||
import 'package:pipelines_app/features/chat/stack/chat_stack_group_ops.dart';
|
||||
import 'package:pipelines_app/features/chat/stack/chat_stack_groups.dart';
|
||||
import 'package:pipelines_app/features/chat/stack/chat_stack_node.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_open_workspace_gateway.dart';
|
||||
|
||||
ChatStackEntry _entry(String id, [String? group]) =>
|
||||
ChatStackEntry(paneId: 'p$id', session: {'id': id}, group: group);
|
||||
|
||||
void main() {
|
||||
group('ChatStackGroups', () {
|
||||
test('assigns, merges on rename, dissolves a group of one', () {
|
||||
final groups = ChatStackGroups();
|
||||
var changes = 0;
|
||||
groups.addListener(() => changes++);
|
||||
// One chat is no group.
|
||||
groups.assign(['a'], 'Work');
|
||||
expect(groups.assignments, isEmpty);
|
||||
expect(changes, 0);
|
||||
groups.assign(['a', 'b'], 'Work');
|
||||
groups.assign(['c', 'd'], 'Home');
|
||||
expect(groups.membersOf('Work'), ['a', 'b']);
|
||||
expect(groups.nextName(), 'Group 1');
|
||||
groups.rename('Home', 'Work');
|
||||
expect(groups.membersOf('Work'), ['a', 'b', 'c', 'd']);
|
||||
groups.unassign(['a', 'b', 'c']);
|
||||
expect(groups.assignments, isEmpty);
|
||||
groups.assign(['a', 'b', 'c'], 'Group 1');
|
||||
expect(groups.nextName(), 'Group 2');
|
||||
groups.retain({'a', 'x'});
|
||||
expect(groups.assignments, isEmpty);
|
||||
expect(changes, greaterThan(0));
|
||||
groups.dispose();
|
||||
});
|
||||
|
||||
test('names are trimmed, bounded and never empty', () {
|
||||
expect(chatStackGroupName(' Work \n'), 'Work');
|
||||
expect(chatStackGroupName(' '), isNull);
|
||||
expect(chatStackGroupName('a\tb'), 'a b');
|
||||
expect(chatStackGroupName('x' * 100)!.length, chatStackGroupNameLimit);
|
||||
});
|
||||
});
|
||||
|
||||
group('nodes and drops', () {
|
||||
final entries = [
|
||||
_entry('a'),
|
||||
_entry('b', 'Work'),
|
||||
_entry('c'),
|
||||
_entry('d', 'Work'),
|
||||
];
|
||||
final nodes = chatStackNodes(entries);
|
||||
|
||||
test('a group stands where its first chat is', () {
|
||||
expect(nodes.map((node) => node.key), [
|
||||
'chat:pa',
|
||||
'group:Work',
|
||||
'chat:pc',
|
||||
]);
|
||||
expect(chatStackOrder(nodes), ['a', 'b', 'd', 'c']);
|
||||
// A lone member shows as a chat.
|
||||
expect(
|
||||
chatStackNodes([_entry('x', 'Solo')]).single,
|
||||
isA<ChatStackChatNode>(),
|
||||
);
|
||||
});
|
||||
|
||||
test('dropping onto a chat or a group joins as expected', () {
|
||||
final made = chatStackJoined(nodes, 2, 0, () => 'Group 1');
|
||||
expect(made.created, isTrue);
|
||||
expect(made.join, ['a', 'c']);
|
||||
expect(made.order, ['a', 'c', 'b', 'd']);
|
||||
final joined = chatStackJoined(nodes, 0, 1, () => 'unused');
|
||||
expect((joined.group, joined.created), ('Work', false));
|
||||
expect(joined.join, ['a']);
|
||||
expect(joined.order, ['b', 'd', 'a', 'c']);
|
||||
final took = chatStackJoined(nodes, 1, 2, () => 'unused');
|
||||
expect(took.join, ['c']);
|
||||
expect(took.order, ['a', 'b', 'd', 'c']);
|
||||
expect(chatStackLeft(nodes, 'Work', 'b'), ['a', 'd', 'b', 'c']);
|
||||
expect(chatStackRegrouped(nodes, 'Work', ['d', 'b']), [
|
||||
'a',
|
||||
'd',
|
||||
'b',
|
||||
'c',
|
||||
]);
|
||||
expect(chatStackMoved(nodes, 0, 2), ['b', 'd', 'c', 'a']);
|
||||
});
|
||||
|
||||
test('the middle of an item groups, its edges reorder, stably', () {
|
||||
bool all(int _) => true;
|
||||
// From slot 0, one slot up: the middle of item 1.
|
||||
expect(
|
||||
chatStackDropTarget(
|
||||
position: 1,
|
||||
from: 0,
|
||||
count: 3,
|
||||
slot: 0,
|
||||
canDropOnto: all,
|
||||
),
|
||||
(slot: 0, onto: 1),
|
||||
);
|
||||
// Past its middle: the gap moves above it...
|
||||
expect(
|
||||
chatStackDropTarget(
|
||||
position: 1.4,
|
||||
from: 0,
|
||||
count: 3,
|
||||
slot: 0,
|
||||
canDropOnto: all,
|
||||
),
|
||||
(slot: 1, onto: null),
|
||||
);
|
||||
// ...and holds there while item 1 slides below it.
|
||||
expect(
|
||||
chatStackDropTarget(
|
||||
position: 1.3,
|
||||
from: 0,
|
||||
count: 3,
|
||||
slot: 1,
|
||||
canDropOnto: all,
|
||||
),
|
||||
(slot: 1, onto: null),
|
||||
);
|
||||
// Below its middle the gap stays below it.
|
||||
expect(
|
||||
chatStackDropTarget(
|
||||
position: .7,
|
||||
from: 0,
|
||||
count: 3,
|
||||
slot: 0,
|
||||
canDropOnto: all,
|
||||
),
|
||||
(slot: 0, onto: null),
|
||||
);
|
||||
// Without grouping the middle reorders too; the gap never passes
|
||||
// lastSlot.
|
||||
expect(
|
||||
chatStackDropTarget(
|
||||
position: 2.3,
|
||||
from: 0,
|
||||
count: 3,
|
||||
slot: 1,
|
||||
lastSlot: 1,
|
||||
),
|
||||
(slot: 1, onto: null),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('an entry carries its group over the wire', () {
|
||||
final entry = ChatOpenWorkspaceEntry.fromJson({
|
||||
'session_id': 'a',
|
||||
'group': ' Work ',
|
||||
})!;
|
||||
expect(entry.group, 'Work');
|
||||
expect(entry.toJson(), {'session_id': 'a', 'group': 'Work'});
|
||||
expect(ChatOpenWorkspaceEntry.fromJson({'session_id': 'b'})!.group, isNull);
|
||||
const snapshot = ChatOpenWorkspaceSnapshot(1, [
|
||||
ChatOpenWorkspaceEntry('a'),
|
||||
]);
|
||||
expect(
|
||||
snapshot.sameEntries([const ChatOpenWorkspaceEntry('a', group: 'W')]),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user