Commit c5fcaf6d authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Introduce a `paints` matcher, and convert the previous customers of (#7567)

MockCanvas to use it instead.

Currently it only supports a very limited set of drawing features, but
adding new ones is easy.

Once the feature set is more complete, and we've used this a bunch, if
it feels right, this API will get promoted to flutter_test.
parent 3b104a81
......@@ -204,21 +204,12 @@ void main() {
);
RenderBox box = tester.renderObject(find.byType(MergeableMaterial));
MockCanvas canvas = new MockCanvas();
box.paint(new MockPaintingContext(canvas), Offset.zero);
final Invocation drawCommand = canvas.invocations.firstWhere((Invocation invocation) {
return invocation.memberName == #drawRRect;
});
final BoxShadow boxShadow = kElevationToShadow[2][0];
final RRect rrect = kMaterialEdges[MaterialType.card].toRRect(
new Rect.fromLTRB(0.0, 0.0, 800.0, 100.0)
);
expect(drawCommand.positionalArguments[0], equals(rrect));
expect(drawCommand.positionalArguments[1].color, equals(boxShadow.color));
expect(drawCommand.positionalArguments[1].maskFilter, isNotNull);
expect(box, paints..rrect(rrect: rrect, color: boxShadow.color, hasMaskFilter: true));
});
testWidgets('MergeableMaterial merge gap', (WidgetTester tester) async {
......
......@@ -104,19 +104,11 @@ void main() {
final RenderBox sliderBox =
tester.firstRenderObject<RenderBox>(find.byType(Slider));
Paint getThumbPaint() {
final MockCanvas canvas = new MockCanvas();
sliderBox.paint(new MockPaintingContext(canvas), Offset.zero);
final Invocation drawCommand =
canvas.invocations.where((Invocation invocation) {
return invocation.memberName == #drawCircle;
}).single;
return drawCommand.positionalArguments[2];
}
expect(getThumbPaint().style, equals(PaintingStyle.fill));
expect(sliderBox, paints..circle(style: PaintingStyle.fill));
expect(sliderBox, isNot(paints..circle()..circle()));
await tester.pumpWidget(buildApp(true));
expect(getThumbPaint().style, equals(PaintingStyle.stroke));
expect(sliderBox, paints..circle(style: PaintingStyle.stroke));
expect(sliderBox, isNot(paints..circle()..circle()));
});
testWidgets('Slider can tap in vertical scroller',
......
......@@ -7,8 +7,6 @@ import 'dart:ui' as ui;
import 'package:flutter/painting.dart';
import 'package:flutter_test/flutter_test.dart';
import '../rendering/mock_canvas.dart';
void main() {
test("TextPainter caret test", () {
TextPainter painter = new TextPainter();
......@@ -32,6 +30,6 @@ void main() {
test("TextPainter error test", () {
TextPainter painter = new TextPainter();
expect(() { painter.paint(new MockCanvas(), Offset.zero); }, throwsFlutterError);
expect(() { painter.paint(null, Offset.zero); }, throwsFlutterError);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment