Skip to content

Commit fcc680b

Browse files
committed
boxes: Add class method in MessageBox to update content header.
This commit adds a method to update content header of a specific message box (if required). The current logic re-builds the whole message box if an update is required. This might need improvement as to update a specific element only. (Though that might prove useful only if that element is rendered via a dedicated class method). Tests added.
1 parent ce5b2d2 commit fcc680b

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

tests/ui/test_ui_tools.py

+43
Original file line numberDiff line numberDiff line change
@@ -2285,6 +2285,49 @@ def test_main_view_generates_EDITED_label(
22852285
assert label[0].text == "EDITED"
22862286
assert label[1][1] == 7
22872287

2288+
@pytest.mark.parametrize(
2289+
"message",
2290+
[
2291+
{
2292+
"id": 4,
2293+
"type": "stream",
2294+
"display_recipient": "Verona",
2295+
"stream_id": 5,
2296+
"subject": "Test topic",
2297+
"is_me_message": True,
2298+
"flags": [],
2299+
"content": "",
2300+
"reactions": [],
2301+
"sender_full_name": "Human 1",
2302+
"timestamp": 1532103879,
2303+
}
2304+
],
2305+
)
2306+
@pytest.mark.parametrize(
2307+
"to_vary_in_each_message, header_needed, update_required",
2308+
[
2309+
({"subject": "Test topic 2"}, True, True),
2310+
({}, False, False),
2311+
({"sender_full_name": "Human 2"}, False, True),
2312+
({"timestamp": 1532103869}, False, False),
2313+
],
2314+
ids=[
2315+
"recipient_header_present",
2316+
"recipient_header_not_present",
2317+
"content_header_present",
2318+
"content_header_not_present",
2319+
],
2320+
)
2321+
def test_update_msg_content_header(
2322+
self, msg_box, message, update_required, mocker, to_vary_in_each_message,
2323+
header_needed
2324+
):
2325+
last_msg = dict(message, **to_vary_in_each_message)
2326+
2327+
msg_box = MessageBox(message, self.model, last_msg)
2328+
2329+
assert msg_box.update_msg_content_header() == update_required
2330+
22882331
@pytest.mark.parametrize("key", keys_for_command("STREAM_MESSAGE"))
22892332
@pytest.mark.parametrize(
22902333
"narrow, expect_to_prefill",

zulipterminal/ui_tools/boxes.py

+20
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,26 @@ def main_view(self) -> List[Any]:
13611361
]
13621362
return [part for part, condition in parts if condition]
13631363

1364+
def update_msg_content_header(self) -> bool:
1365+
"""
1366+
Update the content header of a message box (if required).
1367+
"""
1368+
update_required = False
1369+
1370+
if self.need_recipient_header():
1371+
update_required = self[1][1].text != " "
1372+
1373+
# Content header is not None
1374+
elif isinstance(self[0][1], urwid.Text):
1375+
update_required = self[0][1].text != " "
1376+
1377+
if update_required:
1378+
# Re initialize the message if update is required.
1379+
# FIXME: Render specific element (here content header) instead?
1380+
super().__init__(self.main_view())
1381+
1382+
return update_required
1383+
13641384
@classmethod
13651385
def transform_content(
13661386
cls, content: Any, server_url: str

0 commit comments

Comments
 (0)