@@ -62,6 +62,13 @@ void main() {
6262 });
6363 });
6464
65+ Future <void > tapText (WidgetTester tester, Finder textFinder) async {
66+ final height = tester.getSize (textFinder).height;
67+ final target = tester.getTopLeft (textFinder)
68+ .translate (height/ 4 , height/ 2 ); // aim for middle of first letter
69+ await tester.tapAt (target);
70+ }
71+
6572 group ('LinkNode interactions' , () {
6673 // The Flutter test font uses square glyphs, so width equals height:
6774 // https://github.com/flutter/flutter/wiki/Flutter-Test-Fonts
@@ -85,7 +92,7 @@ void main() {
8592 await prepareContent (tester,
8693 '<p><a href="https://example/">hello</a></p>' );
8794
88- await tester. tap ( find.text ('hello' ));
95+ await tapText (tester, find.text ('hello' ));
8996 check (testBinding.takeLaunchUrlCalls ())
9097 .single.equals ((url: Uri .parse ('https://example/' ), mode: LaunchMode .platformDefault));
9198 }, variant: const TargetPlatformVariant ({TargetPlatform .android, TargetPlatform .iOS}));
@@ -111,7 +118,7 @@ void main() {
111118 testWidgets ('link nested in other spans' , (tester) async {
112119 await prepareContent (tester,
113120 '<p><strong><em><a href="https://a/">word</a></em></strong></p>' );
114- await tester. tap ( find.text ('word' ));
121+ await tapText (tester, find.text ('word' ));
115122 check (testBinding.takeLaunchUrlCalls ())
116123 .single.equals ((url: Uri .parse ('https://a/' ), mode: LaunchMode .platformDefault));
117124 });
@@ -134,15 +141,15 @@ void main() {
134141 testWidgets ('relative links are resolved' , (tester) async {
135142 await prepareContent (tester,
136143 '<p><a href="/a/b?c#d">word</a></p>' );
137- await tester. tap ( find.text ('word' ));
144+ await tapText (tester, find.text ('word' ));
138145 check (testBinding.takeLaunchUrlCalls ())
139146 .single.equals ((url: Uri .parse ('${eg .realmUrl }a/b?c#d' ), mode: LaunchMode .platformDefault));
140147 });
141148
142149 testWidgets ('link inside HeadingNode' , (tester) async {
143150 await prepareContent (tester,
144151 '<h6><a href="https://a/">word</a></h6>' );
145- await tester. tap ( find.text ('word' ));
152+ await tapText (tester, find.text ('word' ));
146153 check (testBinding.takeLaunchUrlCalls ())
147154 .single.equals ((url: Uri .parse ('https://a/' ), mode: LaunchMode .platformDefault));
148155 });
@@ -151,7 +158,7 @@ void main() {
151158 await prepareContent (tester,
152159 '<p><a href="file:///etc/bad">word</a></p>' );
153160 testBinding.launchUrlResult = false ;
154- await tester. tap ( find.text ('word' ));
161+ await tapText (tester, find.text ('word' ));
155162 await tester.pump ();
156163 check (testBinding.takeLaunchUrlCalls ())
157164 .single.equals ((url: Uri .parse ('file:///etc/bad' ), mode: LaunchMode .platformDefault));
@@ -187,7 +194,7 @@ void main() {
187194 final pushedRoutes = await prepareContent (tester,
188195 html: '<p><a href="/#narrow/stream/1-check">stream</a></p>' );
189196
190- await tester. tap ( find.text ('stream' ));
197+ await tapText (tester, find.text ('stream' ));
191198 check (testBinding.takeLaunchUrlCalls ()).isEmpty ();
192199 check (pushedRoutes).single.isA <WidgetRoute >()
193200 .page.isA <MessageListPage >().narrow.equals (const StreamNarrow (1 ));
@@ -198,7 +205,7 @@ void main() {
198205 final pushedRoutes = await prepareContent (tester,
199206 html: '<p><a href="/#narrow/stream/1-check/topic">invalid</a></p>' );
200207
201- await tester. tap ( find.text ('invalid' ));
208+ await tapText (tester, find.text ('invalid' ));
202209 final expectedUrl = eg.realmUrl.resolve ('/#narrow/stream/1-check/topic' );
203210 check (testBinding.takeLaunchUrlCalls ())
204211 .single.equals ((url: expectedUrl, mode: LaunchMode .platformDefault));
0 commit comments