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.
108 lines
3.4 KiB
Dart
108 lines
3.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/ui/layout/sliver_reveal.dart';
|
|
|
|
void main() {
|
|
Widget host({
|
|
required bool open,
|
|
Duration duration = kThemeAnimationDuration,
|
|
}) => MaterialApp(
|
|
home: CustomScrollView(
|
|
slivers: [
|
|
SliverReveal(
|
|
open: open,
|
|
duration: duration,
|
|
curve: Curves.easeInOut,
|
|
sliver: SliverList.builder(
|
|
itemCount: 1000,
|
|
itemBuilder: (_, index) =>
|
|
SizedBox(height: 50, child: Text('item $index')),
|
|
),
|
|
),
|
|
const SliverToBoxAdapter(child: Text('after')),
|
|
],
|
|
),
|
|
);
|
|
|
|
double afterTop(WidgetTester tester) =>
|
|
tester.getTopLeft(find.text('after')).dy;
|
|
|
|
testWidgets('closed builds nothing; open builds only the visible items', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(host(open: false));
|
|
expect(find.textContaining('item'), findsNothing);
|
|
expect(afterTop(tester), 0);
|
|
|
|
await tester.pumpWidget(host(open: true));
|
|
await tester.pump(kThemeAnimationDuration ~/ 2);
|
|
// Part-way open: the items reveal from the top, clipped at the extent.
|
|
expect(find.text('item 0'), findsOneWidget);
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('item 0'), findsOneWidget);
|
|
expect(find.text('item 999', skipOffstage: false), findsNothing);
|
|
expect(tester.widgetList(find.textContaining('item')).length, lessThan(40));
|
|
});
|
|
|
|
testWidgets('closing shrinks the extent, then drops the items', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: CustomScrollView(
|
|
slivers: [
|
|
SliverReveal(
|
|
open: true,
|
|
duration: kThemeAnimationDuration,
|
|
curve: Curves.linear,
|
|
sliver: SliverList.list(
|
|
children: [
|
|
for (var i = 0; i < 4; i++)
|
|
SizedBox(height: 50, child: Text('item $i')),
|
|
],
|
|
),
|
|
),
|
|
const SliverToBoxAdapter(child: Text('after')),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
expect(afterTop(tester), 200);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: CustomScrollView(
|
|
slivers: [
|
|
SliverReveal(
|
|
open: false,
|
|
duration: kThemeAnimationDuration,
|
|
curve: Curves.linear,
|
|
sliver: SliverList.list(
|
|
children: [
|
|
for (var i = 0; i < 4; i++)
|
|
SizedBox(height: 50, child: Text('item $i')),
|
|
],
|
|
),
|
|
),
|
|
const SliverToBoxAdapter(child: Text('after')),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
await tester.pump(kThemeAnimationDuration ~/ 2);
|
|
expect(afterTop(tester), closeTo(100, 1));
|
|
await tester.pumpAndSettle();
|
|
expect(afterTop(tester), 0);
|
|
expect(find.textContaining('item'), findsNothing);
|
|
});
|
|
|
|
testWidgets('no motion opens and closes at once', (tester) async {
|
|
await tester.pumpWidget(host(open: false, duration: Duration.zero));
|
|
await tester.pumpWidget(host(open: true, duration: Duration.zero));
|
|
await tester.pump();
|
|
expect(find.text('item 0'), findsOneWidget);
|
|
await tester.pumpWidget(host(open: false, duration: Duration.zero));
|
|
await tester.pump();
|
|
expect(find.textContaining('item'), findsNothing);
|
|
});
|
|
}
|