Files
pipelines/app/test/features/chat/conversation/chat_row_keys_test.dart
T
alan 6e8c9b1a9e Chat: a sent message rises in from the composer
The just-sent (or queued) message slides up 20px, fades and grows from
0.96 over 280ms on an emphasized decelerate curve. Only a send marks it:
history, scroll restore, other devices, replies and the server copy
replacing the local one appear in place. Row keys follow the operation
id so the server copy keeps the row. Reduced motion shows it at once.
The capture fixture now accepts chat_prompt.
2026-11-03 15:59:34 +00:00

120 lines
3.1 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/conversation/chat_row_keys.dart';
import 'package:pipelines_app/features/chat/domain/chat_transcript.dart';
import 'chat_thread_fixtures.dart';
JsonMap _assistant(String id) => chatMessage(
id,
'assistant',
parts: [
{'type': 'reasoning', 'id': 'r-$id', 'text': 'reasoning $id'},
{'type': 'text', 'id': 't-$id', 'text': 'answer $id'},
],
);
JsonMap _user(String id) => chatMessage(
id,
'user',
parts: [
{'type': 'text', 'text': 'question $id'},
],
);
void main() {
test('an older page prepended into a folded turn keeps its key', () {
final keys = ChatRowKeys();
final newest = keys.forRows(
transcriptRows([_assistant('msg_6'), _assistant('msg_4')]),
);
final paged = keys.forRows(
transcriptRows([
_assistant('msg_2'),
_assistant('msg_0'),
_assistant('msg_6'),
_assistant('msg_4'),
]),
);
expect(newest, hasLength(1));
expect(paged, hasLength(1));
expect(paged.single, newest.single);
});
test('a live assistant message appended to a folded turn keeps its key', () {
final keys = ChatRowKeys();
final newest = keys.forRows(transcriptRows([_assistant('msg_6')]));
final streamed = keys.forRows(
transcriptRows([_assistant('msg_6'), _assistant('msg_live')]),
);
expect(streamed.single, newest.single);
});
test('user rows keep their key and folded turns stay distinct', () {
final keys = ChatRowKeys();
final first = keys.forRows(
transcriptRows([
_user('u1'),
_assistant('a1'),
_user('u2'),
_assistant('a2'),
]),
);
final paged = keys.forRows(
transcriptRows([
_user('u0'),
_assistant('a0'),
_user('u1'),
_assistant('a1'),
_user('u2'),
_assistant('a2'),
]),
);
expect(first.toSet(), hasLength(4));
expect(paged.toSet(), hasLength(6));
expect(paged.sublist(2), first);
});
test('an id-less prepended turn never collides with a held key', () {
final keys = ChatRowKeys();
keys.forRows(transcriptRows([_assistant('a1')]));
final paged = keys.forRows(
transcriptRows([
// No id: only a positional fallback is possible.
chatMessage(
'',
'assistant',
parts: [
{'type': 'text', 'text': 'anonymous older answer'},
],
),
_user('u1'),
_assistant('a1'),
]),
);
expect(paged.toSet(), hasLength(paged.length));
});
test('the server copy of a sent message keeps the local row key', () {
final keys = ChatRowKeys();
final local = keys.forRows(
transcriptRows([
_assistant('msg_0'),
{..._user('local-op1'), 'operation_id': 'op1'},
]),
);
final echoed = keys.forRows(
transcriptRows([
_assistant('msg_0'),
{..._user('srv-1'), 'operation_id': 'op1'},
]),
);
expect(echoed, local);
});
}