import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/chat/domain/chat_transcript_days.dart'; int _at(int day, int hour) => DateTime(2026, 11, day, hour).millisecondsSinceEpoch; JsonMap _user(int? time) => { 'kind': 'user', 'message': {'created_at': ?time}, }; JsonMap _turn(int? time) => {'kind': 'assistant', 'created_at': ?time}; void main() { test('a row takes its own, its message\'s or its first notice\'s time', () { expect(chatRowCreatedAt(_turn(_at(24, 9))), _at(24, 9)); expect(chatRowCreatedAt(_user(_at(24, 10))), _at(24, 10)); expect( chatRowCreatedAt({ 'kind': 'task_notices', 'messages': [ {'created_at': 'bad'}, {'created_at': _at(25, 8)}, ], }), _at(25, 8), ); expect(chatRowCreatedAt({'kind': 'question', 'form': {}}), isNull); }); test('one divider per calendar day, at that day\'s first timed row', () { final rows = [ _turn(null), // an untimed row neither starts nor breaks a day _user(_at(24, 9)), _turn(_at(24, 9)), {'kind': 'questions'}, _user(_at(24, 23)), _turn(_at(25, 0)), _user(null), _user(_at(25, 10)), _turn(_at(26, 7)), ]; expect(chatDayDividers(rows), [ null, DateTime(2026, 11, 24), null, null, null, DateTime(2026, 11, 25), null, null, DateTime(2026, 11, 26), ]); }); test('no times, no dividers', () { expect(chatDayDividers([_turn(null), _user(null)]), [null, null]); }); }