7b1455631b
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.
52 lines
1.7 KiB
Dart
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));
|
|
});
|
|
}
|