From c10787bc6ac151d04cad91b572cff969ec6c2fba Mon Sep 17 00:00:00 2001 From: Tirth Date: Fri, 1 Dec 2023 01:37:00 +0530 Subject: [PATCH] Write Tests for API Examples of `cupertino_text_field.0`, `data_table.0`, `icon_button.2` & `ink_well.0` (#139258) Write Tests for API Examples of `cupertino_text_field.0`, `data_table.0`, `icon_button.2` & `ink_well.0` Note: test for `cupertino_text_field.0` was already there but it was named `cupertino_text_field.0.dart`. I renamed it to `cupertino_text_field.0_test.dart`. Part of #130459 --- dev/bots/check_code_samples.dart | 4 --- ....dart => cupertino_text_field.0_test.dart} | 0 .../data_table/data_table.0_test.dart | 35 +++++++++++++++++++ .../icon_button/icon_button.2_test.dart | 23 ++++++++++++ .../material/ink_well/ink_well.0_test.dart | 34 ++++++++++++++++++ 5 files changed, 92 insertions(+), 4 deletions(-) rename examples/api/test/cupertino/text_field/{cupertino_text_field.0.dart => cupertino_text_field.0_test.dart} (100%) create mode 100644 examples/api/test/material/data_table/data_table.0_test.dart create mode 100644 examples/api/test/material/icon_button/icon_button.2_test.dart create mode 100644 examples/api/test/material/ink_well/ink_well.0_test.dart diff --git a/dev/bots/check_code_samples.dart b/dev/bots/check_code_samples.dart index dae19e7b0a9c..ba6561d02742 100644 --- a/dev/bots/check_code_samples.dart +++ b/dev/bots/check_code_samples.dart @@ -309,7 +309,6 @@ class SampleChecker { // TODO(gspencergoog): implement the missing tests. // See https://github.com/flutter/flutter/issues/130459 final Set _knownMissingTests = { - 'examples/api/test/cupertino/text_field/cupertino_text_field.0_test.dart', 'examples/api/test/material/bottom_app_bar/bottom_app_bar.2_test.dart', 'examples/api/test/material/bottom_app_bar/bottom_app_bar.1_test.dart', 'examples/api/test/material/theme/theme_extension.1_test.dart', @@ -329,12 +328,10 @@ final Set _knownMissingTests = { 'examples/api/test/material/menu_anchor/menu_anchor.2_test.dart', 'examples/api/test/material/stepper/stepper.controls_builder.0_test.dart', 'examples/api/test/material/flexible_space_bar/flexible_space_bar.0_test.dart', - 'examples/api/test/material/data_table/data_table.0_test.dart', 'examples/api/test/material/floating_action_button_location/standard_fab_location.0_test.dart', 'examples/api/test/material/chip/deletable_chip_attributes.on_deleted.0_test.dart', 'examples/api/test/material/snack_bar/snack_bar.2_test.dart', 'examples/api/test/material/snack_bar/snack_bar.1_test.dart', - 'examples/api/test/material/icon_button/icon_button.2_test.dart', 'examples/api/test/material/icon_button/icon_button.3_test.dart', 'examples/api/test/material/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0_test.dart', 'examples/api/test/material/input_decorator/input_decoration.1_test.dart', @@ -378,7 +375,6 @@ final Set _knownMissingTests = { 'examples/api/test/material/app_bar/sliver_app_bar.4_test.dart', 'examples/api/test/material/app_bar/app_bar.3_test.dart', 'examples/api/test/material/app_bar/app_bar.0_test.dart', - 'examples/api/test/material/ink_well/ink_well.0_test.dart', 'examples/api/test/material/banner/material_banner.1_test.dart', 'examples/api/test/material/banner/material_banner.0_test.dart', 'examples/api/test/material/checkbox/checkbox.1_test.dart', diff --git a/examples/api/test/cupertino/text_field/cupertino_text_field.0.dart b/examples/api/test/cupertino/text_field/cupertino_text_field.0_test.dart similarity index 100% rename from examples/api/test/cupertino/text_field/cupertino_text_field.0.dart rename to examples/api/test/cupertino/text_field/cupertino_text_field.0_test.dart diff --git a/examples/api/test/material/data_table/data_table.0_test.dart b/examples/api/test/material/data_table/data_table.0_test.dart new file mode 100644 index 000000000000..346fbd5577c7 --- /dev/null +++ b/examples/api/test/material/data_table/data_table.0_test.dart @@ -0,0 +1,35 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_api_samples/material/data_table/data_table.0.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('DataTable Smoke Test', (WidgetTester tester) async { + await tester.pumpWidget( + const example.DataTableExampleApp(), + ); + expect(find.widgetWithText(AppBar, 'DataTable Sample'), findsOneWidget); + expect(find.byType(DataTable), findsOneWidget); + final DataTable dataTable = tester.widget(find.byType(DataTable)); + expect(dataTable.columns.length, 3); + expect(dataTable.rows.length, 3); + for (int i = 0; i < dataTable.rows.length; i++) { + expect(dataTable.rows[i].cells.length, 3); + } + expect(find.text('Name'), findsOneWidget); + expect(find.text('Age'), findsOneWidget); + expect(find.text('Role'), findsOneWidget); + expect(find.text('Sarah'), findsOneWidget); + expect(find.text('19'), findsOneWidget); + expect(find.text('Student'), findsOneWidget); + expect(find.text('Janine'), findsOneWidget); + expect(find.text('43'), findsOneWidget); + expect(find.text('Professor'), findsOneWidget); + expect(find.text('William'), findsOneWidget); + expect(find.text('27'), findsOneWidget); + expect(find.text('Associate Professor'), findsOneWidget); + }); +} diff --git a/examples/api/test/material/icon_button/icon_button.2_test.dart b/examples/api/test/material/icon_button/icon_button.2_test.dart new file mode 100644 index 000000000000..301de4efe9d8 --- /dev/null +++ b/examples/api/test/material/icon_button/icon_button.2_test.dart @@ -0,0 +1,23 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_api_samples/material/icon_button/icon_button.2.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('IconButton Types', (WidgetTester tester) async { + await tester.pumpWidget( + const example.IconButtonApp(), + ); + expect(find.widgetWithIcon(IconButton, Icons.filter_drama), findsNWidgets(8)); + final Finder iconButtons = find.widgetWithIcon(IconButton, Icons.filter_drama); + for (int i = 0; i <= 3; i++) { + expect(tester.widget(iconButtons.at(i)).onPressed is VoidCallback, isTrue); + } + for (int i = 4; i <= 7; i++) { + expect(tester.widget(iconButtons.at(i)).onPressed, isNull); + } + }); +} diff --git a/examples/api/test/material/ink_well/ink_well.0_test.dart b/examples/api/test/material/ink_well/ink_well.0_test.dart new file mode 100644 index 000000000000..f48c4c9f0e8d --- /dev/null +++ b/examples/api/test/material/ink_well/ink_well.0_test.dart @@ -0,0 +1,34 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_api_samples/material/ink_well/ink_well.0.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('Clicking on InkWell changes the Size of 50x50 AnimatedContainer to 100x100 and vice versa', (WidgetTester tester) async { + await tester.pumpWidget( + const example.InkWellExampleApp(), + ); + expect(find.widgetWithText(AppBar, 'InkWell Sample'), findsOneWidget); + final Finder inkWell = find.byType(InkWell); + final InkWell inkWellWidget = tester.widget(inkWell); + final Finder animatedContainer = find.byType(AnimatedContainer); + AnimatedContainer animatedContainerWidget = tester.widget(animatedContainer); + expect(inkWell, findsOneWidget); + expect(inkWellWidget.onTap.runtimeType, VoidCallback); + expect(animatedContainerWidget.constraints?.minWidth, 50); + expect(animatedContainerWidget.constraints?.minHeight, 50); + await tester.tap(inkWell); + await tester.pumpAndSettle(); + animatedContainerWidget = tester.widget(animatedContainer); + expect(animatedContainerWidget.constraints?.minWidth, 100); + expect(animatedContainerWidget.constraints?.minHeight, 100); + await tester.tap(inkWell); + await tester.pumpAndSettle(); + animatedContainerWidget = tester.widget(animatedContainer); + expect(animatedContainerWidget.constraints?.minWidth, 50); + expect(animatedContainerWidget.constraints?.minHeight, 50); + }); +}