-
Notifications
You must be signed in to change notification settings - Fork 164
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: Recognize channel operator in narrow links #704
internal_link: Recognize channel operator in narrow links #704
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.
I feel like we don't need all those tests duplicated just to test that channel and stream can be used interchangeably! But I'm not sure. how could it be handled otherwise?
Thanks @Khader-1! Let's use the "buddy review" system here, now that the start of the official GSoC period is imminent. That means:
|
66efd39
to
6a49c8c
Compare
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!
Looks great, just some comments related to style nits.
test/model/internal_link_test.dart
Outdated
@@ -130,13 +130,16 @@ void main() { | |||
final bool expected = testCase.$1; | |||
final String description = testCase.$2; | |||
final String urlString = testCase.$3; | |||
final String urlWithChannelSyntax = urlString.replaceFirst('#narrow/stream/', '#narrow/channel/'); |
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: Feels like this can go unnoticed when skimming through tests, instead I'd just add those extra cases in the testCases
list.
test/model/internal_link_test.dart
Outdated
@@ -195,6 +219,8 @@ void main() { | |||
final testCases = [ | |||
('/#narrow/stream/name/topic/', null), // missing operand | |||
('/#narrow/stream/name/unknown/operand/', null), // unknown operator | |||
('/#narrow/channel/name/topic/', null), // missing operand |
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:
I'd prefer a newline here to better segregate stream
vs channel
.
test/model/internal_link_test.dart
Outdated
}); | ||
|
||
group('on stream link with wrong name, ID wins', () { | ||
testExpectedStreamNarrow('#narrow/stream/1-nonsense', 1); | ||
testExpectedStreamNarrow('#narrow/stream/1-', 1); | ||
testExpectedStreamNarrow('#narrow/channel/1-nonsense', 1); |
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: newline, here and other similar cases below
test/model/internal_link_test.dart
Outdated
} | ||
final testCases = [ | ||
(mkUrlString('(no.20topic)'), TopicNarrow(stream.streamId, '(no topic)')), | ||
(mkUrlString('lunch'), TopicNarrow(stream.streamId, 'lunch')), | ||
(mkUrlString('(no.20topic)', 'stream'), TopicNarrow(stream.streamId, '(no topic)')), |
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: Add whitespace to preserve formatting, here and similar cases below
(mkUrlString('(no.20topic)', 'stream'), TopicNarrow(stream.streamId, '(no topic)')),
(mkUrlString('lunch', 'stream'), TopicNarrow(stream.streamId, 'lunch')),
(mkUrlString('(no.20topic)', 'channel'), TopicNarrow(stream.streamId, '(no topic)')),
(mkUrlString('lunch', 'channel'), TopicNarrow(stream.streamId, 'lunch')),
Good question. I agree it'd be best not to duplicate most of these — after this changeover, we'd like to mostly stop thinking about the old forms, and have our code all focused on the "channel" forms. (Though not entirely stop thinking about the old forms, because it's important they continue to work.) I think a good strategy would be to augment The main commit could have the tests transform "stream" to "channel", so that the change to the test file is small and easy to review. Then a followup commit, within the PR, can sweep through all the test URLs and make them say "/channel/" instead of "/stream/", and flip the transform around. |
6a49c8c
to
b1a421e
Compare
Thanks for the review @rajveermalviya! and Thanks for the reply @gnprice! How about this, keeping in mind that I'm already working on #631. We can take this approach:
I've already pushed a revision with the first two steps, please take a look. |
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! Apart from one comment, it looks great :)
Now over to @kenclary for mentor review.
test/model/internal_link_test.dart
Outdated
// This is here to avoid duplicating each test case that contains `#narrow/stream` or `#narrow/channel` | ||
final urlWithChannelSyntax = urlString.replaceFirst('#narrow/stream', '#narrow/channel'); | ||
final urlWithStreamSyntax = urlString.replaceFirst('#narrow/channel', '#narrow/stream'); | ||
for (final urlString in {urlWithStreamSyntax, urlWithChannelSyntax}) { |
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.
for (final urlString in {urlWithStreamSyntax, urlWithChannelSyntax}) { | |
for (final urlString in [urlWithStreamSyntax, urlWithChannelSyntax]) { |
{'hello'}
creates a Set<String>
, if that's unintentional use [
]
instead, which creates List<String>
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.
No it is actually intentional. Specifically, when the url being tested does not contain #narrow/stream
nor #narrow/channel
then both urlWithStreamSyntax
, urlWithChannelSyntax
would be the same and using the list would cause unnecessary duplications.
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.
that sounds correct. it's obscure, though. can it get a comment explaining how the object is better than an array?
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.
Sure, a new revision is there now.
b1a421e
to
a55dedc
Compare
Sure, it's OK if the followup commit I mentioned at the end of #704 (comment) happens in a later PR as part of #631, instead of this PR. I liked what the previous revision was doing to deduplicate the test cases that come from the big list of tuples, though, too. So what I had in mind was to deduplicate callers of For explicitly duplicated test cases, I really do mean just a handful — for example one boring StreamNarrow and one boring TopicNarrow, plus a TopicNarrow with |
a55dedc
to
0728a6f
Compare
Thanks @gnprice! Please check the new revision |
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! One small comment below.
final urlWithChannelSyntax = urlString.replaceFirst('#narrow/stream', '#narrow/channel'); | ||
final urlWithStreamSyntax = urlString.replaceFirst('#narrow/channel', '#narrow/stream'); |
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.
Let's relax this so it handles the stream
/channel
operator even if it's at some position other than the first. It's usually the first, but it doesn't have to be. For example, this is a valid narrow link that the web app knows how to handle: https://chat.zulip.org/#narrow/is/unread/stream/14-GSoC
I think this could be done like this:
- in
urlString
, skip past the#narrow/
at the beginning - split the rest by '/'
- in that list of segments, look at the even-indexed ones (i.e.,
index % 2 == 0
) - for each of those that's equal to "stream", replace it with "channel" and vice versa
(We wouldn't want to just replace all occurrences of "stream" or "channel" in the URL; we want to avoid doing things like changing a topic operand that happens to have one of those strings in 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.
It's true those are valid links, but it looks like we don't currently have any examples of them in this test file.
(Likely we should! Our implementation looks like it accepts them. But we don't right now. These tests were basically ported from zulip-mobile, because the tests there for this area were quite thorough, but that implementation doesn't accept those links.)
So for this PR, I'm happy to keep it simple in this respect.
Adding that logic would be a good followup, along with adding some test cases where /channel/ comes after /topic/, and where things come in other surprising orders.
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.
Cool, thanks for that suggestion, Greg. Since this was my only comment, I'll mark this for integration review. 🙂
Marking for Greg's review following #704 (comment) ; @Khader-1 please take a look at that comment about a followup. 🙂 |
Thanks @Khader-1, and thanks @rajveermalviya and everyone for the reviews! This looks good — merging. (See comment above about a useful followup.) |
0728a6f
to
50eba89
Compare
Fixes: #632