Files
pipelines/app/test/features/chat/domain/chat_cycle_test.dart
T
alan 23d8658e80 Chat: Ctrl+Tab cycles the list's chats, starred only when any are starred
Ctrl+Tab / Ctrl+Shift+Tab on the Chat destination now steps through the
chat list's open chats in list order (wrapping) instead of the workspace
panes: only the starred chats when any open chat is starred, otherwise all
open chats. From a chat outside the cycle it goes to the first (Shift: last).
The target opens as a list click does, focusing the pane already showing it.
The terminal's claim on Ctrl+Tab and floating-window cycling are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 14:28:18 +00:00

100 lines
3.3 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/domain/chat_cycle.dart';
List<String> _ids(List<JsonMap> rows) => [
for (final row in rows) '${row['id']}',
];
String? _after(List<JsonMap> rows, String id) =>
chatSessionAfter(rows, id)?['id'] as String?;
bool _closedFolded(String title) => title != 'Closed';
void main() {
// Server recency order; the list regroups it.
final sessions = <JsonMap>[
{'id': 'r', 'title': 'Recent', 'directory': '/w'},
{'id': 'd', 'title': 'Other', 'directory': '/v'},
{'id': 'c', 'title': 'Done', 'directory': '/w', 'closed_at': 1},
{'id': 's', 'title': 'Second', 'directory': '/w'},
{'id': 'z', 'title': 'Zed', 'directory': '/w', 'starred': true},
{'id': 'a', 'title': 'apple', 'directory': '/v', 'starred': true},
];
test('shown rows: Starred by name, Chats by directory, folded skipped', () {
final folded = chatSessionsShown(
sessions,
query: '',
isOpen: _closedFolded,
);
expect(_ids(folded), ['a', 'z', 'r', 's', 'd']);
final open = chatSessionsShown(sessions, query: '', isOpen: (_) => true);
expect(_ids(open), ['a', 'z', 'r', 's', 'd', 'c']);
final searched = chatSessionsShown(
sessions,
query: 'o',
isOpen: (_) => true,
);
expect(_ids(searched), ['d', 's', 'c']);
});
test('next wraps from the last row to the first', () {
final rows = chatSessionsShown(sessions, query: '', isOpen: _closedFolded);
var id = 'a';
final visited = <String>[];
for (var i = 0; i < rows.length; i++) {
id = _after(rows, id)!;
visited.add(id);
}
expect(visited, ['z', 'r', 's', 'd', 'a']);
});
test('a chat in a folded section moves to the first shown row', () {
final rows = chatSessionsShown(sessions, query: '', isOpen: _closedFolded);
expect(_after(rows, 'c'), 'a');
});
test('nothing to move to without another shown row', () {
final one = <JsonMap>[
{'id': 'only'},
];
expect(_after(one, 'only'), isNull);
expect(_after(const [], 'only'), isNull);
expect(_after(one, 'elsewhere'), 'only');
});
String? tab(List<JsonMap> cycle, String id, int step) =>
chatTabTarget(cycle, id, step)?['id'] as String?;
test('tab cycle: starred only when any open chat is starred', () {
final cycle = chatTabCycle(sessions);
expect(_ids(cycle), ['a', 'z']);
expect(tab(cycle, 'a', 1), 'z');
expect(tab(cycle, 'z', 1), 'a');
expect(tab(cycle, 'a', -1), 'z');
// Outside the cycle: first forwards, last backwards.
expect(tab(cycle, 'r', 1), 'a');
expect(tab(cycle, 'r', -1), 'z');
});
test('tab cycle: every open chat when none is starred', () {
final unstarred = [
for (final row in sessions) {...row}..remove('starred'),
];
final cycle = chatTabCycle(unstarred);
expect(_ids(cycle), ['r', 's', 'z', 'd', 'a']);
expect(tab(cycle, 'a', 1), 'r');
expect(tab(cycle, 'r', -1), 'a');
// A closed starred chat does not make a starred cycle.
final closedStar = <JsonMap>[
{'id': 'x', 'starred': true, 'closed_at': 1},
{'id': 'y'},
{'id': 'w', 'closed': true},
];
expect(_ids(chatTabCycle(closedStar)), ['y']);
expect(tab(chatTabCycle(closedStar), 'y', 1), isNull);
expect(tab(const [], 'y', 1), isNull);
});
}