Skip to content

content test: Aim taps on links more precisely at the text #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -664,26 +664,26 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: e45c31f458d01fd9ef4a214feb2e153b72d5b1907435f4332b1637a2f348c021
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
url: "https://pub.dev"
source: hosted
version: "9.0.18"
version: "10.0.0"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "54808cfcfa87dbc0d74c61ac063d624adf1bd5c0407301f32b06c783c60dc4ca"
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "2.0.1"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "7e71be3c161472f6c9158ac8875dd8de575060d60b5d159ebca3600ea32c9116"
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
url: "https://pub.dev"
source: hosted
version: "1.0.6"
version: "2.0.1"
lints:
dependency: transitive
description:
Expand Down Expand Up @@ -1290,5 +1290,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.3.0-244.0.dev <4.0.0"
flutter: ">=3.18.0-18.0.pre.10"
dart: ">=3.3.0-276.0.dev <4.0.0"
flutter: ">=3.18.0-18.0.pre.98"
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ environment:
# that by the time we want to release, these will have become stable.
# TODO: Before general release, switch to stable Flutter and Dart versions,
# or pin exact versions: https://github.com/zulip/zulip-flutter/issues/15
sdk: '>=3.3.0-244.0.dev <4.0.0'
flutter: '>=3.18.0-18.0.pre.10'
sdk: '>=3.3.0-276.0.dev <4.0.0'
flutter: '>=3.18.0-18.0.pre.98'

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
Expand Down
21 changes: 14 additions & 7 deletions test/widgets/content_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ void main() {
});
});

Future<void> tapText(WidgetTester tester, Finder textFinder) async {
final height = tester.getSize(textFinder).height;
final target = tester.getTopLeft(textFinder)
.translate(height/4, height/2); // aim for middle of first letter
await tester.tapAt(target);
}

group('LinkNode interactions', () {
// The Flutter test font uses square glyphs, so width equals height:
// https://github.com/flutter/flutter/wiki/Flutter-Test-Fonts
Expand All @@ -85,7 +92,7 @@ void main() {
await prepareContent(tester,
'<p><a href="https://example/">hello</a></p>');

await tester.tap(find.text('hello'));
await tapText(tester, find.text('hello'));
check(testBinding.takeLaunchUrlCalls())
.single.equals((url: Uri.parse('https://example/'), mode: LaunchMode.platformDefault));
}, variant: const TargetPlatformVariant({TargetPlatform.android, TargetPlatform.iOS}));
Expand All @@ -111,7 +118,7 @@ void main() {
testWidgets('link nested in other spans', (tester) async {
await prepareContent(tester,
'<p><strong><em><a href="https://a/">word</a></em></strong></p>');
await tester.tap(find.text('word'));
await tapText(tester, find.text('word'));
check(testBinding.takeLaunchUrlCalls())
.single.equals((url: Uri.parse('https://a/'), mode: LaunchMode.platformDefault));
});
Expand All @@ -134,15 +141,15 @@ void main() {
testWidgets('relative links are resolved', (tester) async {
await prepareContent(tester,
'<p><a href="/a/b?c#d">word</a></p>');
await tester.tap(find.text('word'));
await tapText(tester, find.text('word'));
check(testBinding.takeLaunchUrlCalls())
.single.equals((url: Uri.parse('${eg.realmUrl}a/b?c#d'), mode: LaunchMode.platformDefault));
});

testWidgets('link inside HeadingNode', (tester) async {
await prepareContent(tester,
'<h6><a href="https://a/">word</a></h6>');
await tester.tap(find.text('word'));
await tapText(tester, find.text('word'));
check(testBinding.takeLaunchUrlCalls())
.single.equals((url: Uri.parse('https://a/'), mode: LaunchMode.platformDefault));
});
Expand All @@ -151,7 +158,7 @@ void main() {
await prepareContent(tester,
'<p><a href="file:///etc/bad">word</a></p>');
testBinding.launchUrlResult = false;
await tester.tap(find.text('word'));
await tapText(tester, find.text('word'));
await tester.pump();
check(testBinding.takeLaunchUrlCalls())
.single.equals((url: Uri.parse('file:///etc/bad'), mode: LaunchMode.platformDefault));
Expand Down Expand Up @@ -187,7 +194,7 @@ void main() {
final pushedRoutes = await prepareContent(tester,
html: '<p><a href="/#narrow/stream/1-check">stream</a></p>');

await tester.tap(find.text('stream'));
await tapText(tester, find.text('stream'));
check(testBinding.takeLaunchUrlCalls()).isEmpty();
check(pushedRoutes).single.isA<WidgetRoute>()
.page.isA<MessageListPage>().narrow.equals(const StreamNarrow(1));
Expand All @@ -198,7 +205,7 @@ void main() {
final pushedRoutes = await prepareContent(tester,
html: '<p><a href="/#narrow/stream/1-check/topic">invalid</a></p>');

await tester.tap(find.text('invalid'));
await tapText(tester, find.text('invalid'));
final expectedUrl = eg.realmUrl.resolve('/#narrow/stream/1-check/topic');
check(testBinding.takeLaunchUrlCalls())
.single.equals((url: expectedUrl, mode: LaunchMode.platformDefault));
Expand Down