mirror of
https://github.com/flutter/packages.git
synced 2025-07-01 23:51:55 +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';
|
const String data = '# Header';
|
||||||
await tester.pumpWidget(boilerplate(const MarkdownBody(data: 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>[
|
expectWidgetTypes(widgets, <Type>[
|
||||||
Directionality,
|
|
||||||
MarkdownBody,
|
MarkdownBody,
|
||||||
Column,
|
Column,
|
||||||
Wrap,
|
Wrap,
|
||||||
|
@ -17,9 +17,11 @@ void defineTests() {
|
|||||||
const String data = '---';
|
const String data = '---';
|
||||||
await tester.pumpWidget(boilerplate(const MarkdownBody(data: 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>[
|
expectWidgetTypes(widgets, <Type>[
|
||||||
Directionality,
|
|
||||||
MarkdownBody,
|
MarkdownBody,
|
||||||
Container,
|
Container,
|
||||||
DecoratedBox,
|
DecoratedBox,
|
||||||
@ -36,9 +38,11 @@ void defineTests() {
|
|||||||
const String data = '-----';
|
const String data = '-----';
|
||||||
await tester.pumpWidget(boilerplate(const MarkdownBody(data: 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>[
|
expectWidgetTypes(widgets, <Type>[
|
||||||
Directionality,
|
|
||||||
MarkdownBody,
|
MarkdownBody,
|
||||||
Container,
|
Container,
|
||||||
DecoratedBox,
|
DecoratedBox,
|
||||||
@ -55,9 +59,11 @@ void defineTests() {
|
|||||||
const String data = '* * *';
|
const String data = '* * *';
|
||||||
await tester.pumpWidget(boilerplate(const MarkdownBody(data: 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>[
|
expectWidgetTypes(widgets, <Type>[
|
||||||
Directionality,
|
|
||||||
MarkdownBody,
|
MarkdownBody,
|
||||||
Container,
|
Container,
|
||||||
DecoratedBox,
|
DecoratedBox,
|
||||||
@ -74,9 +80,11 @@ void defineTests() {
|
|||||||
const String data = '# h1\n ## h2\n* * *';
|
const String data = '# h1\n ## h2\n* * *';
|
||||||
await tester.pumpWidget(boilerplate(const MarkdownBody(data: 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>[
|
expectWidgetTypes(widgets, <Type>[
|
||||||
Directionality,
|
|
||||||
MarkdownBody,
|
MarkdownBody,
|
||||||
Column,
|
Column,
|
||||||
Column,
|
Column,
|
||||||
|
@ -65,9 +65,11 @@ void defineTests() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final List<Widget> widgets = tester.allWidgets.toList();
|
final List<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||||
expectWidgetTypes(widgets.take(3), <Type>[
|
find.byType(Markdown),
|
||||||
Directionality,
|
tester,
|
||||||
|
).toList();
|
||||||
|
expectWidgetTypes(widgets.take(2), <Type>[
|
||||||
Markdown,
|
Markdown,
|
||||||
ListView,
|
ListView,
|
||||||
]);
|
]);
|
||||||
|
@ -317,9 +317,11 @@ void defineTests() {
|
|||||||
styleSheet: style,
|
styleSheet: style,
|
||||||
)));
|
)));
|
||||||
|
|
||||||
final Iterable<Widget> widgets = tester.allWidgets;
|
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||||
|
find.byType(MarkdownBody),
|
||||||
|
tester,
|
||||||
|
);
|
||||||
expectWidgetTypes(widgets, <Type>[
|
expectWidgetTypes(widgets, <Type>[
|
||||||
Directionality,
|
|
||||||
MarkdownBody,
|
MarkdownBody,
|
||||||
Column,
|
Column,
|
||||||
Padding,
|
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>[
|
expectWidgetTypes(widgets, <Type>[
|
||||||
Directionality,
|
|
||||||
MarkdownBody,
|
MarkdownBody,
|
||||||
Column,
|
Column,
|
||||||
Column,
|
Column,
|
||||||
|
@ -43,9 +43,14 @@ void defineTests() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final Iterable<Widget> widgets = tester.allWidgets;
|
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||||
expectWidgetTypes(
|
find.byType(MarkdownBody),
|
||||||
widgets, <Type>[Directionality, MarkdownBody, Column]);
|
tester,
|
||||||
|
);
|
||||||
|
expectWidgetTypes(widgets, <Type>[
|
||||||
|
MarkdownBody,
|
||||||
|
Column,
|
||||||
|
]);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -58,9 +63,16 @@ void defineTests() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final Iterable<Widget> widgets = tester.allWidgets;
|
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||||
expectWidgetTypes(widgets,
|
find.byType(MarkdownBody),
|
||||||
<Type>[Directionality, MarkdownBody, Column, Wrap, RichText]);
|
tester,
|
||||||
|
);
|
||||||
|
expectWidgetTypes(widgets, <Type>[
|
||||||
|
MarkdownBody,
|
||||||
|
Column,
|
||||||
|
Wrap,
|
||||||
|
RichText,
|
||||||
|
]);
|
||||||
expectTextStrings(widgets, <String>['Hello']);
|
expectTextStrings(widgets, <String>['Hello']);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -77,9 +89,16 @@ void defineTests() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final Iterable<Widget> widgets = tester.allWidgets;
|
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||||
expectWidgetTypes(widgets,
|
find.byType(MarkdownBody),
|
||||||
<Type>[Directionality, MarkdownBody, Column, Wrap, RichText]);
|
tester,
|
||||||
|
);
|
||||||
|
expectWidgetTypes(widgets, <Type>[
|
||||||
|
MarkdownBody,
|
||||||
|
Column,
|
||||||
|
Wrap,
|
||||||
|
RichText,
|
||||||
|
]);
|
||||||
expectTextStrings(widgets, <String>['aaa bbb']);
|
expectTextStrings(widgets, <String>['aaa bbb']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -96,9 +115,12 @@ void defineTests() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final Iterable<Widget> widgets = tester.allWidgets;
|
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||||
expectWidgetTypes(widgets,
|
find.byType(MarkdownBody),
|
||||||
<Type>[Directionality, MarkdownBody, Column, Wrap, RichText]);
|
tester,
|
||||||
|
);
|
||||||
|
expectWidgetTypes(
|
||||||
|
widgets, <Type>[MarkdownBody, Column, Wrap, RichText]);
|
||||||
expectTextStrings(widgets, <String>['line 1\nline 2']);
|
expectTextStrings(widgets, <String>['line 1\nline 2']);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -114,9 +136,12 @@ void defineTests() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final Iterable<Widget> widgets = tester.allWidgets;
|
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||||
expectWidgetTypes(widgets,
|
find.byType(MarkdownBody),
|
||||||
<Type>[Directionality, MarkdownBody, Column, Wrap, RichText]);
|
tester,
|
||||||
|
);
|
||||||
|
expectWidgetTypes(
|
||||||
|
widgets, <Type>[MarkdownBody, Column, Wrap, RichText]);
|
||||||
expectTextStrings(widgets, <String>['line 1\nline 2']);
|
expectTextStrings(widgets, <String>['line 1\nline 2']);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -131,9 +156,16 @@ void defineTests() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final Iterable<Widget> widgets = tester.allWidgets;
|
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||||
expectWidgetTypes(widgets,
|
find.byType(MarkdownBody),
|
||||||
<Type>[Directionality, MarkdownBody, Column, Wrap, RichText]);
|
tester,
|
||||||
|
);
|
||||||
|
expectWidgetTypes(widgets, <Type>[
|
||||||
|
MarkdownBody,
|
||||||
|
Column,
|
||||||
|
Wrap,
|
||||||
|
RichText,
|
||||||
|
]);
|
||||||
expectTextStrings(widgets, <String>['line 1. line 2.']);
|
expectTextStrings(widgets, <String>['line 1. line 2.']);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -148,9 +180,16 @@ void defineTests() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final Iterable<Widget> widgets = tester.allWidgets;
|
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||||
expectWidgetTypes(widgets,
|
find.byType(MarkdownBody),
|
||||||
<Type>[Directionality, MarkdownBody, Column, Wrap, RichText]);
|
tester,
|
||||||
|
);
|
||||||
|
expectWidgetTypes(widgets, <Type>[
|
||||||
|
MarkdownBody,
|
||||||
|
Column,
|
||||||
|
Wrap,
|
||||||
|
RichText,
|
||||||
|
]);
|
||||||
expectTextStrings(widgets, <String>['line 1. line 2.']);
|
expectTextStrings(widgets, <String>['line 1. line 2.']);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -168,9 +207,12 @@ void defineTests() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final Iterable<Widget> widgets = tester.allWidgets;
|
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||||
expectWidgetTypes(widgets,
|
find.byType(MarkdownBody),
|
||||||
<Type>[Directionality, MarkdownBody, Column, Wrap, RichText]);
|
tester,
|
||||||
|
);
|
||||||
|
expectWidgetTypes(
|
||||||
|
widgets, <Type>[MarkdownBody, Column, Wrap, RichText]);
|
||||||
expectTextStrings(widgets, <String>['line 1.\nline 2.']);
|
expectTextStrings(widgets, <String>['line 1.\nline 2.']);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -247,9 +289,16 @@ void defineTests() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final Iterable<Widget> widgets = tester.allWidgets;
|
final Iterable<Widget> widgets = selfAndDescendantWidgetsOf(
|
||||||
expectWidgetTypes(widgets,
|
find.byType(MarkdownBody),
|
||||||
<Type>[Directionality, MarkdownBody, Column, Wrap, RichText]);
|
tester,
|
||||||
|
);
|
||||||
|
expectWidgetTypes(widgets, <Type>[
|
||||||
|
MarkdownBody,
|
||||||
|
Column,
|
||||||
|
Wrap,
|
||||||
|
RichText,
|
||||||
|
]);
|
||||||
expectTextStrings(widgets, <String>['strikethrough']);
|
expectTextStrings(widgets, <String>['strikethrough']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -18,6 +18,17 @@ final TextTheme textTheme = Typography.material2018()
|
|||||||
.black
|
.black
|
||||||
.merge(const TextTheme(bodyMedium: TextStyle(fontSize: 12.0)));
|
.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) {
|
void expectWidgetTypes(Iterable<Widget> widgets, List<Type> expected) {
|
||||||
final List<Type> actual = widgets.map((Widget w) => w.runtimeType).toList();
|
final List<Type> actual = widgets.map((Widget w) => w.runtimeType).toList();
|
||||||
expect(actual, expected);
|
expect(actual, expected);
|
||||||
|
Reference in New Issue
Block a user