Skip to content

Commit

Permalink
Merge pull request #60 from eBay/iterate_on_image_loading
Browse files Browse the repository at this point in the history
Iterate on asset priming
  • Loading branch information
coreysprague authored Jun 26, 2020
2 parents 386d611 + ff9cde4 commit bf1083c
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 8 deletions.
4 changes: 4 additions & 0 deletions packages/golden_toolkit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.5.1

Improved the reliability of the default behavior for ```tester.waitForAssets()``` to handle additional cases.

## 0.5.0

### More intelligent behavior for loading assets
Expand Down
6 changes: 3 additions & 3 deletions packages/golden_toolkit/lib/src/testing_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ Future<void> legacyPrimeAssets(WidgetTester tester) async {
/// See also:
/// * [GoldenToolkitConfiguration.primeAssets] to configure a global asset prime function.
Future<void> defaultPrimeAssets(WidgetTester tester) async {
final imageElements = find.byType(Image).evaluate();
final containerElements = find.byType(Container).evaluate();
final imageElements = find.byType(Image, skipOffstage: false).evaluate();
final containerElements = find.byType(DecoratedBox, skipOffstage: false).evaluate();
await tester.runAsync(() async {
for (final imageElement in imageElements) {
final widget = imageElement.widget;
Expand All @@ -291,7 +291,7 @@ Future<void> defaultPrimeAssets(WidgetTester tester) async {
}
}
for (final container in containerElements) {
final Container widget = container.widget;
final DecoratedBox widget = container.widget;
final decoration = widget.decoration;
if (decoration is BoxDecoration) {
if (decoration.image != null) {
Expand Down
2 changes: 1 addition & 1 deletion packages/golden_toolkit/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: golden_toolkit
description: Common patterns for screenshot-based widget testing using Goldens.
version: 0.5.0
version: 0.5.1
homepage: https://github.com/eBay/flutter_glove_box/
repository: https://github.com/eBay/flutter_glove_box/tree/master/packages/golden_toolkit
issue_tracker: https://github.com/eBay/flutter_glove_box/issues
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:golden_toolkit/golden_toolkit.dart';
import 'package:golden_toolkit/src/configuration.dart';
Expand Down Expand Up @@ -55,6 +56,27 @@ void main() {
config: defaultConfiguration,
);
});

testWidgets('should load assets that have not come into view yet', (tester) async {
await GoldenToolkit.runWithConfiguration(
() async {
await tester.pumpWidgetBuilder(
const ListOfItemsWithOneImage(
itemSize: Size(100, 100),
cacheExtent: 1000,
indexThatContainsImage: 10,
),
surfaceSize: const Size(300, 100),
);
await tester.waitForAssets();
await tester.drag(find.byType(Scrollable), const Offset(0, -1000));
await tester.pump();
await expectLater(
find.byType(ListOfItemsWithOneImage).first, matchesGoldenFile('goldens/list_of_images_will_show.png'));
},
config: defaultConfiguration,
);
});
},
);
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ class BoxDecorationWithImage extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Container(
width: 800,
height: 600,
decoration: const BoxDecoration(
return const DecoratedBox(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/earth_image.jpg', package: 'sample_dependency'),
),
Expand All @@ -35,3 +33,38 @@ GoldenToolkitConfiguration get legacyConfiguration =>

GoldenToolkitConfiguration get defaultConfiguration =>
GoldenToolkit.configuration.copyWith(primeAssets: defaultPrimeAssets);

@immutable
class ListOfItemsWithOneImage extends StatelessWidget {
const ListOfItemsWithOneImage({
@required this.itemSize,
@required this.indexThatContainsImage,
@required this.cacheExtent,
});

final Size itemSize;
final int indexThatContainsImage;
final double cacheExtent;

@override
Widget build(BuildContext context) {
return Container(
color: Colors.grey,
child: ListView.builder(
itemBuilder: (context, index) => Center(
child: Row(
children: [
Container(
width: itemSize.width,
height: itemSize.height,
color: Colors.lightBlue,
child: (index == indexThatContainsImage) ? const ImageWidget() : null,
),
],
),
),
cacheExtent: cacheExtent,
),
);
}
}

0 comments on commit bf1083c

Please sign in to comment.