-
-
Notifications
You must be signed in to change notification settings - Fork 901
/
Copy pathflutter_html_test.dart
101 lines (94 loc) · 2.51 KB
/
flutter_html_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
"Check that widget does not fail on empty data",
(tester) async {
await tester.pumpWidget(
MaterialApp(
home: Html(
data: "",
),
),
);
expect(find.text('', findRichText: true), findsOneWidget);
},
);
testWidgets(
"Check that widget displays given text",
(tester) async {
await tester.pumpWidget(
MaterialApp(
home: Html(
data: "Text",
),
),
);
expect(find.text('Text', findRichText: true), findsOneWidget);
},
);
testWidgets('Check that a simple element is displayed', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: Html(
data: "<p>Text</p>",
),
),
);
expect(find.text('Text', findRichText: true), findsOneWidget);
});
testWidgets(
'Check that a simple element is hidden when tagsList does not contain it',
(tester) async {
await tester.pumpWidget(
MaterialApp(
home: Html(
data: "<p>Text</p>",
onlyRenderTheseTags: const {'html', 'body', 'div'}, //Anything but `p`
),
),
);
expect(find.text('Text', findRichText: true), findsNothing);
});
testWidgets(
'Check that a simple element is displayed when it is included in tagsList',
(tester) async {
await tester.pumpWidget(
MaterialApp(
home: Html(
data: "<p>Text</p>",
onlyRenderTheseTags: const {'html', 'body', 'p'},
),
),
);
expect(find.text('Text', findRichText: true), findsOneWidget);
});
testWidgets('Check that a custom element is not displayed', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: Html(
data: "<custom>Text</custom>",
),
),
);
expect(find.text('Text', findRichText: true), findsNothing);
});
testWidgets('Check that a custom element is displayed when configured',
(tester) async {
await tester.pumpWidget(
MaterialApp(
home: Html(
data: "<custom>Text</custom>",
extensions: [
TagExtension(
tagsToExtend: {"custom"},
builder: (context) => Text(context.innerHtml),
),
],
),
),
);
expect(find.text('Text', findRichText: true), findsOneWidget);
});
}