Skip to content

Commit

Permalink
Merge pull request theyakka#95 from ankur2136/preloadFix
Browse files Browse the repository at this point in the history
Fix tests which require image preloading
  • Loading branch information
lukef authored Jul 9, 2020
2 parents 481d862 + ded9636 commit c231c2f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
Binary file modified test/.golden/qr_image_logo_golden.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 38 additions & 14 deletions test/image_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,32 +142,56 @@ void main() {
});

testWidgets('QrImage generates correct image with logo', (tester) async {
final key = GlobalKey();
final qrImage = MaterialApp(
home: Center(
key: key,
child: RepaintBoundary(
child: QrImage(
data: 'This is a a qr code with a logo',
version: QrVersions.auto,
gapless: true,
errorCorrectionLevel: QrErrorCorrectLevel.L,
embeddedImage: FileImage(File('test/.images/logo_yakka.png')),
await pumpWidgetWithImages(
tester,
MaterialApp(
home: Center(
child: RepaintBoundary(
child: QrImage(
data: 'This is a a qr code with a logo',
version: QrVersions.auto,
gapless: true,
errorCorrectionLevel: QrErrorCorrectLevel.L,
embeddedImage: FileImage(File('test/.images/logo_yakka.png')),
),
),
),
),
['test/.images/logo_yakka.png'],
);

await tester.pumpWidget(buildTestableWidget(qrImage));
await tester.pump(Duration(seconds: 15));
await tester.pumpAndSettle();

await expectLater(
find.byKey(key),
find.byType(QrImage),
matchesGoldenFile('./.golden/qr_image_logo_golden.png'),
);
});
}

/// Pre-cache images to make sure they show up in golden tests.
///
/// See https://github.com/flutter/flutter/issues/36552 for more info.
Future<void> pumpWidgetWithImages(
WidgetTester tester,
Widget widget,
List<String> assetNames,
) async {
Future<void> precacheFuture;
await tester.pumpWidget(
Builder(builder: (buildContext) {
precacheFuture = tester.runAsync(() async {
await Future.wait([
for (final assetName in assetNames)
precacheImage(FileImage(File(assetName)), buildContext),
]);
});
return widget;
}),
);
await precacheFuture;
}

Widget buildTestableWidget(Widget widget) {
return MediaQuery(data: MediaQueryData(), child: MaterialApp(home: widget));
}

0 comments on commit c231c2f

Please sign in to comment.