Skip to content
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

Integrate internal links in message contents #318

Merged
merged 1 commit into from
Oct 18, 2023

Conversation

sirpengi
Copy link
Contributor

This PR is built on top of #305

Intercepts link navigation to run through parseInternalLink (from #305) and redirects internal links to their respected narrows.

Fixes: #73

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sirpengi! Comments below, all on the tests. (And only on the last commit, since the rest is discussed at #305.)

Comment on lines 181 to 185
final connection = store.connection as FakeApiConnection;
connection.prepare(json: newestResult(
foundOldest: true,
messages: [],
).toJson());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the function of this part? It doesn't seem to be needed in the otherwise similar prepareContent in the previous group.

final testNavObserver = TestNavigatorObserver()
..onPushed = (route, prevRoute) => pushedRoutes.add(route);
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot(
streams: [eg.stream(streamId: 1, name: 'check')],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the function of this line? Seems like the tests pass without it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Along with this and the previous comment I've pared down the setup. The connection.prepare wasn't necessary at all, but I think I arrived at this incrementally by adding things until the tests stopped complaining about things unrelated to the test I was writing. After further digging and consulting the other tests I've also found out the reason for the double await tester.pump() (the first is for the global store and second is for the pre-account store?) and I think this understanding will help me arrive at better test scaffolding (as well as understanding the existing tests)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this line in particular for now, but started a discussion here: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/possibly.20extreneous.20test.20scaffolding

@@ -158,6 +166,78 @@ void main() {
});
});

group('Internal links', () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other groups in this test file are named for the corresponding classes for the pieces of content they test. This should follow that, to help keep the file organized.

E.g. it could be "LinkNode on internal links", if it's not combined into the existing "LinkNode interactions".

@@ -158,6 +166,78 @@ void main() {
});
});

group('Internal links', () {
Future<List<Route<dynamic>>> prepareContentWithNavigator(WidgetTester tester, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function name contrasts with others in the file by saying "with navigator". But it doesn't create any more of a navigator than those other functions called prepareContent — they each mount a MaterialApp widget, and that creates a Navigator, exactly like what happens in this function. So the name is misleading.

One thing this function does do is add a navigator observer. But that's a kind of observer, not a kind of navigator.

I think just prepareContent suffices as a name. The function is a local helper for this test group; so it prepares some content, and the specific set of bells and whistles involved in doing so is just whatever set this test group needs.

Comment on lines 196 to 209
testWidgets('internal links are resolved: StreamNarrow', (tester) async {
final pushedRoutes = await prepareContentWithNavigator(tester,
html: '<p><a href="/#narrow/stream/1-check">stream</a></p>');

await tester.tap(find.text('stream'));
check(testBinding.takeLaunchUrlCalls()).isEmpty();
check(pushedRoutes).single.isA<WidgetRoute>()
.page.isA<MessageListPage>()
.narrow.equals(const StreamNarrow(1));
});

testWidgets('internal links are resolved: TopicNarrow', (tester) async {
final pushedRoutes = await prepareContentWithNavigator(tester,
html: '<p><a href="/#narrow/stream/1-check/topic/my.20topic">topic</a></p>');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having several versions like this for different types of narrow is OK, but FYI I'd say they're of low value — we already have extensive tests of the parsing that leads to the different types of narrow, over in test/model/internal_link_test.dart (from #305). The key things to test here are (a) some internal link, and (b) some link that resembles an internal link but is invalid, because those are the cases that this code-under-test knows the difference between.

@sirpengi sirpengi force-pushed the pr-integrate-internal-links branch 2 times, most recently from c5b0509 to 1bb4c50 Compare October 13, 2023 09:48
@sirpengi
Copy link
Contributor Author

Pushed up changes based on comments but awaiting discussion on #318 (comment)

@sirpengi sirpengi force-pushed the pr-integrate-internal-links branch from 1bb4c50 to 876e60f Compare October 13, 2023 17:59
@sirpengi
Copy link
Contributor Author

I believe all comments were handled now and the discussion resolved, but I will re-review this PR and ping when ready.

@sirpengi sirpengi force-pushed the pr-integrate-internal-links branch from 876e60f to a53a4f3 Compare October 16, 2023 08:08
Integrates [parseInternalLink] into content link nodes
so that recognized narrows are navigated to within the app,
rather than opened in a browser.

Fixes: zulip#73
@sirpengi sirpengi force-pushed the pr-integrate-internal-links branch from a53a4f3 to 0847f10 Compare October 16, 2023 08:23
@sirpengi
Copy link
Contributor Author

@gnprice Okay, ready for a review again!

@gnprice
Copy link
Member

gnprice commented Oct 18, 2023

Thanks @sirpengi for the revision! All looks good — merging.

@gnprice gnprice merged commit 0847f10 into zulip:main Oct 18, 2023
1 check passed
@sirpengi sirpengi deleted the pr-integrate-internal-links branch January 23, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle Zulip-internal links by navigation
2 participants