From cb100c4ba31cdcb568566b2769ca8e70da8b344f Mon Sep 17 00:00:00 2001 From: Julien BOURNONVILLE Date: Fri, 22 Mar 2024 10:31:31 +0100 Subject: [PATCH] Add test for the option to show or hide heading checkbox in data tables --- test/custom_features_test.dart | 39 ++++++++++++++++++++++++++++++++++ test/test_utils.dart | 2 ++ 2 files changed, 41 insertions(+) diff --git a/test/custom_features_test.dart b/test/custom_features_test.dart index 1111c95..9922e19 100644 --- a/test/custom_features_test.dart +++ b/test/custom_features_test.dart @@ -1981,8 +1981,47 @@ void main() { expect(d.length, kDesserts.length); expect((d.first.widget as Theme).child.runtimeType, Checkbox); }); + + testWidgets('DataTable2 heading checkbox', (WidgetTester tester) async { + final List columns = [ + const DataColumn2(label: Text('Column1')), + ]; + final List rows = [ + DataRow2( + onSelectChanged: (value) {}, + cells: const [DataCell(Text('Content1'))], + ), + ]; + + // Check if heading checkbox is shown by default + await wrapWidgetSetSurf( + tester, + buildTable( + columns: columns, + rows: rows, + )); + + await tester.pumpAndSettle(); + expect(find.text('Column1'), findsOneWidget); + expect(find.byType(Checkbox), findsNWidgets(2)); + + // Check if heading checkbox is hided + await wrapWidgetSetSurf( + tester, + buildTable( + showHeadingCheckbox: false, + columns: columns, + rows: rows, + )); + + await tester.pumpAndSettle(); + expect(find.text('Column1'), findsOneWidget); + expect(find.byType(Checkbox), findsOneWidget); + }); } + + Tripple _getColumnSizes(WidgetTester tester, bool header) { var s0 = tester.getSize(find.byType(DataTable2)); diff --git a/test/test_utils.dart b/test/test_utils.dart index 76c7a25..03deb6c 100644 --- a/test/test_utils.dart +++ b/test/test_utils.dart @@ -151,6 +151,7 @@ DataTable2 buildTable( Color? fixedCornerColor, Color? headingRowColor, BoxDecoration? headingRowDecoration, + bool showHeadingCheckbox = true, double? dividerThickness, bool showBottomBorder = false, TableBorder? border, @@ -172,6 +173,7 @@ DataTable2 buildTable( sortArrowIcon: sortArrowIcon ?? Icons.arrow_upward, headingRowColor: MaterialStatePropertyAll(headingRowColor), headingRowDecoration: headingRowDecoration, + showHeadingCheckBox: showHeadingCheckbox, sortArrowAnimationDuration: sortArrowAnimationDuration ?? const Duration(milliseconds: 150), minWidth: minWidth,