7b045e5aab
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
2.3 KiB
Dart
83 lines
2.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/rendering.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/ui/status/app_spinner.dart';
|
|
|
|
void main() {
|
|
testWidgets('the spinner owns its controller, so no per-frame lookup', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
const MaterialApp(home: Center(child: AppSpinner(strokeWidth: 2))),
|
|
);
|
|
final indicator = tester.widget<CircularProgressIndicator>(
|
|
find.byType(CircularProgressIndicator),
|
|
);
|
|
expect(indicator.controller, isNotNull);
|
|
expect(indicator.controller!.isAnimating, isTrue);
|
|
expect(indicator.strokeWidth, 2);
|
|
await tester.pumpWidget(const SizedBox());
|
|
});
|
|
|
|
testWidgets('a spinning row does not lay its list out again every frame', (
|
|
tester,
|
|
) async {
|
|
final layouts = <int>[0];
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: ListView(
|
|
children: [
|
|
for (var i = 0; i < 3; i++)
|
|
_LayoutCount(
|
|
layouts: layouts,
|
|
// A list row that picks its layout from its width, as
|
|
// AppListRow does.
|
|
child: LayoutBuilder(
|
|
builder: (context, constraints) => Row(
|
|
children: [
|
|
if (i == 1)
|
|
const SizedBox.square(
|
|
dimension: 12,
|
|
child: AppSpinner(strokeWidth: 2),
|
|
),
|
|
Text('row $i'),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
final before = layouts[0];
|
|
for (var frame = 0; frame < 10; frame++) {
|
|
await tester.pump(const Duration(milliseconds: 16));
|
|
}
|
|
expect(layouts[0], before);
|
|
await tester.pumpWidget(const SizedBox());
|
|
});
|
|
}
|
|
|
|
/// Counts the layouts of a list row.
|
|
class _LayoutCount extends SingleChildRenderObjectWidget {
|
|
const _LayoutCount({required this.layouts, required super.child});
|
|
|
|
final List<int> layouts;
|
|
|
|
@override
|
|
RenderObject createRenderObject(BuildContext context) =>
|
|
_RenderLayoutCount(layouts);
|
|
}
|
|
|
|
class _RenderLayoutCount extends RenderProxyBox {
|
|
_RenderLayoutCount(this.layouts);
|
|
|
|
final List<int> layouts;
|
|
|
|
@override
|
|
void performLayout() {
|
|
layouts[0]++;
|
|
super.performLayout();
|
|
}
|
|
}
|