Skip to content

Commit

Permalink
Fixed links and excerpts
Browse files Browse the repository at this point in the history
  • Loading branch information
atsansone committed May 17, 2024
1 parent 05dbebd commit 201974d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,27 @@ void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); // NEW

// #docregion initial
testWidgets('tap on the floating action button, verify counter',
(tester) async {
// Load app widget.
await tester.pumpWidget(const MyApp());
group('end-to-end test', () {
testWidgets('tap on the floating action button, verify counter',
(tester) async {
// Load app widget.
await tester.pumpWidget(const MyApp());

// Verify the counter starts at 0.
expect(find.text('0'), findsOneWidget);
// Verify the counter starts at 0.
expect(find.text('0'), findsOneWidget);

// Finds the floating action button to tap on.
final fab = find.byKey(const Key('increment'));
// Finds the floating action button to tap on.
final fab = find.byKey(const ValueKey('increment'));

// Emulate a tap on the floating action button.
await tester.tap(fab);
// Emulate a tap on the floating action button.
await tester.tap(fab);

// Trigger a frame.
await tester.pumpAndSettle();
// Trigger a frame.
await tester.pumpAndSettle();

// Verify the counter increments by 1.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
// Verify the counter increments by 1.
expect(find.text('1'), findsOneWidget);
});
});
}
// #enddocregion initial
28 changes: 10 additions & 18 deletions src/content/testing/integration-tests/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,16 @@ the `lib/main.dart` file should resemble the following code.
```dart title="lib/main.dart"
import 'package:flutter/material.dart';

void main() {
runApp(const MyApp());
}
void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
return const MaterialApp(
title: 'Counter App',
home: MyHomePage(title: 'Counter App Home Page'),
);
}
}
Expand All @@ -114,7 +108,6 @@ class _MyHomePageState extends State<MyHomePage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
Expand All @@ -132,9 +125,9 @@ class _MyHomePageState extends State<MyHomePage> {
),
),
floatingActionButton: FloatingActionButton(
// Provide a ValueKey to this button. This allows finding this
// Provide a Key to this button. This allows finding this
// specific button inside the test suite, and tapping it.
key: const ValueKey('increment'),
key: const Key('increment'),
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
Expand Down Expand Up @@ -219,16 +212,15 @@ and your app's Dart file.
of your `counter_app`.
(This `import` points to the example app called `introduction`.)

<?code-excerpt "integration_test/app_test.dart (integration-test)" replace="/introduction/counter_app/g"?>
```dart title="integration_test/app_test.dart"
<?code-excerpt "integration_test/counter_test.dart (initial)" replace="/introduction/counter_app/g"?>
```dart title="integration_test/counter_test.dart"
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:how_to/main.dart';
import 'package:integration_test/integration_test.dart';
import 'package:counter_app/main.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
// ···
group('end-to-end test', () {
testWidgets('tap on the floating action button, verify counter',
(tester) async {
Expand Down

0 comments on commit 201974d

Please sign in to comment.