Files
pipelines/app/test/ui/layout/memo_subtree_test.dart
T
alan 7b1455631b Rebuild only changed list rows and lay out big artifact sections lazily
Runs and chat session rows are memoized on their own data (MemoSubtree), so
a run event or a chat's running change rebuilds one row instead of every
built row. The artifact gallery's open sections are lazy slivers revealed
by a sliver open/close animation, and thumbnails decode at display size.
Benches in test/perf measure both.
2026-11-02 00:08:29 +00:00

52 lines
1.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/layout/memo_subtree.dart';
void main() {
testWidgets('rebuilds only when the memo changes', (tester) async {
var builds = 0;
Widget host(Object memo) => Directionality(
textDirection: TextDirection.ltr,
child: MemoSubtree(
memo: memo,
builder: (_) {
builds++;
return Text('$memo');
},
),
);
await tester.pumpWidget(host((MemoMap({'id': 1, 'a': 'x'}), true)));
// An equal map (a new instance) and equal props keep the built child.
await tester.pumpWidget(host((MemoMap({'id': 1, 'a': 'x'}), true)));
expect(builds, 1);
await tester.pumpWidget(host((MemoMap({'id': 1, 'a': 'y'}), true)));
expect(builds, 2);
await tester.pumpWidget(host((MemoMap({'id': 1, 'a': 'y'}), false)));
expect(builds, 3);
});
testWidgets('the built subtree still follows its inherited widgets', (
tester,
) async {
Widget host(Color color) => MaterialApp(
theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: color)),
home: MemoSubtree(
memo: 1,
builder: (_) => Builder(
builder: (context) => ColoredBox(
key: const Key('box'),
color: Theme.of(context).colorScheme.primary,
),
),
),
);
Color shown() =>
tester.widget<ColoredBox>(find.byKey(const Key('box'))).color;
await tester.pumpWidget(host(Colors.red));
final before = shown();
await tester.pumpWidget(host(Colors.blue));
await tester.pumpAndSettle();
expect(shown(), isNot(before));
});
}