-
-
Notifications
You must be signed in to change notification settings - Fork 261
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
model: Improve reporting upon moving/splitting topic. #1178
model: Improve reporting upon moving/splitting topic. #1178
Conversation
4d493b5
to
a616169
Compare
a616169
to
a448fab
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.
@srdeotarse Thanks for looking at this, including giving the tests a go 👍
This doesn't appear to pass tests (CI), which is not what you have in the PR description.
Since the re-indexing occurs outside the current method where the message occurs, it's possible we may need to do that elsewhere.
zulipterminal/model.py
Outdated
if old_topic != new_topic: | ||
self.controller.report_success("You changed a message's topic.") | ||
self.controller.report_success( | ||
f"You changed {no_of_messages} message's topic from #{stream_name} > {old_topic} to #{stream_name} > {new_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.
I'm not sure if we have a standard way to do this using report_success
, but this may be clearer if we can provide a highlight style to group the stream+topic in each case.
This may require changes to existing code, so that could be a follow-up.
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.
After fixing the format for reporting message upon moving topics, we can look into highlighting as well.
a448fab
to
f16fbaf
Compare
f16fbaf
to
9d1610d
Compare
Rebased with current main branch and updated mypy. Still showing error below @neiljp -
|
4b5095e
to
94a3afe
Compare
@srdeotarse Was there a reason you closed/reopened this? Generally there's no need to do so. |
zulipterminal/model.py
Outdated
self.controller.report_success("You changed a message's topic.") | ||
if recent_moved_msgs == "one": | ||
self.controller.report_success( | ||
f"You changed {recent_moved_msgs} message's topic from #{stream_name} > {old_topic} to #{stream_name} > {new_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.
This is identical except for the apostrophe placement? If so, it'll be simpler to integrate the difference into the variable, and avoid the need for a conditional here.
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.
This was what I referred to by simplifying the code in the next review.
@@ -888,24 +907,54 @@ def test_update_private_message( | |||
"topic": "party", | |||
}, | |||
"lets_party", | |||
"party", | |||
"stream", | |||
"change_all", | |||
True, | |||
), | |||
], |
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.
Given the longer test here now, it would be useful to also add inline test ids.
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.
See my followup comment in the next 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.
OK, so you have the case
around each set of test parameters; for the ids see other tests which use a named parameter to case
(ie. pytest.param
), ie. id=some_description
).
You might try running this test as it is with -v
and using -k
to filter this test only, then see what happens when you add an id. What you see there is useful, in addition to it looking a little like a comment for that test parametrization.
@neiljp I was trying to rebase with main to solve mypy error for Optional[int] and accidentally deleted my local branch. |
94a3afe
to
5137a37
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.
@srdeotarse Thanks for the update 👍
Other than the comments inline, I think we could simplify the code for readability, though it is functional as it is :)
One aspect this brings up is the short time given until the message disappears in the footer. For a simple solution, we could tune this manually with an optional parameter to pass through, which might be warranted as a preparatory commit before the one you have.
I've thought previously we could try to handle this automatically based on word length and reading speed, with some minimum, but that may need more tuning than a simple prep commit.
tests/model/test_model.py
Outdated
@@ -834,78 +834,130 @@ def test_update_private_message( | |||
], | |||
) | |||
@pytest.mark.parametrize( | |||
"req, old_topic, footer_updated", | |||
"test_id, req, old_topic, new_topic, stream_name, propagate_mode, footer_updated", |
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.
Regarding test ids, I was referring to using pytest.param
, which we've been importing as case
. This makes description of each parametrized element easier.
5137a37
to
42863b0
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.
@srdeotarse I've mainly focused on the tests here, since once they're well-defined then refactoring the code to give the same behavior should be enforced - and good test-writing technique is a useful skill.
The first commit is good to have separate, but as per my inline comment I'd suggest you keep it very simple to simply allow passing a custom duration in the main commit, with a default of the current 3 as now. The version with a formula is worthy of it's own PR since the implementation is worthy of a separate discussion and this can be merged in the meantime.
@@ -888,24 +907,54 @@ def test_update_private_message( | |||
"topic": "party", | |||
}, | |||
"lets_party", | |||
"party", | |||
"stream", | |||
"change_all", | |||
True, | |||
), | |||
], |
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.
OK, so you have the case
around each set of test parameters; for the ids see other tests which use a named parameter to case
(ie. pytest.param
), ie. id=some_description
).
You might try running this test as it is with -v
and using -k
to filter this test only, then see what happens when you add an id. What you see there is useful, in addition to it looking a little like a comment for that test parametrization.
self.client.update_message.assert_called_once_with(req) | ||
assert result == return_value | ||
self.display_error_if_present.assert_called_once_with(response, self.controller) | ||
report_success = model.controller.report_success | ||
if result and footer_updated: | ||
report_success.assert_called_once_with("You changed a message's topic.") | ||
report_success.assert_called_once_with(expected_report_success) |
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 hope you can see how much cleaner this is 👍
The simpler test logic is, the fewer bugs can be in the tests themselves - other than also making them easier to read.
You didn't write this original test, but even so imagine that you looked for this test first, and changed it to specify new behavior first, then updated the code to make it pass (see TDD - test driven development - if you've not come across it). We're wanting to make a specification for the behavior, not write test code that parallels the behavior.
zulipterminal/core.py
Outdated
self.view.set_footer_text( | ||
text, "task:success", float(len(text.split()) * 6 / 13) | ||
) # Average reading speed = 130 wpm |
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'd like to see more discussion and explanation of this logic when we do implement this, and we should more broadly apply it to the other report_*
methods too. This appears to work for now, but here I'd prefer to go for simpler optional pass-through of a duration to this method for now, which we can iterate on later - ie. an additional named parameter with a default value.
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.
We're discussing this in the stream now 👍
42863b0
to
705c14b
Compare
This is useful to ensure there is enough time for long/complex text to be read before the footer resets.
11a63fe
to
a4a882c
Compare
a4a882c
to
7196234
Compare
This slipped out of being included in #1178. Test updated.
@srdeotarse Thanks for the contribution 👍 I made a few minor textual adjustments which you might be able to identify manually, or find using |
What does this PR do?
This PR improves reporting upon moving a message by editing it's topic.
Partial fix for #1172
Tested?
Commit flow
Notes & Questions
Interactions
Visual changes
model.py.-.zulip-terminal.WSL_.Ubuntu.-.Visual.Studio.Code.2022-03-23.21-44-36.mp4