Skip to content

Commit 33cc8e1

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 a1801a4 commit 33cc8e1

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

tests/ui/test_ui_tools.py

+35
Original file line numberDiff line numberDiff line change
@@ -1877,6 +1877,41 @@ def test_main_view_generates_EDITED_label(self, mocker,
18771877
assert label[0].text == 'EDITED'
18781878
assert label[1][1] == 7
18791879

1880+
@pytest.mark.parametrize('message', [
1881+
{
1882+
'id': 4,
1883+
'type': 'stream',
1884+
'display_recipient': 'Verona',
1885+
'stream_id': 5,
1886+
'subject': 'Test topic',
1887+
'is_me_message': True,
1888+
'flags': [],
1889+
'content': '',
1890+
'reactions': [],
1891+
'sender_full_name': 'Human 1', # this message name
1892+
'timestamp': 1532103879,
1893+
}
1894+
])
1895+
@pytest.mark.parametrize('differences, header_needed, update_required', [
1896+
({'subject': 'Test topic 2'}, True, True),
1897+
({}, False, False),
1898+
({'sender_full_name': 'Human 2'}, False, True),
1899+
({'timestamp': 1532103869}, False, False),
1900+
], ids=[
1901+
'recipient_header_present',
1902+
'recipient_header_not_present',
1903+
'content_header_present',
1904+
'content_header_not_present',
1905+
])
1906+
def test_update_msg_content_header(self, msg_box, message,
1907+
update_required, mocker,
1908+
differences, header_needed):
1909+
last_msg = dict(message, **differences)
1910+
1911+
msg_box = MessageBox(message, self.model, last_msg)
1912+
1913+
assert msg_box.update_msg_content_header() == update_required
1914+
18801915
@pytest.mark.parametrize('key', keys_for_command('STREAM_MESSAGE'))
18811916
@pytest.mark.parametrize('narrow, expect_to_prefill', [
18821917
([], False),

zulipterminal/ui_tools/boxes.py

+20
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,26 @@ def main_view(self) -> List[Any]:
12941294
]
12951295
return [part for part, condition in parts if condition]
12961296

1297+
def update_msg_content_header(self) -> bool:
1298+
"""
1299+
Update the content header of a message box (if required).
1300+
"""
1301+
update_required = False
1302+
1303+
if self.need_recipient_header():
1304+
update_required = (self[1][1].text != ' ')
1305+
1306+
# Content header is not None
1307+
elif isinstance(self[0][1], urwid.Text):
1308+
update_required = (self[0][1].text != ' ')
1309+
1310+
if update_required:
1311+
# Re initialize the message if update is required.
1312+
# FIXME: Render specific element (here content header) instead?
1313+
super().__init__(self.main_view())
1314+
1315+
return update_required
1316+
12971317
@classmethod
12981318
def transform_content(cls, content: Any, server_url: str,
12991319
) -> Tuple[Tuple[None, Any],

0 commit comments

Comments
 (0)