mirror of
https://github.com/flutter/packages.git
synced 2025-07-01 15:23:25 +08:00
Remove testing asset from package (#336)
This commit is contained in:
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
@ -118,7 +118,7 @@ In laboris eiusmod reprehenderit aliquip sit proident occaecat. Non sit labore a
|
||||
|
||||
Minim id consequat adipisicing cupidatat laborum culpa veniam non consectetur et duis pariatur reprehenderit eu ex consectetur. Sunt nisi qui eiusmod ut cillum laborum Lorem officia aliquip laboris ullamco nostrud laboris non irure laboris.
|
||||
|
||||

|
||||

|
||||
|
||||
In laboris eiusmod reprehenderit aliquip sit proident occaecat. Non sit labore anim elit veniam Lorem minim commodo eiusmod irure do minim nisi.
|
||||
|
||||
@ -126,7 +126,11 @@ In laboris eiusmod reprehenderit aliquip sit proident occaecat. Non sit labore a
|
||||
|
||||
Officia irure in non voluptate adipisicing sit amet tempor duis dolore deserunt enim ut. Reprehenderit incididunt in ad anim et deserunt deserunt Lorem laborum quis. Enim aute anim labore proident laboris voluptate elit excepteur in.
|
||||
|
||||

|
||||

|
||||
|
||||
In laboris eiusmod reprehenderit aliquip sit proident occaecat. Non sit labore anim elit veniam Lorem minim commodo eiusmod irure do minim nisi.
|
||||
|
||||

|
||||
|
||||
# Extended Syntax
|
||||
|
||||
|
@ -20,7 +20,3 @@ dev_dependencies:
|
||||
environment:
|
||||
sdk: ">=2.12.0-0 <3.0.0"
|
||||
flutter: ">=1.17.0"
|
||||
|
||||
flutter:
|
||||
assets:
|
||||
- assets/logo.png
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
BIN
packages/flutter_markdown/test/assets/images/logo.png
Normal file
BIN
packages/flutter_markdown/test/assets/images/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
@ -5,6 +5,7 @@
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@ -110,19 +111,45 @@ void defineTests() {
|
||||
testWidgets(
|
||||
'should work with resources',
|
||||
(WidgetTester tester) async {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
const String data = '';
|
||||
await tester.pumpWidget(
|
||||
boilerplate(
|
||||
const Markdown(data: data),
|
||||
MaterialApp(
|
||||
home: DefaultAssetBundle(
|
||||
bundle: TestAssetBundle(),
|
||||
child: Center(
|
||||
child: Container(
|
||||
color: Colors.white,
|
||||
width: 500,
|
||||
child: Markdown(
|
||||
data: data,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final Iterable<Widget> widgets = tester.allWidgets;
|
||||
final Image image =
|
||||
widgets.firstWhere((Widget widget) => widget is Image) as Image;
|
||||
final image = tester.allWidgets
|
||||
.firstWhere((Widget widget) => widget is Image) as Image;
|
||||
|
||||
expect(image.image is AssetImage, isTrue);
|
||||
expect((image.image as AssetImage).assetName, 'assets/logo.png');
|
||||
|
||||
// Force the asset image to be rasterized so it can be compared.
|
||||
await tester.runAsync(() async {
|
||||
final element = tester.element(find.byType(Markdown));
|
||||
await precacheImage(image.image, element);
|
||||
});
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await expectLater(
|
||||
find.byType(Container),
|
||||
matchesGoldenFile(
|
||||
'assets/images/golden/image_test/resource_asset_logo.png'));
|
||||
},
|
||||
);
|
||||
|
||||
@ -296,9 +323,20 @@ void defineTests() {
|
||||
|
||||
await tester.pumpWidget(
|
||||
boilerplate(
|
||||
Markdown(
|
||||
data: data,
|
||||
imageBuilder: builder,
|
||||
MaterialApp(
|
||||
home: DefaultAssetBundle(
|
||||
bundle: TestAssetBundle(),
|
||||
child: Center(
|
||||
child: Container(
|
||||
color: Colors.white,
|
||||
width: 500,
|
||||
child: Markdown(
|
||||
data: data,
|
||||
imageBuilder: builder,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@ -309,6 +347,19 @@ void defineTests() {
|
||||
|
||||
expect(image.image.runtimeType, AssetImage);
|
||||
expect((image.image as AssetImage).assetName, 'assets/logo.png');
|
||||
|
||||
// Force the asset image to be rasterized so it can be compared.
|
||||
await tester.runAsync(() async {
|
||||
final element = tester.element(find.byType(Markdown));
|
||||
await precacheImage(image.image, element);
|
||||
});
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await expectLater(
|
||||
find.byType(Container),
|
||||
matchesGoldenFile(
|
||||
'assets/images/golden/image_test/custom_builder_asset_logo.png'));
|
||||
},
|
||||
);
|
||||
});
|
||||
|
@ -2,9 +2,14 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io' as io;
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
@ -162,3 +167,33 @@ Widget boilerplate(Widget child) {
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
class TestAssetBundle extends CachingAssetBundle {
|
||||
static const manifest = r'{"assets/logo.png":["assets/logo.png"]}';
|
||||
|
||||
@override
|
||||
Future<ByteData> load(String key) async {
|
||||
if (key == 'AssetManifest.json') {
|
||||
final ByteData? asset =
|
||||
ByteData.view(utf8.encoder.convert(manifest).buffer);
|
||||
return Future<ByteData>.value(asset);
|
||||
} else if (key == 'assets/logo.png') {
|
||||
// The root directory tests are run from is different for 'flutter test'
|
||||
// verses 'flutter test test/*_test.dart'. Adjust the root directory
|
||||
// to access the assets directory.
|
||||
final rootDirectory =
|
||||
io.Directory.current.path.endsWith(io.Platform.pathSeparator + 'test')
|
||||
? io.Directory.current.parent
|
||||
: io.Directory.current;
|
||||
final file = io.File('${rootDirectory.path}/test/assets/images/logo.png');
|
||||
|
||||
final ByteData? asset = ByteData.view(file.readAsBytesSync().buffer);
|
||||
if (asset == null) {
|
||||
throw FlutterError('Unable to load asset: $key');
|
||||
}
|
||||
return asset;
|
||||
} else {
|
||||
throw 'Unknown asset key: $key';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user