import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/chat/domain/chat_quick_switch.dart'; final rows = [ {'id': 'r1', 'title': 'Recent work', 'directory': '/home/a/alpha'}, {'id': 'z', 'title': 'Zeta notes', 'starred': true}, { 'id': 'r2', 'title': 'Older', 'directory': '/home/a/beta', 'backend': 'codex', }, {'id': 'r3', 'title': 'Same folder', 'directory': '/home/a/alpha'}, {'id': 'a', 'title': 'Alpha starred', 'starred': true}, {'id': 'c', 'title': 'Closed one', 'closed_at': 5}, {'id': 'x', 'title': 'Closed flag', 'closed': true}, { 'id': 'f', 'title': 'Far away', '_server_id': 'm2', '_server_name': 'Studio', }, ]; List ids(List rows) => [ for (final row in rows) '${row['id']}', ]; void main() { test('no query lists open chats in list order, starred first', () { // Starred by name, then Chats by directory group in server recency. expect(ids(chatQuickSwitchCandidates(rows)), [ 'a', 'z', 'r1', 'r3', 'r2', 'f', ]); }); test('a query narrows by title, directory, harness and machine', () { final open = chatQuickSwitchCandidates(rows); expect(ids(chatQuickSwitchMatches(open, 'beta')), ['r2']); expect(ids(chatQuickSwitchMatches(open, 'CODEX')), ['r2']); expect(ids(chatQuickSwitchMatches(open, 'studio')), ['f']); expect( ids(chatQuickSwitchMatches(open, 'lab', serverName: (_) => 'Lab box')), ['a', 'z', 'r1', 'r3', 'r2', 'f'], ); expect(ids(chatQuickSwitchMatches(open, 'closed')), isEmpty); expect(ids(chatQuickSwitchMatches(open, 'nothing here')), isEmpty); expect(ids(chatQuickSwitchMatches(open, ' ')), ids(open)); }); test('title starts rank before word starts, then substrings', () { final open = chatQuickSwitchCandidates([ {'id': 'mid', 'title': 'kalpha'}, {'id': 'dir', 'title': 'Other', 'directory': '/src/alpha'}, {'id': 'word', 'title': 'The alpha plan'}, {'id': 'start', 'title': 'Alpha first'}, {'id': 'inner', 'title': 'Other', 'directory': '/src/xalphax'}, ]); expect(ids(chatQuickSwitchMatches(open, 'alp')), [ 'start', 'word', 'dir', 'mid', 'inner', ]); }); test('every word must match; ranks add up', () { final open = chatQuickSwitchCandidates(rows); expect(ids(chatQuickSwitchMatches(open, 'same alpha')), ['r3']); expect(ids(chatQuickSwitchMatches(open, 'alpha')), ['a', 'r1', 'r3']); }); test('an unnamed harness is OpenCode', () { expect(chatQuickSwitchHarness({'id': 'q'}), 'opencode'); expect(chatQuickSwitchHarness({'backend': 'claude'}), 'claude'); }); }