-
-
Notifications
You must be signed in to change notification settings - Fork 902
/
Copy patha_test.dart
91 lines (83 loc) · 2.45 KB
/
a_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
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_test/flutter_test.dart';
import '../test_utils.dart';
void main() {
testWidgets('<a> test', (WidgetTester tester) async {
await tester.pumpWidget(
TestApp(
child: Html(
data: """<a>Hello, world!</a>""",
),
),
);
expect(find.text("Hello, world!", findRichText: true), findsOneWidget);
});
testWidgets('<a> test with href', (WidgetTester tester) async {
await tester.pumpWidget(
TestApp(
child: Html(
data: """<a href="https://example.com">Hello, world!</a>""",
),
),
);
expect(find.text("Hello, world!", findRichText: true), findsOneWidget);
});
testWidgets('<a> with widget child renders', (WidgetTester tester) async {
await tester.pumpWidget(
TestApp(
child: Html(
data: """<a href="https://example.com"><icon></icon></a>""",
extensions: [
TagExtension(
tagsToExtend: {"icon"},
child: const Icon(Icons.check),
),
],
),
),
);
expect(find.byIcon(Icons.check), findsOneWidget);
});
testWidgets('Tapping <a> test', (WidgetTester tester) async {
String tappedUrl = "";
await tester.pumpWidget(
TestApp(
child: Html(
data: """<a href="https://example.com">Hello, world!</a>""",
onLinkTap: (url, _, __) {
tappedUrl = url ?? "";
},
),
),
);
final finder = find.textRange.ofSubstring("Hello, world!");
expect(finder, findsOne);
expect(tappedUrl, equals(""));
await tester.tapOnText(finder);
expect(tappedUrl, equals("https://example.com"));
});
testWidgets('Tapping <a> with widget works', (WidgetTester tester) async {
String tappedUrl = "";
await tester.pumpWidget(
TestApp(
child: Html(
data: """<a href="https://example.com"><icon></icon></a>""",
onLinkTap: (url, _, __) {
tappedUrl = url ?? "";
},
extensions: [
TagExtension(
tagsToExtend: {"icon"},
child: const Icon(Icons.check),
),
],
),
),
);
expect(find.byIcon(Icons.check), findsOneWidget);
expect(tappedUrl, equals(""));
await tester.tap(find.byIcon(Icons.check));
expect(tappedUrl, equals("https://example.com"));
});
}