Skip to content

Commit

Permalink
messages: Add tests for transform_content.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rsashank committed May 31, 2024
1 parent d65cbee commit 9d51e8e
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions tests/ui_tools/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,96 @@ def test_transform_content(self, mocker, raw_html, expected_content):
rendered_text = Text(content)
assert rendered_text.text == expected_content

@pytest.mark.parametrize(
"raw_html, expected_message_links",
[
(
"""
<p><a href="https://github.com/zulip/zulip-terminal/pull/1">https://github.com/zulip/zulip-terminal/pull/1</a></p>
""",
{
"https://github.com/zulip/zulip-terminal/pull/1": (
"github.com",
1,
True,
)
},
),
(
"""
<p><a href="https://foo.com">https://foo.com</a></p>
""",
{"https://foo.com": ("https://foo.com", 1, False)},
),
(
"""
<p><a href="#narrow/stream/206-zulip-terminal/topic/announce">https://chat.zulip.zulip/#narrow/stream/206-zulip-terminal/topic/announce</a></p>
""",
{
"https://chat.zulip.zulip#narrow/stream/206-zulip-terminal/topic/announce": ( # noqa: E501
"https://chat.zulip.zulip/#narrow/stream/206-zulip-terminal/topic/announce",
1,
True,
)
},
),
],
)
def test_transform_content_message_links(
self, mocker, raw_html, expected_message_links
) -> None:
_, message_links, *_ = MessageBox.transform_content(raw_html, SERVER_URL)

assert message_links == expected_message_links

@pytest.mark.parametrize(
"raw_html, expected_time_mentions",
[
(
"""
<p><time datetime="2024-05-29T11:30:00Z">2024-05-29T17:00:00+05:30</time></p>
""", # noqa: E501
[
(
"Wed, May 29 2024, 17:00 (IST)",
"Original text was 2024-05-29T17:00:00+05:30",
)
],
),
(
"""
<p><time datetime="3000-06-01T14:00:00Z">3000-06-01T19:30:00+05:30</time></p>
""", # noqa: E501
[
(
"Sun, Jun 1 3000, 19:30 (IST)",
"Original text was 3000-06-01T19:30:00+05:30",
)
],
),
(
"""
<p><time datetime="1947-08-14T19:47:00Z">1947-08-15T01:17:00+05:30</time></p>
""", # noqa: E501
[
(
"Fri, Aug 15 1947, 1:17 (IST)",
"Original text was 1947-08-15T01:17:00+05:30",
)
],
),
],
)
def test_transform_content_time_mentions(
self, mocker, raw_html, expected_time_mentions
) -> None:
mocker.patch(
MODULE + ".get_localzone", return_value=pytz.timezone("Asia/Kolkata")
)
_, _, time_mentions, *_ = MessageBox.transform_content(raw_html, SERVER_URL)

assert time_mentions == expected_time_mentions

# FIXME This is the same parametrize as MsgInfoView:test_height_reactions
@pytest.mark.parametrize(
"to_vary_in_each_message, expected_text, expected_attributes",
Expand Down

0 comments on commit 9d51e8e

Please sign in to comment.