Skip to content

Commit 3744219

Browse files
authored
[material_ui] Add more 0x0 size tests part 14 (flutter#13107)
This is my attempt to handle flutter#6537 for the following widgets: ButtonBar MaterialButton RawMaterialButton FilterChip MergeableMaterial
1 parent 8a74ca8 commit 3744219

5 files changed

Lines changed: 65 additions & 0 deletions

File tree

‎packages/material_ui/test/button_bar_test.dart‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,4 +632,19 @@ void main() {
632632
expect(renderButtonBar.debugNeedsLayout, isTrue);
633633
expect(() => renderButtonBar.constraints, throwsStateError);
634634
});
635+
636+
testWidgets('ButtonBar does not crash at zero area', (WidgetTester tester) async {
637+
await tester.pumpWidget(
638+
MaterialApp(
639+
home: Center(
640+
child: SizedBox.shrink(
641+
child: ButtonBar(
642+
children: <Widget>[TextButton(onPressed: () {}, child: const Text('X'))],
643+
),
644+
),
645+
),
646+
),
647+
);
648+
expect(tester.getSize(find.byType(ButtonBar)), Size.zero);
649+
});
635650
}

‎packages/material_ui/test/filter_chip_test.dart‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,4 +1379,19 @@ void main() {
13791379
SystemMouseCursors.forbidden,
13801380
);
13811381
});
1382+
1383+
testWidgets('FilterChip does not crash at zero area', (WidgetTester tester) async {
1384+
await tester.pumpWidget(
1385+
MaterialApp(
1386+
home: Scaffold(
1387+
body: Center(
1388+
child: SizedBox.shrink(
1389+
child: FilterChip(label: const Text('X'), onSelected: (_) {}),
1390+
),
1391+
),
1392+
),
1393+
),
1394+
);
1395+
expect(tester.getSize(find.byType(FilterChip)), Size.zero);
1396+
});
13821397
}

‎packages/material_ui/test/material_button_test.dart‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,4 +954,17 @@ void main() {
954954
final RawMaterialButton rawMaterialButton = tester.widget(rawMaterialButtonFinder);
955955
expect(rawMaterialButton.disabledElevation, equals(0.0));
956956
});
957+
958+
testWidgets('MaterialButton does not crash at zero area', (WidgetTester tester) async {
959+
await tester.pumpWidget(
960+
MaterialApp(
961+
home: Center(
962+
child: SizedBox.shrink(
963+
child: MaterialButton(onPressed: () {}, child: const Text('X')),
964+
),
965+
),
966+
),
967+
);
968+
expect(tester.getSize(find.byType(MaterialButton)), Size.zero);
969+
});
957970
}

‎packages/material_ui/test/mergeable_material_test.dart‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,4 +1114,15 @@ void main() {
11141114
tester.widget<Container>(find.byType(Container).last).decoration! as BoxDecoration;
11151115
expect(boxDecoration.color, themeCardColor);
11161116
});
1117+
1118+
testWidgets('MergeableMaterial does not crash at zero area', (WidgetTester tester) async {
1119+
tester.view.physicalSize = Size.zero;
1120+
addTearDown(tester.view.reset);
1121+
await tester.pumpWidget(
1122+
const MaterialApp(
1123+
home: Scaffold(body: SingleChildScrollView(child: MergeableMaterial())),
1124+
),
1125+
);
1126+
expect(tester.getSize(find.byType(MergeableMaterial)), Size.zero);
1127+
});
11171128
}

‎packages/material_ui/test/raw_material_button_test.dart‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,4 +652,15 @@ void main() {
652652
SystemMouseCursors.basic,
653653
);
654654
}, tags: 'reduced-web-test-set');
655+
656+
testWidgets('RawMaterialButton does not crash at zero area', (WidgetTester tester) async {
657+
await tester.pumpWidget(
658+
MaterialApp(
659+
home: Center(
660+
child: SizedBox.shrink(child: RawMaterialButton(onPressed: () {})),
661+
),
662+
),
663+
);
664+
expect(tester.getSize(find.byType(RawMaterialButton)), Size.zero);
665+
});
655666
}

0 commit comments

Comments
 (0)