Skip to content

Commit 513a05e

Browse files
committed
Update testing_codelab
1 parent 0bbc246 commit 513a05e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+546
-551
lines changed

testing_codelab/codelab_rebuild.yaml

Lines changed: 74 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ steps:
6666
import 'package:flutter/material.dart';
6767
6868
void main() {
69+
- name: Format lib/main.dart
70+
path: testing_app
71+
dart: format lib/main.dart
6972
- name: Copy step_03
7073
copydir:
7174
from: testing_app
@@ -121,9 +124,7 @@ steps:
121124
child: MaterialApp.router(
122125
title: 'Testing Sample',
123126
theme: ThemeData(
124-
colorScheme: ColorScheme.fromSeed(
125-
seedColor: Colors.deepPurple,
126-
),
127+
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
127128
useMaterial3: true,
128129
),
129130
routerConfig: _router,
@@ -168,39 +169,39 @@ steps:
168169
// Copyright 2020 The Flutter Authors. All rights reserved.
169170
// Use of this source code is governed by a BSD-style license that can be
170171
// found in the LICENSE file.
171-
172+
172173
import 'package:flutter/material.dart';
173174
import 'package:provider/provider.dart';
174-
175+
175176
import '../models/favorites.dart';
176-
177+
177178
class FavoritesPage extends StatelessWidget {
178179
const FavoritesPage({super.key});
179-
180+
180181
static String routeName = 'favorites_page';
181-
182+
182183
@override
183184
Widget build(BuildContext context) {
184185
return Scaffold(
185-
appBar: AppBar(
186-
title: const Text('Favorites'),
187-
),
186+
appBar: AppBar(title: const Text('Favorites')),
188187
body: Consumer<Favorites>(
189-
builder: (context, value, child) => ListView.builder(
190-
itemCount: value.items.length,
191-
padding: const EdgeInsets.symmetric(vertical: 16),
192-
itemBuilder: (context, index) => FavoriteItemTile(value.items[index]),
193-
),
188+
builder:
189+
(context, value, child) => ListView.builder(
190+
itemCount: value.items.length,
191+
padding: const EdgeInsets.symmetric(vertical: 16),
192+
itemBuilder:
193+
(context, index) => FavoriteItemTile(value.items[index]),
194+
),
194195
),
195196
);
196197
}
197198
}
198-
199+
199200
class FavoriteItemTile extends StatelessWidget {
200201
const FavoriteItemTile(this.itemNo, {super.key});
201-
202+
202203
final int itemNo;
203-
204+
204205
@override
205206
Widget build(BuildContext context) {
206207
return Padding(
@@ -209,10 +210,7 @@ steps:
209210
leading: CircleAvatar(
210211
backgroundColor: Colors.primaries[itemNo % Colors.primaries.length],
211212
),
212-
title: Text(
213-
'Item $itemNo',
214-
key: Key('favorites_text_$itemNo'),
215-
),
213+
title: Text('Item $itemNo', key: Key('favorites_text_$itemNo')),
216214
trailing: IconButton(
217215
key: Key('remove_icon_$itemNo'),
218216
icon: const Icon(Icons.close),
@@ -236,18 +234,18 @@ steps:
236234
// Copyright 2020 The Flutter Authors. All rights reserved.
237235
// Use of this source code is governed by a BSD-style license that can be
238236
// found in the LICENSE file.
239-
237+
240238
import 'package:flutter/material.dart';
241239
import 'package:go_router/go_router.dart';
242240
import 'package:provider/provider.dart';
243241
import '../models/favorites.dart';
244242
import 'favorites.dart';
245-
243+
246244
class HomePage extends StatelessWidget {
247245
static String routeName = '/';
248-
246+
249247
const HomePage({super.key});
250-
248+
251249
@override
252250
Widget build(BuildContext context) {
253251
return Scaffold(
@@ -272,40 +270,40 @@ steps:
272270
);
273271
}
274272
}
275-
273+
276274
class ItemTile extends StatelessWidget {
277275
final int itemNo;
278-
276+
279277
const ItemTile(this.itemNo, {super.key});
280-
278+
281279
@override
282280
Widget build(BuildContext context) {
283281
var favoritesList = Provider.of<Favorites>(context);
284-
282+
285283
return Padding(
286284
padding: const EdgeInsets.all(8.0),
287285
child: ListTile(
288286
leading: CircleAvatar(
289287
backgroundColor: Colors.primaries[itemNo % Colors.primaries.length],
290288
),
291-
title: Text(
292-
'Item $itemNo',
293-
key: Key('text_$itemNo'),
294-
),
289+
title: Text('Item $itemNo', key: Key('text_$itemNo')),
295290
trailing: IconButton(
296291
key: Key('icon_$itemNo'),
297-
icon: favoritesList.items.contains(itemNo)
298-
? const Icon(Icons.favorite)
299-
: const Icon(Icons.favorite_border),
292+
icon:
293+
favoritesList.items.contains(itemNo)
294+
? const Icon(Icons.favorite)
295+
: const Icon(Icons.favorite_border),
300296
onPressed: () {
301297
!favoritesList.items.contains(itemNo)
302298
? favoritesList.add(itemNo)
303299
: favoritesList.remove(itemNo);
304300
ScaffoldMessenger.of(context).showSnackBar(
305301
SnackBar(
306-
content: Text(favoritesList.items.contains(itemNo)
307-
? 'Added to favorites.'
308-
: 'Removed from favorites.'),
302+
content: Text(
303+
favoritesList.items.contains(itemNo)
304+
? 'Added to favorites.'
305+
: 'Removed from favorites.',
306+
),
309307
duration: const Duration(seconds: 1),
310308
),
311309
);
@@ -413,14 +411,12 @@ steps:
413411
late Favorites favoritesList;
414412
415413
Widget createFavoritesScreen() => ChangeNotifierProvider<Favorites>(
416-
create: (context) {
417-
favoritesList = Favorites();
418-
return favoritesList;
419-
},
420-
child: const MaterialApp(
421-
home: FavoritesPage(),
422-
),
423-
);
414+
create: (context) {
415+
favoritesList = Favorites();
416+
return favoritesList;
417+
},
418+
child: const MaterialApp(home: FavoritesPage()),
419+
);
424420
425421
void addItems() {
426422
for (var i = 0; i < 10; i += 2) {
@@ -444,8 +440,10 @@ steps:
444440
var totalItems = tester.widgetList(find.byIcon(Icons.close)).length;
445441
await tester.tap(find.byIcon(Icons.close).first);
446442
await tester.pumpAndSettle();
447-
expect(tester.widgetList(find.byIcon(Icons.close)).length,
448-
lessThan(totalItems));
443+
expect(
444+
tester.widgetList(find.byIcon(Icons.close)).length,
445+
lessThan(totalItems),
446+
);
449447
expect(find.text('Removed from favorites.'), findsOneWidget);
450448
});
451449
});
@@ -456,39 +454,33 @@ steps:
456454
// Copyright 2020 The Flutter Authors. All rights reserved.
457455
// Use of this source code is governed by a BSD-style license that can be
458456
// found in the LICENSE file.
459-
457+
460458
import 'package:flutter/material.dart';
461459
import 'package:flutter_test/flutter_test.dart';
462460
import 'package:provider/provider.dart';
463461
import 'package:testing_app/models/favorites.dart';
464462
import 'package:testing_app/screens/home.dart';
465-
463+
466464
Widget createHomeScreen() => ChangeNotifierProvider<Favorites>(
467-
create: (context) => Favorites(),
468-
child: const MaterialApp(
469-
home: HomePage(),
470-
),
471-
);
472-
465+
create: (context) => Favorites(),
466+
child: const MaterialApp(home: HomePage()),
467+
);
468+
473469
void main() {
474470
group('Home Page Widget Tests', () {
475471
testWidgets('Testing if ListView shows up', (tester) async {
476472
await tester.pumpWidget(createHomeScreen());
477473
expect(find.byType(ListView), findsOneWidget);
478474
});
479-
475+
480476
testWidgets('Testing Scrolling', (tester) async {
481477
await tester.pumpWidget(createHomeScreen());
482478
expect(find.text('Item 0'), findsOneWidget);
483-
await tester.fling(
484-
find.byType(ListView),
485-
const Offset(0, -200),
486-
3000,
487-
);
479+
await tester.fling(find.byType(ListView), const Offset(0, -200), 3000);
488480
await tester.pumpAndSettle();
489481
expect(find.text('Item 0'), findsNothing);
490482
});
491-
483+
492484
testWidgets('Testing IconButtons', (tester) async {
493485
await tester.pumpWidget(createHomeScreen());
494486
expect(find.byIcon(Icons.favorite), findsNothing);
@@ -526,42 +518,38 @@ steps:
526518
// Copyright 2021 The Flutter Authors. All rights reserved.
527519
// Use of this source code is governed by a BSD-style license that can be
528520
// found in the LICENSE file.
529-
521+
530522
import 'package:flutter/material.dart';
531523
import 'package:flutter_test/flutter_test.dart';
532524
import 'package:testing_app/main.dart';
533-
525+
534526
void main() {
535527
group('Testing App', () {
536528
testWidgets('Favorites operations test', (tester) async {
537529
await tester.pumpWidget(const TestingApp());
538-
539-
final iconKeys = [
540-
'icon_0',
541-
'icon_1',
542-
'icon_2',
543-
];
544-
530+
531+
final iconKeys = ['icon_0', 'icon_1', 'icon_2'];
532+
545533
for (var icon in iconKeys) {
546534
await tester.tap(find.byKey(ValueKey(icon)));
547535
await tester.pumpAndSettle(const Duration(seconds: 1));
548-
536+
549537
expect(find.text('Added to favorites.'), findsOneWidget);
550538
}
551-
539+
552540
await tester.tap(find.text('Favorites'));
553541
await tester.pumpAndSettle();
554-
542+
555543
final removeIconKeys = [
556544
'remove_icon_0',
557545
'remove_icon_1',
558546
'remove_icon_2',
559547
];
560-
548+
561549
for (final iconKey in removeIconKeys) {
562550
await tester.tap(find.byKey(ValueKey(iconKey)));
563551
await tester.pumpAndSettle(const Duration(seconds: 1));
564-
552+
565553
expect(find.text('Removed from favorites.'), findsOneWidget);
566554
}
567555
});
@@ -634,19 +622,20 @@ steps:
634622
// Copyright 2020 The Flutter Authors. All rights reserved.
635623
// Use of this source code is governed by a BSD-style license that can be
636624
// found in the LICENSE file.
637-
625+
638626
import 'package:flutter_driver/flutter_driver.dart' as driver;
639627
import 'package:integration_test/integration_test_driver.dart';
640-
628+
641629
Future<void> main() {
642630
return integrationDriver(
643631
responseDataCallback: (data) async {
644632
if (data != null) {
645633
final timeline = driver.Timeline.fromJson(
646-
data['scrolling_summary'] as Map<String, dynamic>);
647-
634+
data['scrolling_summary'] as Map<String, dynamic>,
635+
);
636+
648637
final summary = driver.TimelineSummary.summarize(timeline);
649-
638+
650639
await summary.writeTimelineToFile(
651640
'scrolling_summary',
652641
pretty: true,

testing_codelab/step_03/android/app/build.gradle renamed to testing_codelab/step_03/android/app/build.gradle.kts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
plugins {
2-
id "com.android.application"
3-
id "kotlin-android"
2+
id("com.android.application")
3+
id("kotlin-android")
44
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
5-
id "dev.flutter.flutter-gradle-plugin"
5+
id("dev.flutter.flutter-gradle-plugin")
66
}
77

88
android {
@@ -16,7 +16,7 @@ android {
1616
}
1717

1818
kotlinOptions {
19-
jvmTarget = JavaVersion.VERSION_1_8
19+
jvmTarget = JavaVersion.VERSION_1_8.toString()
2020
}
2121

2222
defaultConfig {
@@ -34,7 +34,7 @@ android {
3434
release {
3535
// TODO: Add your own signing config for the release build.
3636
// Signing with the debug keys for now, so `flutter run --release` works.
37-
signingConfig = signingConfigs.debug
37+
signingConfig = signingConfigs.getByName("debug")
3838
}
3939
}
4040
}

testing_codelab/step_03/android/build.gradle

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
allprojects {
2+
repositories {
3+
google()
4+
mavenCentral()
5+
}
6+
}
7+
8+
val newBuildDir: Directory = rootProject.layout.buildDirectory.dir("../../build").get()
9+
rootProject.layout.buildDirectory.value(newBuildDir)
10+
11+
subprojects {
12+
val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
13+
project.layout.buildDirectory.value(newSubprojectBuildDir)
14+
}
15+
subprojects {
16+
project.evaluationDependsOn(":app")
17+
}
18+
19+
tasks.register<Delete>("clean") {
20+
delete(rootProject.layout.buildDirectory)
21+
}

0 commit comments

Comments
 (0)