diff --git a/dev/bots/check_code_samples.dart b/dev/bots/check_code_samples.dart index 1c98c5ec470..dae19e7b0a9 100644 --- a/dev/bots/check_code_samples.dart +++ b/dev/bots/check_code_samples.dart @@ -313,7 +313,6 @@ final Set _knownMissingTests = { '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', - 'examples/api/test/material/elevated_button/elevated_button.0_test.dart', 'examples/api/test/material/material_state/material_state_border_side.0_test.dart', 'examples/api/test/material/material_state/material_state_mouse_cursor.0_test.dart', 'examples/api/test/material/material_state/material_state_outlined_border.0_test.dart', @@ -323,22 +322,18 @@ final Set _knownMissingTests = { 'examples/api/test/material/text_field/text_field.1_test.dart', 'examples/api/test/material/button_style/button_style.0_test.dart', 'examples/api/test/material/range_slider/range_slider.0_test.dart', - 'examples/api/test/material/card/card.0_test.dart', 'examples/api/test/material/selection_container/selection_container_disabled.0_test.dart', 'examples/api/test/material/selection_container/selection_container.0_test.dart', 'examples/api/test/material/color_scheme/dynamic_content_color.0_test.dart', 'examples/api/test/material/platform_menu_bar/platform_menu_bar.0_test.dart', '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/stepper/stepper.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.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/outlined_button/outlined_button.0_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', @@ -351,12 +346,10 @@ final Set _knownMissingTests = { 'examples/api/test/material/input_decorator/input_decoration.suffix_icon_constraints.0_test.dart', 'examples/api/test/material/input_decorator/input_decoration.3_test.dart', 'examples/api/test/material/input_decorator/input_decoration.material_state.1_test.dart', - 'examples/api/test/material/filled_button/filled_button.0_test.dart', 'examples/api/test/material/text_form_field/text_form_field.1_test.dart', 'examples/api/test/material/scrollbar/scrollbar.1_test.dart', 'examples/api/test/material/dropdown_menu/dropdown_menu.1_test.dart', 'examples/api/test/material/radio/radio.toggleable.0_test.dart', - 'examples/api/test/material/radio/radio.0_test.dart', 'examples/api/test/material/search_anchor/search_anchor.0_test.dart', 'examples/api/test/material/search_anchor/search_anchor.1_test.dart', 'examples/api/test/material/search_anchor/search_anchor.2_test.dart', diff --git a/examples/api/test/material/card/card.0_test.dart b/examples/api/test/material/card/card.0_test.dart new file mode 100644 index 00000000000..c7899853c5a --- /dev/null +++ b/examples/api/test/material/card/card.0_test.dart @@ -0,0 +1,21 @@ +// 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/card/card.0.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('Card Smoke Test', (WidgetTester tester) async { + await tester.pumpWidget( + const example.CardExampleApp(), + ); + expect(find.byType(Card), findsOneWidget); + expect(find.widgetWithIcon(Card, Icons.album), findsOneWidget); + expect(find.widgetWithText(Card, 'The Enchanted Nightingale'), findsOneWidget); + expect(find.widgetWithText(Card, 'Music by Julie Gable. Lyrics by Sidney Stein.'), findsOneWidget); + expect(find.widgetWithText(Card, 'BUY TICKETS'), findsOneWidget); + expect(find.widgetWithText(Card, 'LISTEN'), findsOneWidget); + }); +} diff --git a/examples/api/test/material/elevated_button/elevated_button.0_test.dart b/examples/api/test/material/elevated_button/elevated_button.0_test.dart new file mode 100644 index 00000000000..7a792195db9 --- /dev/null +++ b/examples/api/test/material/elevated_button/elevated_button.0_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/elevated_button/elevated_button.0.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('ElevatedButton Smoke Test', (WidgetTester tester) async { + await tester.pumpWidget( + const example.ElevatedButtonExampleApp(), + ); + + expect(find.widgetWithText(AppBar, 'ElevatedButton Sample'), findsOneWidget); + final Finder disabledButton = find.widgetWithText(ElevatedButton, 'Disabled'); + expect(disabledButton, findsOneWidget); + expect(tester.widget(disabledButton).onPressed.runtimeType, Null); + final Finder enabledButton = find.widgetWithText(ElevatedButton, 'Enabled'); + expect(enabledButton, findsOneWidget); + expect(tester.widget(enabledButton).onPressed.runtimeType, VoidCallback); + }); +} diff --git a/examples/api/test/material/filled_button/filled_button.0_test.dart b/examples/api/test/material/filled_button/filled_button.0_test.dart new file mode 100644 index 00000000000..0e3775ff37d --- /dev/null +++ b/examples/api/test/material/filled_button/filled_button.0_test.dart @@ -0,0 +1,25 @@ +// 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/filled_button/filled_button.0.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('FilledButton Smoke Test', (WidgetTester tester) async { + await tester.pumpWidget( + const example.FilledButtonApp(), + ); + + expect(find.widgetWithText(AppBar, 'FilledButton Sample'), findsOneWidget); + final Finder disabledButton = find.widgetWithText(FilledButton, 'Disabled'); + expect(disabledButton, findsNWidgets(2)); + expect(tester.widget(disabledButton.first).onPressed.runtimeType, Null); + expect(tester.widget(disabledButton.last).onPressed.runtimeType, Null); + final Finder enabledButton = find.widgetWithText(FilledButton, 'Enabled'); + expect(enabledButton, findsNWidgets(2)); + expect(tester.widget(enabledButton.first).onPressed.runtimeType, VoidCallback); + expect(tester.widget(enabledButton.last).onPressed.runtimeType, VoidCallback); + }); +} diff --git a/examples/api/test/material/outlined_button/outlined_button.0_test.dart b/examples/api/test/material/outlined_button/outlined_button.0_test.dart new file mode 100644 index 00000000000..1e6940aeb0c --- /dev/null +++ b/examples/api/test/material/outlined_button/outlined_button.0_test.dart @@ -0,0 +1,21 @@ +// 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/outlined_button/outlined_button.0.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('OutlinedButton Smoke Test', (WidgetTester tester) async { + await tester.pumpWidget( + const example.OutlinedButtonExampleApp(), + ); + + expect(find.widgetWithText(AppBar, 'OutlinedButton Sample'), findsOneWidget); + final Finder outlinedButton = find.widgetWithText(OutlinedButton, 'Click Me'); + expect(outlinedButton, findsOneWidget); + final OutlinedButton outlinedButtonWidget = tester.widget(outlinedButton); + expect(outlinedButtonWidget.onPressed.runtimeType, VoidCallback); + }); +} diff --git a/examples/api/test/material/radio/radio.0_test.dart b/examples/api/test/material/radio/radio.0_test.dart new file mode 100644 index 00000000000..2278d4ff686 --- /dev/null +++ b/examples/api/test/material/radio/radio.0_test.dart @@ -0,0 +1,33 @@ +// 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/radio/radio.0.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('Radio Smoke Test', (WidgetTester tester) async { + await tester.pumpWidget( + const example.RadioExampleApp(), + ); + + expect(find.widgetWithText(AppBar, 'Radio Sample'), findsOneWidget); + final Finder listTile1 = find.widgetWithText(ListTile, 'Lafayette'); + expect(listTile1, findsOneWidget); + final Finder listTile2 = find.widgetWithText(ListTile, 'Thomas Jefferson'); + expect(listTile2, findsOneWidget); + + final Finder radioButton1 = find.byType(Radio).first; + final Finder radioButton2 = find.byType(Radio).last; + + await tester.tap(radioButton1); + await tester.pumpAndSettle(); + expect(tester.widget>(radioButton1).groupValue, tester.widget>(radioButton1).value); + expect(tester.widget>(radioButton2).groupValue, isNot(tester.widget>(radioButton2).value)); + await tester.tap(radioButton2); + await tester.pumpAndSettle(); + expect(tester.widget>(radioButton1).groupValue, isNot(tester.widget>(radioButton1).value)); + expect(tester.widget>(radioButton2).groupValue, tester.widget>(radioButton2).value); + }); +} diff --git a/examples/api/test/material/snack_bar/snack_bar.0_test.dart b/examples/api/test/material/snack_bar/snack_bar.0_test.dart new file mode 100644 index 00000000000..f4dac771280 --- /dev/null +++ b/examples/api/test/material/snack_bar/snack_bar.0_test.dart @@ -0,0 +1,22 @@ +// 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/snack_bar/snack_bar.0.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('Clicking on Button shows a SnackBar', (WidgetTester tester) async { + await tester.pumpWidget( + const example.SnackBarExampleApp(), + ); + + expect(find.widgetWithText(AppBar, 'SnackBar Sample'), findsOneWidget); + expect(find.widgetWithText(ElevatedButton, 'Show Snackbar'), findsOneWidget); + await tester.tap(find.widgetWithText(ElevatedButton, 'Show Snackbar')); + await tester.pumpAndSettle(); + expect(find.text('Awesome Snackbar!'), findsOneWidget); + expect(find.text('Action'), findsOneWidget); + }); +} diff --git a/examples/api/test/material/stepper/stepper.0_test.dart b/examples/api/test/material/stepper/stepper.0_test.dart new file mode 100644 index 00000000000..fe7d0ab5e49 --- /dev/null +++ b/examples/api/test/material/stepper/stepper.0_test.dart @@ -0,0 +1,70 @@ +// 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/stepper/stepper.0.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('Stepper Smoke Test', (WidgetTester tester) async { + await tester.pumpWidget( + const example.StepperExampleApp(), + ); + + expect(find.widgetWithText(AppBar, 'Stepper Sample'), findsOneWidget); + expect(find.text('Step 1 title').hitTestable(), findsOneWidget); + expect(find.text('Step 2 title').hitTestable(), findsOneWidget); + expect(find.text('Content for Step 1').hitTestable(), findsOneWidget); + expect(find.text('Content for Step 2').hitTestable(), findsNothing); + final Stepper stepper = tester.widget(find.byType(Stepper)); + + // current: 0 & clicks cancel + stepper.onStepCancel?.call(); + await tester.pumpAndSettle(); + expect(find.text('Content for Step 1').hitTestable(), findsOneWidget); + expect(find.text('Content for Step 2').hitTestable(), findsNothing); + + // current: 0 & clicks 0th step + stepper.onStepTapped?.call(0); + await tester.pumpAndSettle(); + expect(find.text('Content for Step 1').hitTestable(), findsOneWidget); + expect(find.text('Content for Step 2').hitTestable(), findsNothing); + + // current: 0 & clicks continue + stepper.onStepContinue?.call(); + await tester.pumpAndSettle(); + expect(find.text('Content for Step 1').hitTestable(), findsNothing); + expect(find.text('Content for Step 2').hitTestable(), findsOneWidget); + + // current: 1 & clicks 1st step + stepper.onStepTapped?.call(1); + await tester.pumpAndSettle(); + expect(find.text('Content for Step 1').hitTestable(), findsNothing); + expect(find.text('Content for Step 2').hitTestable(), findsOneWidget); + + // current: 1 & clicks continue + stepper.onStepContinue?.call(); + await tester.pumpAndSettle(); + expect(find.text('Content for Step 1').hitTestable(), findsNothing); + expect(find.text('Content for Step 2').hitTestable(), findsOneWidget); + + // current: 1 & clicks cancel + stepper.onStepCancel?.call(); + await tester.pumpAndSettle(); + expect(find.text('Content for Step 1').hitTestable(), findsOneWidget); + expect(find.text('Content for Step 2').hitTestable(), findsNothing); + + // current: 0 & clicks 1st step + stepper.onStepTapped?.call(1); + await tester.pumpAndSettle(); + expect(find.text('Content for Step 1').hitTestable(), findsNothing); + expect(find.text('Content for Step 2').hitTestable(), findsOneWidget); + + // current: 1 & clicks 0th step + stepper.onStepTapped?.call(0); + await tester.pumpAndSettle(); + expect(find.text('Content for Step 1').hitTestable(), findsOneWidget); + expect(find.text('Content for Step 2').hitTestable(), findsNothing); + }); +}