-
Notifications
You must be signed in to change notification settings - Fork 214
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
Conversation
There was a problem hiding this 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.
lib/model/internal_link.dart
Outdated
// A generated URL without '/' looks odd and does not linkify. | ||
result = result.replace(path: '/'); | ||
} | ||
assert(result.path.startsWith('/')); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
test/model/compose_test.dart
Outdated
check(narrowLink(store, const CombinedFeedNarrow())) | ||
.equals(Uri.parse(expectedLink)); |
There was a problem hiding this comment.
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.)
Thanks for the review! I have updated the PR. |
Thanks, LGTM! Marking for Greg's review. |
There was a problem hiding this 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.
test/model/internal_link_test.dart
Outdated
@@ -184,6 +184,36 @@ void main() { | |||
testExpectedNarrows(testCases, streams: streams); | |||
}); | |||
|
|||
group('topic link parsing', () { |
There was a problem hiding this comment.
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).
test/model/internal_link_test.dart
Outdated
@@ -184,6 +184,36 @@ void main() { | |||
testExpectedNarrows(testCases, streams: streams); | |||
}); | |||
|
|||
group('topic link parsing', () { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
lib/model/internal_link.dart
Outdated
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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.
test/model/compose_test.dart
Outdated
@@ -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', () { |
There was a problem hiding this comment.
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.
test/model/compose_test.dart
Outdated
final account = eg.selfAccount.copyWith(realmUrl: Uri.parse(realmUrl)); | ||
final store = eg.store(account: account); |
There was a problem hiding this comment.
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:
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?
There was a problem hiding this comment.
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)));
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
test/model/compose_test.dart
Outdated
checkGeneratedLink( | ||
realmUrl: 'http://chat.example.com', | ||
expectedLink: 'http://chat.example.com/#narrow'); |
There was a problem hiding this comment.
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:
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
.
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.
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.
f3f3f1f
to
03c7c5a
Compare
Thanks for the commit and reviews! I have updated the PR. |
There was a problem hiding this 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/model/internal_link_test.dart
Outdated
|
||
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))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bump #1059 (comment)
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.
Thanks! Merging, after the subthread at #1059 (comment) . |
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.
Signed-off-by: Zixuan James Li <[email protected]>
Signed-off-by: Zixuan James Li <[email protected]>
Fixes: zulip#845 Signed-off-by: Zixuan James Li <[email protected]>
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.
Meanwhile, reorganized some test groups with the same name.
Supersedes: #874
Fixes: #845