feat: add Image support to finder (#88761)
This commit is contained in:
@@ -103,6 +103,19 @@ class CommonFinders {
|
||||
);
|
||||
}
|
||||
|
||||
/// Finds [Image] and [FadeInImage] widgets containing `image` equal to the
|
||||
/// `image` argument.
|
||||
///
|
||||
/// ## Sample code
|
||||
///
|
||||
/// ```dart
|
||||
/// expect(find.image(FileImage(File(filePath))), findsOneWidget);
|
||||
/// ```
|
||||
///
|
||||
/// If the `skipOffstage` argument is true (the default), then this skips
|
||||
/// nodes that are [Offstage] or that are from inactive [Route]s.
|
||||
Finder image(ImageProvider image, { bool skipOffstage = true }) => _WidgetImageFinder(image, skipOffstage: skipOffstage);
|
||||
|
||||
/// Finds widgets by searching for one with a particular [Key].
|
||||
///
|
||||
/// ## Sample code
|
||||
@@ -690,6 +703,26 @@ class _WidgetTypeFinder extends MatchFinder {
|
||||
}
|
||||
}
|
||||
|
||||
class _WidgetImageFinder extends MatchFinder {
|
||||
_WidgetImageFinder(this.image, { bool skipOffstage = true }) : super(skipOffstage: skipOffstage);
|
||||
|
||||
final ImageProvider image;
|
||||
|
||||
@override
|
||||
String get description => 'image "$image"';
|
||||
|
||||
@override
|
||||
bool matches(Element candidate) {
|
||||
final Widget widget = candidate.widget;
|
||||
if (widget is Image) {
|
||||
return widget.image == image;
|
||||
} else if (widget is FadeInImage) {
|
||||
return widget.image == image;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class _WidgetIconFinder extends MatchFinder {
|
||||
_WidgetIconFinder(this.icon, { bool skipOffstage = true }) : super(skipOffstage: skipOffstage);
|
||||
|
||||
|
||||
@@ -2,11 +2,22 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('image', () {
|
||||
testWidgets('finds Image widgets', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(_boilerplate(
|
||||
Image(image: FileImage(File('test'), scale: 1.0))
|
||||
));
|
||||
expect(find.image(FileImage(File('test'), scale: 1.0)), findsOneWidget);
|
||||
});
|
||||
});
|
||||
|
||||
group('text', () {
|
||||
testWidgets('finds Text widgets', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(_boilerplate(
|
||||
|
||||
Reference in New Issue
Block a user