import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/chat/domain/chat_find.dart'; void main() { final rows = [ { 'kind': 'user', 'key': 'u1', 'message': { 'id': 'u1', 'parts': [ {'type': 'text', 'text': 'Find the Needle'}, {'type': 'text', 'text': 'and another needle'}, ], }, }, {'kind': 'activity', 'key': 'x', 'label': 'needle in activity'}, { 'kind': 'assistant', 'key': 'a1', 'messageIds': ['a1', 'a2'], 'parts': [ {'type': 'reasoning', 'text': 'needle thoughts'}, {'type': 'text', 'text': 'A **needle** here, needle there'}, {'type': 'text', 'text': ' '}, ], }, ]; test('units are user turns and answer text parts as rendered', () { final units = chatFindUnits(rows, ['k0', 'k1', 'k2']); expect(units.map((u) => u.text), [ 'Find the Needle\nand another needle', 'A **needle** here, needle there', ]); expect(units.map((u) => u.rowKey), ['k0', 'k2']); expect(units.first.messageIds, ['u1']); expect(units.last.messageIds, ['a1', 'a2']); }); test('matches fold case unless asked, in display order', () { final units = chatFindUnits(rows, ['k0', 'k1', 'k2']); final folded = chatFindMatches(units, 'needle', caseSensitive: false); expect(folded.length, 4); expect(folded.first.start, 'Find the '.length); expect(folded.map((m) => m.ordinal), [0, 1, 0, 1]); final exact = chatFindMatches(units, 'Needle', caseSensitive: true); expect(exact.length, 1); }); test('regex characters in the query are literal', () { expect(chatFindRanges('a.b axb (c)', '.', caseSensitive: false), [ (start: 1, end: 2), ]); expect(chatFindRanges('a.b axb (c)', '(c)', caseSensitive: false), [ (start: 8, end: 11), ]); }); test('server hits parse from a scoped reply', () { final hits = ChatFindRemoteHit.fromReply({ 'search_results': { 'results': [ { 'chat': {'message_id': 'm9', 'part': 1, 'offset': 4}, }, { 'chat': {'message_id': 'm8'}, }, ], }, }); expect(hits.map((h) => (h.messageId, h.part, h.offset)), [ ('m9', 1, 4), ('m8', 0, 0), ]); }); }