mirror of
https://github.com/flutter/packages.git
synced 2025-07-01 07:08:10 +08:00
Make markdown tests more resiliant (#2959)
This commit is contained in:

committed by
GitHub

parent
1d6635df4d
commit
c4f56ec562
@ -17,9 +17,11 @@ void defineTests() {
|
||||
const String data = '# Header';
|
||||
await tester.pumpWidget(boilerplate(const MarkdownBody(data: data)));
|
||||
|
||||
final Iterable<Widget> widgets = tester.allWidgets;
|
||||
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||
find.byType(MarkdownBody),
|
||||
tester,
|
||||
);
|
||||
expectWidgetTypes(widgets, <Type>[
|
||||
Directionality,
|
||||
MarkdownBody,
|
||||
Column,
|
||||
Wrap,
|
||||
|
@ -17,9 +17,11 @@ void defineTests() {
|
||||
const String data = '---';
|
||||
await tester.pumpWidget(boilerplate(const MarkdownBody(data: data)));
|
||||
|
||||
final Iterable<Widget> widgets = tester.allWidgets;
|
||||
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||
find.byType(MarkdownBody),
|
||||
tester,
|
||||
);
|
||||
expectWidgetTypes(widgets, <Type>[
|
||||
Directionality,
|
||||
MarkdownBody,
|
||||
Container,
|
||||
DecoratedBox,
|
||||
@ -36,9 +38,11 @@ void defineTests() {
|
||||
const String data = '-----';
|
||||
await tester.pumpWidget(boilerplate(const MarkdownBody(data: data)));
|
||||
|
||||
final Iterable<Widget> widgets = tester.allWidgets;
|
||||
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||
find.byType(MarkdownBody),
|
||||
tester,
|
||||
);
|
||||
expectWidgetTypes(widgets, <Type>[
|
||||
Directionality,
|
||||
MarkdownBody,
|
||||
Container,
|
||||
DecoratedBox,
|
||||
@ -55,9 +59,11 @@ void defineTests() {
|
||||
const String data = '* * *';
|
||||
await tester.pumpWidget(boilerplate(const MarkdownBody(data: data)));
|
||||
|
||||
final Iterable<Widget> widgets = tester.allWidgets;
|
||||
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||
find.byType(MarkdownBody),
|
||||
tester,
|
||||
);
|
||||
expectWidgetTypes(widgets, <Type>[
|
||||
Directionality,
|
||||
MarkdownBody,
|
||||
Container,
|
||||
DecoratedBox,
|
||||
@ -74,9 +80,11 @@ void defineTests() {
|
||||
const String data = '# h1\n ## h2\n* * *';
|
||||
await tester.pumpWidget(boilerplate(const MarkdownBody(data: data)));
|
||||
|
||||
final Iterable<Widget> widgets = tester.allWidgets;
|
||||
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||
find.byType(MarkdownBody),
|
||||
tester,
|
||||
);
|
||||
expectWidgetTypes(widgets, <Type>[
|
||||
Directionality,
|
||||
MarkdownBody,
|
||||
Column,
|
||||
Column,
|
||||
|
@ -65,9 +65,11 @@ void defineTests() {
|
||||
),
|
||||
);
|
||||
|
||||
final List<Widget> widgets = tester.allWidgets.toList();
|
||||
expectWidgetTypes(widgets.take(3), <Type>[
|
||||
Directionality,
|
||||
final List<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||
find.byType(Markdown),
|
||||
tester,
|
||||
).toList();
|
||||
expectWidgetTypes(widgets.take(2), <Type>[
|
||||
Markdown,
|
||||
ListView,
|
||||
]);
|
||||
|
@ -317,9 +317,11 @@ void defineTests() {
|
||||
styleSheet: style,
|
||||
)));
|
||||
|
||||
final Iterable<Widget> widgets = tester.allWidgets;
|
||||
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||
find.byType(MarkdownBody),
|
||||
tester,
|
||||
);
|
||||
expectWidgetTypes(widgets, <Type>[
|
||||
Directionality,
|
||||
MarkdownBody,
|
||||
Column,
|
||||
Padding,
|
||||
|
@ -32,9 +32,11 @@ void defineTests() {
|
||||
),
|
||||
);
|
||||
|
||||
final Iterable<Widget> widgets = tester.allWidgets;
|
||||
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||
find.byType(MarkdownBody),
|
||||
tester,
|
||||
);
|
||||
expectWidgetTypes(widgets, <Type>[
|
||||
Directionality,
|
||||
MarkdownBody,
|
||||
Column,
|
||||
Column,
|
||||
|
@ -43,9 +43,14 @@ void defineTests() {
|
||||
),
|
||||
);
|
||||
|
||||
final Iterable<Widget> widgets = tester.allWidgets;
|
||||
expectWidgetTypes(
|
||||
widgets, <Type>[Directionality, MarkdownBody, Column]);
|
||||
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||
find.byType(MarkdownBody),
|
||||
tester,
|
||||
);
|
||||
expectWidgetTypes(widgets, <Type>[
|
||||
MarkdownBody,
|
||||
Column,
|
||||
]);
|
||||
},
|
||||
);
|
||||
|
||||
@ -58,9 +63,16 @@ void defineTests() {
|
||||
),
|
||||
);
|
||||
|
||||
final Iterable<Widget> widgets = tester.allWidgets;
|
||||
expectWidgetTypes(widgets,
|
||||
<Type>[Directionality, MarkdownBody, Column, Wrap, RichText]);
|
||||
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||
find.byType(MarkdownBody),
|
||||
tester,
|
||||
);
|
||||
expectWidgetTypes(widgets, <Type>[
|
||||
MarkdownBody,
|
||||
Column,
|
||||
Wrap,
|
||||
RichText,
|
||||
]);
|
||||
expectTextStrings(widgets, <String>['Hello']);
|
||||
},
|
||||
);
|
||||
@ -77,9 +89,16 @@ void defineTests() {
|
||||
),
|
||||
);
|
||||
|
||||
final Iterable<Widget> widgets = tester.allWidgets;
|
||||
expectWidgetTypes(widgets,
|
||||
<Type>[Directionality, MarkdownBody, Column, Wrap, RichText]);
|
||||
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||
find.byType(MarkdownBody),
|
||||
tester,
|
||||
);
|
||||
expectWidgetTypes(widgets, <Type>[
|
||||
MarkdownBody,
|
||||
Column,
|
||||
Wrap,
|
||||
RichText,
|
||||
]);
|
||||
expectTextStrings(widgets, <String>['aaa bbb']);
|
||||
});
|
||||
});
|
||||
@ -96,9 +115,12 @@ void defineTests() {
|
||||
),
|
||||
);
|
||||
|
||||
final Iterable<Widget> widgets = tester.allWidgets;
|
||||
expectWidgetTypes(widgets,
|
||||
<Type>[Directionality, MarkdownBody, Column, Wrap, RichText]);
|
||||
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||
find.byType(MarkdownBody),
|
||||
tester,
|
||||
);
|
||||
expectWidgetTypes(
|
||||
widgets, <Type>[MarkdownBody, Column, Wrap, RichText]);
|
||||
expectTextStrings(widgets, <String>['line 1\nline 2']);
|
||||
},
|
||||
);
|
||||
@ -114,9 +136,12 @@ void defineTests() {
|
||||
),
|
||||
);
|
||||
|
||||
final Iterable<Widget> widgets = tester.allWidgets;
|
||||
expectWidgetTypes(widgets,
|
||||
<Type>[Directionality, MarkdownBody, Column, Wrap, RichText]);
|
||||
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||
find.byType(MarkdownBody),
|
||||
tester,
|
||||
);
|
||||
expectWidgetTypes(
|
||||
widgets, <Type>[MarkdownBody, Column, Wrap, RichText]);
|
||||
expectTextStrings(widgets, <String>['line 1\nline 2']);
|
||||
},
|
||||
);
|
||||
@ -131,9 +156,16 @@ void defineTests() {
|
||||
),
|
||||
);
|
||||
|
||||
final Iterable<Widget> widgets = tester.allWidgets;
|
||||
expectWidgetTypes(widgets,
|
||||
<Type>[Directionality, MarkdownBody, Column, Wrap, RichText]);
|
||||
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||
find.byType(MarkdownBody),
|
||||
tester,
|
||||
);
|
||||
expectWidgetTypes(widgets, <Type>[
|
||||
MarkdownBody,
|
||||
Column,
|
||||
Wrap,
|
||||
RichText,
|
||||
]);
|
||||
expectTextStrings(widgets, <String>['line 1. line 2.']);
|
||||
},
|
||||
);
|
||||
@ -148,9 +180,16 @@ void defineTests() {
|
||||
),
|
||||
);
|
||||
|
||||
final Iterable<Widget> widgets = tester.allWidgets;
|
||||
expectWidgetTypes(widgets,
|
||||
<Type>[Directionality, MarkdownBody, Column, Wrap, RichText]);
|
||||
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||
find.byType(MarkdownBody),
|
||||
tester,
|
||||
);
|
||||
expectWidgetTypes(widgets, <Type>[
|
||||
MarkdownBody,
|
||||
Column,
|
||||
Wrap,
|
||||
RichText,
|
||||
]);
|
||||
expectTextStrings(widgets, <String>['line 1. line 2.']);
|
||||
},
|
||||
);
|
||||
@ -168,9 +207,12 @@ void defineTests() {
|
||||
),
|
||||
);
|
||||
|
||||
final Iterable<Widget> widgets = tester.allWidgets;
|
||||
expectWidgetTypes(widgets,
|
||||
<Type>[Directionality, MarkdownBody, Column, Wrap, RichText]);
|
||||
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||
find.byType(MarkdownBody),
|
||||
tester,
|
||||
);
|
||||
expectWidgetTypes(
|
||||
widgets, <Type>[MarkdownBody, Column, Wrap, RichText]);
|
||||
expectTextStrings(widgets, <String>['line 1.\nline 2.']);
|
||||
},
|
||||
);
|
||||
@ -247,9 +289,16 @@ void defineTests() {
|
||||
),
|
||||
);
|
||||
|
||||
final Iterable<Widget> widgets = tester.allWidgets;
|
||||
expectWidgetTypes(widgets,
|
||||
<Type>[Directionality, MarkdownBody, Column, Wrap, RichText]);
|
||||
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||
find.byType(MarkdownBody),
|
||||
tester,
|
||||
);
|
||||
expectWidgetTypes(widgets, <Type>[
|
||||
MarkdownBody,
|
||||
Column,
|
||||
Wrap,
|
||||
RichText,
|
||||
]);
|
||||
expectTextStrings(widgets, <String>['strikethrough']);
|
||||
});
|
||||
});
|
||||
|
@ -18,6 +18,17 @@ final TextTheme textTheme = Typography.material2018()
|
||||
.black
|
||||
.merge(const TextTheme(bodyMedium: TextStyle(fontSize: 12.0)));
|
||||
|
||||
Iterable<Widget> selfAndDescendantWidgetsOf(Finder start, WidgetTester tester) {
|
||||
final Element startElement = tester.element(start);
|
||||
final Iterable<Widget> descendants =
|
||||
collectAllElementsFrom(startElement, skipOffstage: false)
|
||||
.map((Element e) => e.widget);
|
||||
return <Widget>[
|
||||
startElement.widget,
|
||||
...descendants,
|
||||
];
|
||||
}
|
||||
|
||||
void expectWidgetTypes(Iterable<Widget> widgets, List<Type> expected) {
|
||||
final List<Type> actual = widgets.map((Widget w) => w.runtimeType).toList();
|
||||
expect(actual, expected);
|
||||
|
Reference in New Issue
Block a user