1
1
import 'dart:io' ;
2
2
3
3
import 'package:checks/checks.dart' ;
4
- import 'package:flutter/foundation.dart' ;
5
4
import 'package:flutter/material.dart' ;
6
5
import 'package:flutter_test/flutter_test.dart' ;
7
6
import 'package:url_launcher/url_launcher.dart' ;
@@ -57,8 +56,6 @@ void main() {
57
56
});
58
57
59
58
group ('LinkNode interactions' , () {
60
- const expectedModeAndroid = LaunchMode .externalApplication;
61
-
62
59
// The Flutter test font uses square glyphs, so width equals height:
63
60
// https://github.com/flutter/flutter/wiki/Flutter-Test-Fonts
64
61
const fontSize = 48.0 ;
@@ -80,10 +77,8 @@ void main() {
80
77
'<p><a href="https://example/">hello</a></p>' );
81
78
82
79
await tester.tap (find.text ('hello' ));
83
- final expectedMode = defaultTargetPlatform == TargetPlatform .android ?
84
- LaunchMode .externalApplication : LaunchMode .platformDefault;
85
80
check (testBinding.takeLaunchUrlCalls ())
86
- .single.equals ((url: Uri .parse ('https://example/' ), mode: expectedMode ));
81
+ .single.equals ((url: Uri .parse ('https://example/' ), mode: LaunchMode .platformDefault ));
87
82
}, variant: const TargetPlatformVariant ({TargetPlatform .android, TargetPlatform .iOS}));
88
83
89
84
testWidgets ('multiple links in paragraph' , (tester) async {
@@ -97,19 +92,19 @@ void main() {
97
92
98
93
await tester.tapAt (base .translate (1 * fontSize, 0 )); // "fXo bar baz"
99
94
check (testBinding.takeLaunchUrlCalls ())
100
- .single.equals ((url: Uri .parse ('https://a/' ), mode: expectedModeAndroid ));
95
+ .single.equals ((url: Uri .parse ('https://a/' ), mode: LaunchMode .platformDefault ));
101
96
102
97
await tester.tapAt (base .translate (9 * fontSize, 0 )); // "foo bar bXz"
103
98
check (testBinding.takeLaunchUrlCalls ())
104
- .single.equals ((url: Uri .parse ('https://b/' ), mode: expectedModeAndroid ));
99
+ .single.equals ((url: Uri .parse ('https://b/' ), mode: LaunchMode .platformDefault ));
105
100
});
106
101
107
102
testWidgets ('link nested in other spans' , (tester) async {
108
103
await prepareContent (tester,
109
104
'<p><strong><em><a href="https://a/">word</a></em></strong></p>' );
110
105
await tester.tap (find.text ('word' ));
111
106
check (testBinding.takeLaunchUrlCalls ())
112
- .single.equals ((url: Uri .parse ('https://a/' ), mode: expectedModeAndroid ));
107
+ .single.equals ((url: Uri .parse ('https://a/' ), mode: LaunchMode .platformDefault ));
113
108
});
114
109
115
110
testWidgets ('link containing other spans' , (tester) async {
@@ -120,27 +115,27 @@ void main() {
120
115
121
116
await tester.tapAt (base .translate (1 * fontSize, 0 )); // "tXo words"
122
117
check (testBinding.takeLaunchUrlCalls ())
123
- .single.equals ((url: Uri .parse ('https://a/' ), mode: expectedModeAndroid ));
118
+ .single.equals ((url: Uri .parse ('https://a/' ), mode: LaunchMode .platformDefault ));
124
119
125
120
await tester.tapAt (base .translate (6 * fontSize, 0 )); // "two woXds"
126
121
check (testBinding.takeLaunchUrlCalls ())
127
- .single.equals ((url: Uri .parse ('https://a/' ), mode: expectedModeAndroid ));
122
+ .single.equals ((url: Uri .parse ('https://a/' ), mode: LaunchMode .platformDefault ));
128
123
});
129
124
130
125
testWidgets ('relative links are resolved' , (tester) async {
131
126
await prepareContent (tester,
132
127
'<p><a href="/a/b?c#d">word</a></p>' );
133
128
await tester.tap (find.text ('word' ));
134
129
check (testBinding.takeLaunchUrlCalls ())
135
- .single.equals ((url: Uri .parse ('${eg .realmUrl }a/b?c#d' ), mode: expectedModeAndroid ));
130
+ .single.equals ((url: Uri .parse ('${eg .realmUrl }a/b?c#d' ), mode: LaunchMode .platformDefault ));
136
131
});
137
132
138
133
testWidgets ('link inside HeadingNode' , (tester) async {
139
134
await prepareContent (tester,
140
135
'<h6><a href="https://a/">word</a></h6>' );
141
136
await tester.tap (find.text ('word' ));
142
137
check (testBinding.takeLaunchUrlCalls ())
143
- .single.equals ((url: Uri .parse ('https://a/' ), mode: expectedModeAndroid ));
138
+ .single.equals ((url: Uri .parse ('https://a/' ), mode: LaunchMode .platformDefault ));
144
139
});
145
140
146
141
testWidgets ('error dialog if invalid link' , (tester) async {
@@ -150,7 +145,7 @@ void main() {
150
145
await tester.tap (find.text ('word' ));
151
146
await tester.pump ();
152
147
check (testBinding.takeLaunchUrlCalls ())
153
- .single.equals ((url: Uri .parse ('file:///etc/bad' ), mode: expectedModeAndroid ));
148
+ .single.equals ((url: Uri .parse ('file:///etc/bad' ), mode: LaunchMode .platformDefault ));
154
149
checkErrorDialog (tester, expectedTitle: 'Unable to open link' );
155
150
});
156
151
});
0 commit comments