Skip to content

Commit fa6ba10

Browse files
committed
fix: golden names for TestDecoration
1 parent 103e271 commit fa6ba10

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

packages/flutter/test/widgets/container_test.dart

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ void main() {
633633
});
634634

635635
testWidgets('getClipPath() works for lots of kinds of decorations', (WidgetTester tester) async {
636-
Future<void> test(Decoration decoration) async {
636+
Future<void> test(Decoration decoration, [String? name]) async {
637637
await tester.pumpWidget(
638638
Directionality(
639639
textDirection: TextDirection.rtl,
@@ -653,12 +653,12 @@ void main() {
653653
);
654654
await expectLater(
655655
find.byType(Container),
656-
matchesGoldenFile('container_test.getClipPath.${decoration.runtimeType}.png'),
656+
matchesGoldenFile('container_test.getClipPath.${name ?? decoration.runtimeType}.png'),
657657
);
658658
}
659659

660660
await test(const BoxDecoration());
661-
await test(const _TestDecoration());
661+
await test(const _TestDecoration(), 'UnderlineTabIndicator');
662662
await test(const ShapeDecoration(shape: StadiumBorder()));
663663
await test(const FlutterLogoDecoration());
664664
});
@@ -845,13 +845,32 @@ class _TestDecoration extends Decoration {
845845

846846
@override
847847
Path getClipPath(Rect rect, TextDirection textDirection) {
848-
return Path()..addRRect(RRect.fromRectAndRadius(rect, const Radius.circular(10)));
848+
const borderSideWidth = 2.0;
849+
final indicator = Rect.fromLTWH(
850+
rect.left,
851+
rect.bottom - borderSideWidth,
852+
rect.width,
853+
borderSideWidth,
854+
);
855+
return Path()..addRect(indicator);
849856
}
850857
}
851858

852859
class _TestDecorationPainter extends BoxPainter {
853860
@override
854861
void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
855-
// No painting needed for clip path testing.
862+
assert(configuration.size != null);
863+
final Rect rect = offset & configuration.size!;
864+
const borderSideWidth = 2.0;
865+
const color = Color(0xFFFFFFFF);
866+
final paint = Paint()
867+
..color = color
868+
..strokeCap = StrokeCap.square
869+
..strokeWidth = borderSideWidth
870+
..style = PaintingStyle.stroke;
871+
final Offset indicatorBottomLeft = rect.bottomLeft + const Offset(0.0, -borderSideWidth / 2.0);
872+
final Offset indicatorBottomRight =
873+
rect.bottomRight + const Offset(0.0, -borderSideWidth / 2.0);
874+
canvas.drawLine(indicatorBottomLeft, indicatorBottomRight, paint);
856875
}
857876
}

packages/flutter/test/widgets/page_view_test.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ void main() {
2626
const kOrange = Color(0xFFFF8C00);
2727
const kPurple = Color(0xFF800080);
2828
const kYellow = Color(0xFFFFFF00);
29+
const kBlack87 = Color(0xDD000000);
2930

3031
// Regression test for https://github.com/flutter/flutter/issues/100451
3132
testWidgets('PageView.builder respects findChildIndexCallback', (WidgetTester tester) async {
@@ -1254,6 +1255,12 @@ void main() {
12541255

12551256
await tester.pumpWidget(
12561257
TestWidgetsApp(
1258+
builder: (BuildContext context, Widget? child) {
1259+
return DefaultTextStyle(
1260+
style: const TextStyle(color: kBlack87, fontSize: 14.0),
1261+
child: child!,
1262+
);
1263+
},
12571264
home: Center(
12581265
child: SizedBox(
12591266
width: pixel6EmulatorWidth,

0 commit comments

Comments
 (0)