Skip to content

Commit 65ace80

Browse files
committed
Start adding more tests
1 parent 83998fd commit 65ace80

File tree

1 file changed

+50
-65
lines changed

1 file changed

+50
-65
lines changed

test/html_parser_test.dart

Lines changed: 50 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,76 @@
11
import 'package:flutter/material.dart';
2-
import 'package:flutter_html/html_parser.dart';
32
import 'package:flutter_test/flutter_test.dart';
43
import 'package:flutter_html/flutter_html.dart';
54

65
void main() {
7-
// test('Checks that `parse` does not throw an exception', () {
8-
// final elementList = HtmlOldParser(width: 42.0).parse("<b>Bold Text</b>");
9-
// expect(elementList, isNotNull);
10-
// });
116

12-
testWidgets('Tests some plain old text', (WidgetTester tester) async {
13-
await tester.pumpWidget(MaterialApp(
7+
testWidgets("Check that default parser does not fail on empty data", (tester) async {
8+
await tester.pumpWidget(
9+
MaterialApp(
1410
home: Scaffold(
15-
body: Html(data: "This is some plain text"),
16-
)));
17-
18-
expect(find.text("This is some plain text"), findsOneWidget);
19-
});
20-
21-
testWidgets('Tests that a <b> element gets rendered correctly',
22-
(WidgetTester tester) async {
23-
await tester.pumpWidget(MaterialApp(
24-
home: Scaffold(
25-
body: Html(
26-
data: "<b>Bold Text</b>",
11+
body: Html(
12+
data: "",
13+
),
2714
),
2815
),
29-
));
30-
31-
expect(find.byType(RichText), findsOneWidget);
16+
);
3217
});
3318

34-
testWidgets(
35-
'Tests that a combination of elements and text nodes gets rendered',
36-
(WidgetTester tester) async {
37-
await tester.pumpWidget(MaterialApp(
38-
home: Scaffold(
39-
body: Html(
40-
data: "<b>Bold Text</b> and plain text",
19+
testWidgets("Check that RichText parser does not fail on empty data", (tester) async {
20+
await tester.pumpWidget(
21+
MaterialApp(
22+
home: Scaffold(
23+
body: Html(
24+
data: "",
25+
useRichText: true,
26+
),
4127
),
4228
),
43-
));
44-
45-
expect(find.byType(RichText), findsNWidgets(2));
46-
expect(find.text(" and plain text"), findsOneWidget);
29+
);
4730
});
4831

49-
testWidgets('Tests that a <i> element gets rendered correctly',
50-
(WidgetTester tester) async {
51-
await tester.pumpWidget(MaterialApp(
52-
home: Scaffold(
53-
body: Html(
54-
data: "<b>Bold Text</b>, <i>Italic Text</i> and plain text",
32+
testWidgets("Check that `a` tag is rendered by both parsers", (tester) async {
33+
String html = "<a href='https://github.com'>Test link</a>";
34+
await tester.pumpWidget(
35+
MaterialApp(
36+
home: Scaffold(
37+
body: Html(
38+
data: html,
39+
),
5540
),
5641
),
57-
));
42+
);
5843

59-
expect(find.byType(RichText), findsNWidgets(4));
60-
expect(find.text(", "), findsOneWidget);
61-
expect(find.text(" and plain text"), findsOneWidget);
62-
});
63-
64-
testWidgets('Tests that nested elements get rendered correctly',
65-
(WidgetTester tester) async {
66-
await tester.pumpWidget(MaterialApp(
67-
home: Scaffold(
68-
body: Html(
69-
data:
70-
"<b>Bold Text and <i>Italic bold text and <u>Underlined italic bold text</u></i></b>",
44+
await tester.pumpWidget(
45+
MaterialApp(
46+
home: Scaffold(
47+
body: Html(
48+
data: html,
49+
useRichText: true,
50+
),
7151
),
7252
),
73-
));
74-
75-
expect(find.byType(RichText), findsNWidgets(3));
53+
);
7654
});
7755

78-
testWidgets('Tests that the header elements (h1-h6) get rendered correctly',
79-
(WidgetTester tester) async {
80-
await tester.pumpWidget(MaterialApp(
81-
home: Scaffold(
82-
body: Html(
83-
data:
84-
"<h1>H1</h1><h2>H2</h2><h3>H3</h3><h4>H4</h4><h5>H5</h5><h6>H6</h6>",
56+
testWidgets("Check that tapping on the `a` tag calls the callback", (tester) async {
57+
String html = "<a href='https://github.com'>Test link</a>";
58+
String urlTapped;
59+
60+
await tester.pumpWidget(
61+
MaterialApp(
62+
home: Scaffold(
63+
body: Html(
64+
data: html,
65+
onLinkTap: (url) {
66+
urlTapped = url;
67+
},
68+
),
8569
),
8670
),
87-
));
88-
89-
expect(find.byType(RichText), findsNWidgets(6));
71+
);
72+
await tester.tap(find.text("Test link"));
73+
expect(urlTapped, "https://github.com");
9074
});
75+
9176
}

0 commit comments

Comments
 (0)