f7b5958d64
A chat's colour is picked from its row menu (Colour...), a long-press or the chat information sheet. The list shows it as a leading bar, a faint row tint and a coloured avatar; the open chat shows a faint wash under its top bar. Shades are Cupertino's dynamic system colours and Material swatches tuned per brightness. Changes from other devices apply live. Ctrl+1...Ctrl+9 open the Nth item of the open tab's list (chats, runs, pipelines) in on-screen order, also while typing. Starred chats are sorted by name, case-insensitively, as one alphabetical group.
73 lines
2.5 KiB
Dart
73 lines
2.5 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_colors.dart';
|
|
import 'package:pipelines_app/features/chat/domain/chat_sessions.dart';
|
|
|
|
List<String> _ids(Iterable<JsonMap> rows) => [
|
|
for (final row in rows) '${row['id']}',
|
|
];
|
|
|
|
void main() {
|
|
// Server recency order: the newest first.
|
|
final rows = <JsonMap>[
|
|
{'id': 'c1', 'title': 'zeta', 'directory': '/b', 'starred': true},
|
|
{'id': 'c2', 'title': 'Recent', 'directory': '/a'},
|
|
{'id': 'c3', 'title': 'Alpha', 'directory': '/b', 'starred': true},
|
|
{'id': 'c4', 'title': 'Older', 'directory': '/b'},
|
|
{'id': 'c6', 'title': 'beta', 'directory': '/a', 'starred': true},
|
|
{'id': 'c5', 'title': 'Beta', 'directory': '/c', 'starred': true},
|
|
{'id': 'c7', 'title': 'Oldest', 'directory': '/a'},
|
|
{'id': 'c8', 'title': 'Done', 'closed_at': 1, 'starred': true},
|
|
];
|
|
|
|
test('starred chats are alphabetical, ignoring case, ties by id', () {
|
|
final sections = chatSessionSections(rows);
|
|
expect(sections.map((s) => s.title), ['Starred', 'Chats', 'Closed']);
|
|
expect(_ids(sections[0].sessions), ['c3', 'c5', 'c6', 'c1']);
|
|
// The other sections keep the server's recency order.
|
|
expect(_ids(sections[1].sessions), ['c2', 'c4', 'c7']);
|
|
expect(_ids(sections[2].sessions), ['c8']);
|
|
});
|
|
|
|
test('a starred chat keeps its place when another is used', () {
|
|
final used = [rows[2], ...rows.where((r) => r['id'] != 'c3')];
|
|
expect(
|
|
_ids(chatSessionSections(used).first.sessions),
|
|
_ids(chatSessionSections(rows).first.sessions),
|
|
);
|
|
});
|
|
|
|
test(
|
|
'list order: starred whole, then chats by directory, folded skipped',
|
|
() {
|
|
final sections = chatSessionSections(rows);
|
|
expect(
|
|
_ids(chatSessionsInListOrder(sections, isOpen: (t) => t != 'Closed')),
|
|
['c3', 'c5', 'c6', 'c1', 'c2', 'c7', 'c4'],
|
|
);
|
|
expect(_ids(chatSessionsInListOrder(sections, isOpen: (_) => true)), [
|
|
'c3',
|
|
'c5',
|
|
'c6',
|
|
'c1',
|
|
'c2',
|
|
'c7',
|
|
'c4',
|
|
'c8',
|
|
]);
|
|
expect(
|
|
_ids(chatSessionsInListOrder(sections, isOpen: (t) => t == 'Chats')),
|
|
['c2', 'c7', 'c4'],
|
|
);
|
|
},
|
|
);
|
|
|
|
test('only palette names are colours', () {
|
|
expect(chatSessionColor({'color': 'teal'}), 'teal');
|
|
expect(chatSessionColor({'color': '#ff0000'}), isNull);
|
|
expect(chatSessionColor({}), isNull);
|
|
expect(chatSessionColor(null), isNull);
|
|
expect(chatColorNames, hasLength(8));
|
|
});
|
|
}
|