From 84876e58ce2090468f045f5f8b668db7101275ed Mon Sep 17 00:00:00 2001 From: Valentin Vignal <32538273+ValentinVignal@users.noreply.github.com> Date: Thu, 23 May 2024 16:50:18 +0800 Subject: [PATCH] Add test for scaffold.0.dart and scaffold.2.dart (#148166) Contributes to https://github.com/flutter/flutter/issues/130459 It adds test for - `examples/api/lib/material/scaffold/scaffold.0.dart` - `examples/api/lib/material/scaffold/scaffold.2.dart` It also modifies the `scaffold.1_test.dart` because the only difference with scaffold 0 is the background color, so I figured the test should include it --- dev/bots/check_code_samples.dart | 2 -- .../material/scaffold/scaffold.0_test.dart | 25 +++++++++++++++++ .../material/scaffold/scaffold.1_test.dart | 3 +++ .../material/scaffold/scaffold.2_test.dart | 27 +++++++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 examples/api/test/material/scaffold/scaffold.0_test.dart create mode 100644 examples/api/test/material/scaffold/scaffold.2_test.dart diff --git a/dev/bots/check_code_samples.dart b/dev/bots/check_code_samples.dart index dc45fce90c..1abbbf6e72 100644 --- a/dev/bots/check_code_samples.dart +++ b/dev/bots/check_code_samples.dart @@ -351,9 +351,7 @@ final Set _knownMissingTests = { 'examples/api/test/material/scaffold/scaffold.drawer.0_test.dart', 'examples/api/test/material/scaffold/scaffold_messenger.of.0_test.dart', 'examples/api/test/material/scaffold/scaffold_messenger.0_test.dart', - 'examples/api/test/material/scaffold/scaffold.0_test.dart', 'examples/api/test/material/scaffold/scaffold_state.show_bottom_sheet.0_test.dart', - 'examples/api/test/material/scaffold/scaffold.2_test.dart', 'examples/api/test/material/scaffold/scaffold_messenger_state.show_material_banner.0_test.dart', 'examples/api/test/material/scaffold/scaffold_messenger.of.1_test.dart', 'examples/api/test/material/scaffold/scaffold_messenger_state.show_snack_bar.0_test.dart', diff --git a/examples/api/test/material/scaffold/scaffold.0_test.dart b/examples/api/test/material/scaffold/scaffold.0_test.dart new file mode 100644 index 0000000000..6716da9380 --- /dev/null +++ b/examples/api/test/material/scaffold/scaffold.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/scaffold/scaffold.0.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('The count should be incremented when the floating action button is tapped', (WidgetTester tester) async { + await tester.pumpWidget( + const example.ScaffoldExampleApp(), + ); + + expect(find.widgetWithText(AppBar, 'Sample Code'), findsOne); + expect(find.widgetWithIcon(FloatingActionButton, Icons.add), findsOne); + expect(find.text('You have pressed the button 0 times.'), findsOne); + + for (int i = 1; i <= 5; i++) { + await tester.tap(find.byType(FloatingActionButton)); + await tester.pump(); + expect(find.text('You have pressed the button $i times.'), findsOne); + } + }); +} diff --git a/examples/api/test/material/scaffold/scaffold.1_test.dart b/examples/api/test/material/scaffold/scaffold.1_test.dart index a468b509b9..e456910162 100644 --- a/examples/api/test/material/scaffold/scaffold.1_test.dart +++ b/examples/api/test/material/scaffold/scaffold.1_test.dart @@ -21,5 +21,8 @@ void main() { await tester.pump(); expect(find.text('You have pressed the button $i times.'), findsOne); } + + final Scaffold scaffold = tester.firstWidget(find.byType(Scaffold)); + expect(scaffold.backgroundColor, Colors.blueGrey.shade200); }); } diff --git a/examples/api/test/material/scaffold/scaffold.2_test.dart b/examples/api/test/material/scaffold/scaffold.2_test.dart new file mode 100644 index 0000000000..1c27441e5c --- /dev/null +++ b/examples/api/test/material/scaffold/scaffold.2_test.dart @@ -0,0 +1,27 @@ +// 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/scaffold/scaffold.2.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('The count should be incremented when the centered floating action button is tapped', (WidgetTester tester) async { + await tester.pumpWidget( + const example.ScaffoldExampleApp(), + ); + + expect(find.widgetWithText(AppBar, 'Sample Code'), findsOne); + expect(find.widgetWithIcon(FloatingActionButton, Icons.add), findsOne); + expect(find.text('You have pressed the button 0 times.'), findsOne); + expect(find.byType(BottomAppBar), findsOne); + expect(tester.getCenter(find.byType(FloatingActionButton)).dx, 400); + + for (int i = 1; i <= 5; i++) { + await tester.tap(find.byType(FloatingActionButton)); + await tester.pump(); + expect(find.text('You have pressed the button $i times.'), findsOne); + } + }); +}