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

internal_link: Always include a "/" after hostname #1059

Merged
merged 4 commits into from
Dec 11, 2024
Merged

Conversation

PIG208
Copy link
Member

@PIG208 PIG208 commented Nov 13, 2024

Meanwhile, reorganized some test groups with the same name.

Supersedes: #874
Fixes: #845

@PIG208 PIG208 requested a review from chrisbobbe November 13, 2024 19:51
@PIG208 PIG208 added the maintainer review PR ready for review by Zulip maintainers label Nov 18, 2024
Copy link
Collaborator

@chrisbobbe chrisbobbe left a comment

Choose a reason for hiding this comment

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

Thanks! Small comments below.

// A generated URL without '/' looks odd and does not linkify.
result = result.replace(path: '/');
}
assert(result.path.startsWith('/'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can leave out the assert; it's redundant with tests and doesn't open opportunities to simplify code below it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense. This feels like a duplication of the assertion made in the comments above.

Comment on lines 322 to 323
check(narrowLink(store, const CombinedFeedNarrow()))
.equals(Uri.parse(expectedLink));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm slightly inclined to stringify the narrowLink result and compare that to the String expectedLink. The user's experience of a narrowLink result is always through Uri.toString. (Quote-and-reply and copy-link-to-message.)

@PIG208
Copy link
Member Author

PIG208 commented Nov 22, 2024

Thanks for the review! I have updated the PR.

@chrisbobbe
Copy link
Collaborator

Thanks, LGTM! Marking for Greg's review.

@chrisbobbe chrisbobbe added integration review Added by maintainers when PR may be ready for integration and removed maintainer review PR ready for review by Zulip maintainers labels Nov 25, 2024
@chrisbobbe chrisbobbe requested a review from gnprice November 25, 2024 21:12
@chrisbobbe chrisbobbe assigned gnprice and unassigned chrisbobbe Nov 25, 2024
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 @PIG208, and thanks @chrisbobbe for the previous review! Comments below.

@@ -184,6 +184,36 @@ void main() {
testExpectedNarrows(testCases, streams: streams);
});

group('topic link parsing', () {
Copy link
Member

Choose a reason for hiding this comment

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

nit:

internal_link test [nfc]: Merge tests with the same name

s/tests/groups/ — this commit doesn't merge any tests (and it doesn't look like we had any tests with the same name).

@@ -184,6 +184,36 @@ void main() {
testExpectedNarrows(testCases, streams: streams);
});

group('topic link parsing', () {
Copy link
Member

Choose a reason for hiding this comment

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

Moving these tests up here splits some related tests from each other: the tests above and below this moved group all use the same streams local and have the same structure. So best to keep those together by leaving these below them.

Copy link
Member

Choose a reason for hiding this comment

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

Or in fact let's just leave these where they are entirely — it looks like you don't end up making any changes to this test file in the main commit, so it doesn't seem like in this PR we're making use of any energy we spend loading these tests into our heads enough to refactor them.

Copy link
Member

Choose a reason for hiding this comment

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

… I guess that last remark is made moot by my other comment that the new tests should go in this file.

I'll push a revision with a new commit that fixes these group-name collisions more minimally. We're still not in this PR doing anything with these tests of parseInternalLink — the code being modified isn't parseInternalLink, but rather narrowLink which is roughly its inverse — so we don't need to think too hard about these tests at the moment.

Uri result = store.realmUrl.replace(fragment: fragment.toString());
if (result.path.isEmpty) {
// Always ensure that there is a '/' right after the hostname.
// A generated URL without '/' looks odd and does not linkify.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// A generated URL without '/' looks odd and does not linkify.
// A generated URL without '/' looks odd,
// and if used in a Zulip message does not get automatically linkified.

The not getting linkified is a specific fact about what Zulip does with URLs it spots in the plain text of a message; it's not a general fact about URLs, and this function isn't specific to generating something to go into a Zulip message.

@@ -314,6 +314,28 @@ hello
'#narrow/dm/1,2-dm/near/12345',
'#narrow/pm-with/1,2-pm/near/12345');
});

test('normalize links to always include a "/" after hostname', () {
Copy link
Member

Choose a reason for hiding this comment

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

The code this is testing is in internal_link.dart, not compose.dart, so let's place the test to match. We can do that with a prep commit moving this narrowLink test group to the top of internal_link_test.dart; really that should have happened as part of 2f944a0.

Comment on lines 320 to 321
final account = eg.selfAccount.copyWith(realmUrl: Uri.parse(realmUrl));
final store = eg.store(account: account);
Copy link
Member

Choose a reason for hiding this comment

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

nit: just make a fresh Account from scratch:

Suggested change
final account = eg.selfAccount.copyWith(realmUrl: Uri.parse(realmUrl));
final store = eg.store(account: account);
final store = eg.store(account: eg.account(realmUrl: Uri.parse(realmUrl)));

Or is there a reason that doesn't work?

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be:

      final store = eg.store(account: eg.account(user: eg.selfUser, realmUrl: Uri.parse(realmUrl)));

which is fine and actually as short as the other way:

      final store = eg.store(account: eg.selfAccount.copyWith(realmUrl: Uri.parse(realmUrl)));

Copy link
Member

Choose a reason for hiding this comment

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

... Oh, I didn't see this reply when writing #1059 (comment) . I think I got got by the GitHub bug where a PR page often/usually live-updates with new comments, but then often doesn't, so I was looking at the page (in an existing tab) and didn't see any reply.

Anyway, if it needs that extra detail, no need to change it. And from your revision I see there's an existing test there that sets this up the same way.

Copy link
Member Author

@PIG208 PIG208 Dec 11, 2024

Choose a reason for hiding this comment

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

I guess the non-copy-with implementation would be a tiny bit more realistic because we supposedly (there is a TODO on eg.account) will regenerate a bunch of fields from scratch as well.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm true. Not a bunch, I don't think; but the account ID, and maybe the API key too. Sure.

Comment on lines 326 to 328
checkGeneratedLink(
realmUrl: 'http://chat.example.com',
expectedLink: 'http://chat.example.com/#narrow');
Copy link
Member

Choose a reason for hiding this comment

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

nit: always best to make the code transparent about what it's doing, when that doesn't come at a high cost in concision:

Suggested change
checkGeneratedLink(
realmUrl: 'http://chat.example.com',
expectedLink: 'http://chat.example.com/#narrow');
check(generatedLink('http://chat.example.com'))
.equals( 'http://chat.example.com/#narrow');

(And here it actually improves concision, too).

Then further can rename generatedLink to something a bit more specific, like narrowLinkFor.

gnprice added a commit to PIG208/zulip-flutter that referenced this pull request Dec 3, 2024
The organization of this code's test cases is a bit scattered;
partly because they were ported from tests written for the
legacy zulip-mobile RN app, which themselves accumulated in layers
over time.  (After all, one doesn't want to drop one of these tests
in a refactoring unless taking the time to be sure its substance is
covered by a surviving test.)

It's potentially confusing having several groups with the same name,
though.  Fix that by picking different names for all but one of them.

The name collision was originally noted by Zixuan in zulip#1059.
PIG208 pushed a commit to PIG208/zulip-flutter that referenced this pull request Dec 11, 2024
The organization of this code's test cases is a bit scattered;
partly because they were ported from tests written for the
legacy zulip-mobile RN app, which themselves accumulated in layers
over time.  (After all, one doesn't want to drop one of these tests
in a refactoring unless taking the time to be sure its substance is
covered by a surviving test.)

It's potentially confusing having several groups with the same name,
though.  Fix that by picking different names for all but one of them.

The name collision was originally noted by Zixuan in zulip#1059.
@PIG208 PIG208 force-pushed the pr-links branch 2 times, most recently from f3f3f1f to 03c7c5a Compare December 11, 2024 19:39
@PIG208
Copy link
Member Author

PIG208 commented Dec 11, 2024

Thanks for the commit and reviews! I have updated the PR.

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 for the revision! Just one surviving comment.

Oh and in a commit message:

5a1caac internal_link test [nfc]: Give test groups distinct names
5acef65 internal_link test [nfc]: Re-home narrow link tests
1ff2621 internal_links: Always include a "/" after hostname

There's no identifier internal_links, so that identifier-styled term shouldn't appear in text when there isn't an identifier it refers to.


test('normalize links to always include a "/" after hostname', () {
String narrowLinkFor({required String realmUrl}) {
final store = eg.store(account: eg.selfAccount.copyWith(realmUrl: Uri.parse(realmUrl)));
Copy link
Member

Choose a reason for hiding this comment

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

PIG208 pushed a commit to PIG208/zulip-flutter that referenced this pull request Dec 11, 2024
The organization of this code's test cases is a bit scattered;
partly because they were ported from tests written for the
legacy zulip-mobile RN app, which themselves accumulated in layers
over time.  (After all, one doesn't want to drop one of these tests
in a refactoring unless taking the time to be sure its substance is
covered by a surviving test.)

It's potentially confusing having several groups with the same name,
though.  Fix that by picking different names for all but one of them.

The name collision was originally noted by Zixuan in zulip#1059.
@PIG208 PIG208 requested a review from gnprice December 11, 2024 23:01
@gnprice
Copy link
Member

gnprice commented Dec 11, 2024

Thanks! Merging, after the subthread at #1059 (comment) .

gnprice and others added 4 commits December 11, 2024 15:23
The organization of this code's test cases is a bit scattered;
partly because they were ported from tests written for the
legacy zulip-mobile RN app, which themselves accumulated in layers
over time.  (After all, one doesn't want to drop one of these tests
in a refactoring unless taking the time to be sure its substance is
covered by a surviving test.)

It's potentially confusing having several groups with the same name,
though.  Fix that by picking different names for all but one of them.

The name collision was originally noted by Zixuan in zulip#1059.
@gnprice gnprice merged commit fd91f72 into zulip:main Dec 11, 2024
@PIG208 PIG208 deleted the pr-links branch December 11, 2024 23:27
shivanshsharma13 pushed a commit to shivanshsharma13/zulip-flutter that referenced this pull request Dec 13, 2024
The organization of this code's test cases is a bit scattered;
partly because they were ported from tests written for the
legacy zulip-mobile RN app, which themselves accumulated in layers
over time.  (After all, one doesn't want to drop one of these tests
in a refactoring unless taking the time to be sure its substance is
covered by a surviving test.)

It's potentially confusing having several groups with the same name,
though.  Fix that by picking different names for all but one of them.

The name collision was originally noted by Zixuan in zulip#1059.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration review Added by maintainers when PR may be ready for integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include / after hostname in generated links
3 participants