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

messages: Add tests for transform_content. #1507

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rsashank
Copy link
Member

What does this PR do, and why?

This update PR tests for the transform_content class method for self.message_links and self.time_mentions. The addition of these tests addresses feedback from issue #1455, which pointed out the lack of tests for these aspects.

@neiljp said:

It'd be good to see some tests for what ends up in self.code_snippets, though we don't seem to have tests for the others.

External discussion & connections

  • Discussed in #zulip-terminal in topic
  • Fully fixes #
  • Partially fixes issue #
  • Builds upon previous unmerged work in PR #
  • Is a follow-up to work in PR #
  • Requires merge of PR #
  • Merge will enable work on #

How did you test this?

  • Manually - Behavioral changes
  • Manually - Visual changes
  • Adapting existing automated tests
  • Adding automated tests for new behavior (or missing tests)
  • Existing automated tests should already cover this (only a refactor of tested code)

Self-review checklist for each commit

  • It is a minimal coherent idea
  • It has a commit summary following the documented style (title & body)
  • It has a commit summary describing the motivation and reasoning for the change
  • It individually passes linting and tests
  • [] It contains test additions for any new behavior
  • It flows clearly from a previous branch commit, and/or prepares for the next commit

@zulipbot zulipbot added the size: L [Automatic label added by zulipbot] label May 29, 2024
Copy link
Collaborator

@Niloth-p Niloth-p left a comment

Choose a reason for hiding this comment

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

Same as the other PR,

  • type annotations
  • test ids

Nice work with the noqa exceptions 😉

Nicely done!
I haven't looked into the scope and history behind this PR yet.
But the implementation lgtm.

tests/ui_tools/test_messages.py Show resolved Hide resolved
[
(
"""
<p><a href="https://github.com/zulip/zulip-terminal/pull/1">https://github.com/zulip/zulip-terminal/pull/1</a></p>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we have some link where the text is not the same as the link?
One of the first two?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done :)

tests/ui_tools/test_messages.py Outdated Show resolved Hide resolved
@zulipbot zulipbot added size: XL [Automatic label added by zulipbot] and removed size: L [Automatic label added by zulipbot] labels May 31, 2024
@rsashank
Copy link
Member Author

Thanks for helping out with the noqa exceptions and for the detailed review! :) @Niloth-p

Copy link
Collaborator

@mounilKshah mounilKshah 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 working on this @rsashank
The test cases considered for each of the functions seem appropriate and enough for testing the respective aspects of the transform_content function.

@@ -1585,14 +1587,120 @@ def test_keypress_EDIT_MESSAGE(
# fmt: on
],
)
def test_transform_content(self, mocker, raw_html, expected_content):
def test_transform_content(self, raw_html: str, expected_content: Any) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure if there's a need for this change as we don't usually define data type for the function arguments or the function return variable as we decide what to pass.
You may not keep them in the newly created test function as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This file is not currently type-checked, though it would be good to do so (there's an issue for it). Adding these right now are more like comments, which is fine but won't be tested or maintained, which is the downside - though if they keep passing manual review then they should help when we do apply mypy to these files.

Given the introduction of the similar transform_content tests, it would make sense to rename this test to define what set of cases it handles, so I'd consider it reasonable to update nearby lines like the types.

@mounilKshah mounilKshah added PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback and removed PR needs mentor review labels Jun 16, 2024
@rsashank rsashank removed the PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback label Jun 26, 2024
Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

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

@rsashank This looks like an improvement to me 👍

In addition to my points inline, I'd consider the case of no links/mentions, and multiple ones.

Did you see an improvement in numeric coverage compared to this rebased against main?

Historically we tested transform_content separately since it became a wrapper around soup2markup for quotes. These tests could be considered more complex tests for soup2markup, but transform_content seems fine too - the current soup2markup test is a simple rendering test only. One readability confusion in that regard is that all these tests are not near the soup2markup test (L676).

This PR has an interesting connection to the muted user work; there I mentioned that we likely need to parse the message to get these fields in any case, which could suggest we do the transform completely separately (earlier) than the header calculation. We currently remake the entire messagebox, I recall, but storing the content earlier may make updating only the content/author easier for muting/unmuting events.

@@ -1585,14 +1587,120 @@ def test_keypress_EDIT_MESSAGE(
# fmt: on
],
)
def test_transform_content(self, mocker, raw_html, expected_content):
def test_transform_content(self, raw_html: str, expected_content: Any) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file is not currently type-checked, though it would be good to do so (there's an issue for it). Adding these right now are more like comments, which is fine but won't be tested or maintained, which is the downside - though if they keep passing manual review then they should help when we do apply mypy to these files.

Given the introduction of the similar transform_content tests, it would make sense to rename this test to define what set of cases it handles, so I'd consider it reasonable to update nearby lines like the types.

Comment on lines 1638 to 1643
ids=[
"github_pr",
"external_link_no_footlink",
"internal_link",
"github_link_with_text",
],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's have these ids inline.

Also the first is a github_pr (link) but it'd be useful to clarify what form it takes, ie. the link matches the text in that first case.

Copy link
Member Author

Choose a reason for hiding this comment

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

github_pr_link_matches_text?

),
(
"""
<p><a href="#narrow/stream/206-zulip-terminal/topic/announce">https://chat.zulip.zulip/#narrow/stream/206-zulip-terminal/topic/announce</a></p>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are these test cases all from real example messages, to indicate this is what we actually receive?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I printed in debug mode and got them.

],
),
],
ids=["test_date", "distant_future_date", "past_date"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd suggest inlining these too.

@neiljp neiljp added PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback and removed PR needs review PR requires feedback to proceed labels Sep 23, 2024
@rsashank rsashank force-pushed the transform_content branch 2 times, most recently from 4d8ae77 to 9b09c07 Compare September 29, 2024 17:56
This commit introduces tests for the `transform_content` class method,
specifically focusing on the `message_links` and `time_mentions`.

These enhancements improve the reliability and testing coverage of the
`transform_content` method.
@rsashank rsashank added PR needs review PR requires feedback to proceed and removed PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback labels Sep 30, 2024
@rsashank
Copy link
Member Author

Updated this PR @neiljp! Thanks for the feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: tests PR needs review PR requires feedback to proceed size: XL [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants