fix(app): a sent message keeps its place in the transcript, so each reply follows it

This commit is contained in:
2026-10-23 15:34:46 +01:00
parent d791fce36c
commit 37c155e6e9
4 changed files with 95 additions and 45 deletions
@@ -0,0 +1,52 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'chat_composer_bar_fixtures.dart';
import 'chat_thread_fixtures.dart';
void main() {
testWidgets('each reply follows the message it answers, in its own box', (
tester,
) async {
tester.view.physicalSize = const Size(800, 2400);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
var operation = 0;
final gateway = ComposerBarGateway();
addTearDown(gateway.close);
await tester.pumpWidget(
composerThread(gateway, newOperationId: () => 'op-${++operation}'),
);
await tester.pumpAndSettle();
Future<void> send(String text) async {
await tester.enterText(
find.byKey(const Key('chat-composer-field')),
text,
);
await tester.pump();
await tester.tap(find.byKey(const Key('chat-composer-primary')));
await tester.pump();
}
double top(String text) => tester
.getTopLeft(find.textContaining(text, findRichText: true).first)
.dy;
// The reply streams in before the server echoes the operator's turn.
await send('first question');
gateway.emitEvent(chatTextFrame('first answer', messageId: 'a1'));
await tester.pump();
gateway.emitEvent(chatStepFrame('ended'));
await tester.pump();
await send('second question');
gateway.emitEvent(chatTextFrame('second answer', messageId: 'a2'));
await tester.pumpAndSettle();
expect(top('first question'), lessThan(top('first answer')));
expect(top('first answer'), lessThan(top('second question')));
expect(top('second question'), lessThan(top('second answer')));
});
}