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 _ids(Iterable rows) => [ for (final row in rows) '${row['id']}', ]; void main() { // Server recency order: the newest first. final rows = [ {'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)); }); }