Unverified Commit a49ee534 authored by Tirth's avatar Tirth Committed by GitHub

Write Tests for API Examples of `snack_bar.0`, `elevated_button.0`,...

Write Tests for API Examples of `snack_bar.0`, `elevated_button.0`, `stepper.0`, `radio.0`, `filled_button.0`, `outlined_button.0` & `card.0` (#138987)

Write Tests for API Examples of `snack_bar.0`, `elevated_button.0`, `stepper.0`, `radio.0`, `filled_button.0`, `outlined_button.0` & `card.0`

Part of #130459
parent 3267fbc0
...@@ -313,7 +313,6 @@ final Set<String> _knownMissingTests = <String>{ ...@@ -313,7 +313,6 @@ final Set<String> _knownMissingTests = <String>{
'examples/api/test/material/bottom_app_bar/bottom_app_bar.2_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/bottom_app_bar/bottom_app_bar.1_test.dart',
'examples/api/test/material/theme/theme_extension.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_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_mouse_cursor.0_test.dart',
'examples/api/test/material/material_state/material_state_outlined_border.0_test.dart', 'examples/api/test/material/material_state/material_state_outlined_border.0_test.dart',
...@@ -323,22 +322,18 @@ final Set<String> _knownMissingTests = <String>{ ...@@ -323,22 +322,18 @@ final Set<String> _knownMissingTests = <String>{
'examples/api/test/material/text_field/text_field.1_test.dart', '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/button_style/button_style.0_test.dart',
'examples/api/test/material/range_slider/range_slider.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_disabled.0_test.dart',
'examples/api/test/material/selection_container/selection_container.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/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/platform_menu_bar/platform_menu_bar.0_test.dart',
'examples/api/test/material/menu_anchor/menu_anchor.2_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.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/flexible_space_bar/flexible_space_bar.0_test.dart',
'examples/api/test/material/data_table/data_table.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/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/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.2_test.dart',
'examples/api/test/material/snack_bar/snack_bar.1_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.2_test.dart',
'examples/api/test/material/icon_button/icon_button.3_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/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0_test.dart',
...@@ -351,12 +346,10 @@ final Set<String> _knownMissingTests = <String>{ ...@@ -351,12 +346,10 @@ final Set<String> _knownMissingTests = <String>{
'examples/api/test/material/input_decorator/input_decoration.suffix_icon_constraints.0_test.dart', '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.3_test.dart',
'examples/api/test/material/input_decorator/input_decoration.material_state.1_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/text_form_field/text_form_field.1_test.dart',
'examples/api/test/material/scrollbar/scrollbar.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/dropdown_menu/dropdown_menu.1_test.dart',
'examples/api/test/material/radio/radio.toggleable.0_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.0_test.dart',
'examples/api/test/material/search_anchor/search_anchor.1_test.dart', 'examples/api/test/material/search_anchor/search_anchor.1_test.dart',
'examples/api/test/material/search_anchor/search_anchor.2_test.dart', 'examples/api/test/material/search_anchor/search_anchor.2_test.dart',
......
// 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);
});
}
// 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<ElevatedButton>(disabledButton).onPressed.runtimeType, Null);
final Finder enabledButton = find.widgetWithText(ElevatedButton, 'Enabled');
expect(enabledButton, findsOneWidget);
expect(tester.widget<ElevatedButton>(enabledButton).onPressed.runtimeType, VoidCallback);
});
}
// 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<FilledButton>(disabledButton.first).onPressed.runtimeType, Null);
expect(tester.widget<FilledButton>(disabledButton.last).onPressed.runtimeType, Null);
final Finder enabledButton = find.widgetWithText(FilledButton, 'Enabled');
expect(enabledButton, findsNWidgets(2));
expect(tester.widget<FilledButton>(enabledButton.first).onPressed.runtimeType, VoidCallback);
expect(tester.widget<FilledButton>(enabledButton.last).onPressed.runtimeType, VoidCallback);
});
}
// 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>(outlinedButton);
expect(outlinedButtonWidget.onPressed.runtimeType, VoidCallback);
});
}
// 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<example.SingingCharacter>).first;
final Finder radioButton2 = find.byType(Radio<example.SingingCharacter>).last;
await tester.tap(radioButton1);
await tester.pumpAndSettle();
expect(tester.widget<Radio<example.SingingCharacter>>(radioButton1).groupValue, tester.widget<Radio<example.SingingCharacter>>(radioButton1).value);
expect(tester.widget<Radio<example.SingingCharacter>>(radioButton2).groupValue, isNot(tester.widget<Radio<example.SingingCharacter>>(radioButton2).value));
await tester.tap(radioButton2);
await tester.pumpAndSettle();
expect(tester.widget<Radio<example.SingingCharacter>>(radioButton1).groupValue, isNot(tester.widget<Radio<example.SingingCharacter>>(radioButton1).value));
expect(tester.widget<Radio<example.SingingCharacter>>(radioButton2).groupValue, tester.widget<Radio<example.SingingCharacter>>(radioButton2).value);
});
}
// 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);
});
}
// 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<Stepper>(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);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment