20bf6202b3
Reuse unchanged transcript rows, the composer bar and the header across streamed deltas, and share parsed markdown by text so rows scrolled back into view are not parsed again. Adds a rebuild/parse harness and a release-web frame-timing probe with a long-transcript fixture.
71 lines
2.2 KiB
Dart
71 lines
2.2 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/chat/conversation/chat_row_widgets.dart';
|
|
import 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_cache.dart';
|
|
|
|
void main() {
|
|
test('chatJsonEquals compares decoded JSON structurally', () {
|
|
expect(
|
|
chatJsonEquals(
|
|
{
|
|
'a': [
|
|
1,
|
|
'x',
|
|
{'b': true},
|
|
],
|
|
},
|
|
{
|
|
'a': [
|
|
1,
|
|
'x',
|
|
{'b': true},
|
|
],
|
|
},
|
|
),
|
|
isTrue,
|
|
);
|
|
expect(chatJsonEquals({'a': 1}, {'a': 2}), isFalse);
|
|
expect(chatJsonEquals({'a': 1}, {'b': 1}), isFalse);
|
|
expect(chatJsonEquals([1, 2], [1, 2, 3]), isFalse);
|
|
expect(chatJsonEquals({'a': null}, <String, dynamic>{}), isFalse);
|
|
});
|
|
|
|
test('ChatRowWidgets reuses a widget until its row or inputs change', () {
|
|
final rows = ChatRowWidgets();
|
|
var builds = 0;
|
|
Widget build() {
|
|
builds++;
|
|
return SizedBox(width: builds.toDouble());
|
|
}
|
|
|
|
final first = rows.widgetFor('k', {'text': 'a'}, [1], build);
|
|
expect(rows.widgetFor('k', {'text': 'a'}, [1], build), same(first));
|
|
expect(builds, 1);
|
|
expect(rows.widgetFor('k', {'text': 'b'}, [1], build), isNot(same(first)));
|
|
final second = rows.widgetFor('k', {'text': 'b'}, [2], build);
|
|
expect(builds, 3);
|
|
rows.prune();
|
|
// A row the last build did not ask for is forgotten.
|
|
rows.prune();
|
|
expect(rows.widgetFor('k', {'text': 'b'}, [2], build), isNot(same(second)));
|
|
expect(builds, 4);
|
|
});
|
|
|
|
test('ChatMarkdownCache parses a text once and stays bounded', () {
|
|
final cache = ChatMarkdownCache(maxEntries: 2, maxChars: 100);
|
|
final blocks = cache.blocksFor('# One');
|
|
expect(cache.blocksFor('# One'), same(blocks));
|
|
expect(cache.parses, 1);
|
|
cache.blocksFor('two');
|
|
cache.blocksFor('three');
|
|
// The least recently used text was evicted and parses again.
|
|
expect(cache.blocksFor('# One'), isNot(same(blocks)));
|
|
expect(cache.parses, 4);
|
|
// A text larger than the character budget is parsed but never held.
|
|
final long = 'x' * 200;
|
|
cache.blocksFor(long);
|
|
cache.blocksFor(long);
|
|
expect(cache.parses, 6);
|
|
});
|
|
}
|