Unverified Commit 0343555a authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Migrate more tests (#68037)

* Migrate more tests

* fix
parent dbf8cd4b
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
......@@ -18,12 +16,12 @@ void checkTree(WidgetTester tester, List<BoxDecoration> expectedDecorations) {
expect(element.renderObject, isA<RenderStack>());
final RenderStack renderObject = element.renderObject as RenderStack;
try {
RenderObject child = renderObject.firstChild;
RenderObject? child = renderObject.firstChild;
for (final BoxDecoration decoration in expectedDecorations) {
expect(child, isA<RenderDecoratedBox>());
final RenderDecoratedBox decoratedBox = child as RenderDecoratedBox;
final RenderDecoratedBox decoratedBox = child! as RenderDecoratedBox;
expect(decoratedBox.decoration, equals(decoration));
final StackParentData decoratedBoxParentData = decoratedBox.parentData as StackParentData;
final StackParentData decoratedBoxParentData = decoratedBox.parentData! as StackParentData;
child = decoratedBoxParentData.nextSibling;
}
expect(child, isNull);
......@@ -34,10 +32,13 @@ void checkTree(WidgetTester tester, List<BoxDecoration> expectedDecorations) {
}
class MockMultiChildRenderObjectWidget extends MultiChildRenderObjectWidget {
MockMultiChildRenderObjectWidget({ Key key, List<Widget> children }) : super(key: key, children: children);
MockMultiChildRenderObjectWidget({ Key? key, required List<Widget> children }) : super(key: key, children: children);
@override
RenderObject createRenderObject(BuildContext context) => null;
RenderObject createRenderObject(BuildContext context) {
assert(false);
return FakeRenderObject();
}
}
void main() {
......@@ -354,17 +355,11 @@ void main() {
checkTree(tester, <BoxDecoration>[kBoxDecorationB, kBoxDecorationC]);
});
}
// Regression test for https://github.com/flutter/flutter/issues/37136.
test('provides useful assertion message when one of the children is null', () {
bool assertionTriggered = false;
try {
MockMultiChildRenderObjectWidget(children: const <Widget>[null]);
} catch (e) {
expect(e.toString(), contains("MockMultiChildRenderObjectWidget's children must not contain any null values,"));
assertionTriggered = true;
}
expect(assertionTriggered, isTrue);
});
class FakeRenderObject extends RenderBox {
@override
void performLayout() {
size = constraints.biggest;
}
}
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -68,7 +66,7 @@ void main() {
List<String> _getChildOrder(RenderFlex flex) {
final List<String> childOrder = <String>[];
flex.visitChildren((RenderObject child) {
childOrder.add(((child as RenderParagraph).text as TextSpan).text);
childOrder.add(((child as RenderParagraph).text as TextSpan).text!);
});
return childOrder;
}
......@@ -2,15 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'test_widgets.dart';
class TestCustomPainter extends CustomPainter {
TestCustomPainter({ this.log, this.name });
TestCustomPainter({ required this.log, required this.name });
final List<String> log;
final String name;
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
......@@ -60,11 +58,11 @@ void main() {
final NavigatorState navigator = tester.state(find.byType(Navigator));
final List<String> log = <String>[];
observer
..onPushed = (Route<dynamic> route, Route<dynamic> previousRoute) {
log.add('${route.settings.name} pushed, previous route: ${previousRoute.settings.name}');
..onPushed = (Route<dynamic>? route, Route<dynamic>? previousRoute) {
log.add('${route!.settings.name} pushed, previous route: ${previousRoute!.settings.name}');
}
..onRemoved = (Route<dynamic> route, Route<dynamic> previousRoute) {
log.add('${route.settings.name} removed, previous route: ${previousRoute?.settings?.name}');
..onRemoved = (Route<dynamic>? route, Route<dynamic>? previousRoute) {
log.add('${route!.settings.name} removed, previous route: ${previousRoute?.settings.name}');
};
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:typed_data';
import 'dart:ui' as ui show Image;
......@@ -30,21 +28,20 @@ Future<void> main() async {
),
);
final RenderImage renderImage = tester.renderObject(find.byType(Image));
final ui.Image image1 = renderImage.image;
final ui.Image? image1 = renderImage.image;
await tester.pump(const Duration(milliseconds: 100));
final ui.Image image2 = renderImage.image;
final ui.Image? image2 = renderImage.image;
expect(image1, isNot(same(image2)));
Navigator.pushNamed(imageKey.currentContext, '/page');
Navigator.pushNamed(imageKey.currentContext!, '/page');
await tester.pump(); // Starts the page animation.
await tester.pump(const Duration(seconds: 1)); // Let the page animation complete.
// The image is now obscured by another page, it should not be changing
// frames.
final ui.Image image3 = renderImage.image;
final ui.Image? image3 = renderImage.image;
await tester.pump(const Duration(milliseconds: 100));
final ui.Image image4 = renderImage.image;
final ui.Image? image4 = renderImage.image;
expect(image3, same(image4));
});
}
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
......@@ -191,7 +189,7 @@ void main() {
final Element element = find.byType(RepaintBoundary).first.evaluate().single;
// The following line will send the layer to engine and cause crash if an
// empty opacity layer is sent.
final OffsetLayer offsetLayer = element.renderObject.debugLayer as OffsetLayer;
final OffsetLayer offsetLayer = element.renderObject!.debugLayer! as OffsetLayer;
await offsetLayer.toImage(const Rect.fromLTRB(0.0, 0.0, 1.0, 1.0));
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/42767
}
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';
......@@ -52,7 +50,7 @@ void main() {
final Key child2Key = UniqueKey();
final Key child3Key = UniqueKey();
Widget buildFrame({ double spacing, TextDirection textDirection }) {
Widget buildFrame({ required double spacing, required TextDirection textDirection }) {
return Directionality(
textDirection: textDirection,
child: Align(
......@@ -176,7 +174,7 @@ void main() {
});
testWidgets('OverflowBar intrinsic width', (WidgetTester tester) async {
Widget buildFrame({ double width }) {
Widget buildFrame({ required double width }) {
return Directionality(
textDirection: TextDirection.ltr,
child: Center(
......@@ -207,7 +205,7 @@ void main() {
});
testWidgets('OverflowBar intrinsic height', (WidgetTester tester) async {
Widget buildFrame({ double maxWidth }) {
Widget buildFrame({ required double maxWidth }) {
return Directionality(
textDirection: TextDirection.ltr,
child: Center(
......
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