Skip to content

Commit ddf924c

Browse files
committed
views: Show author name in EditHistoryView.
Test added.
1 parent 755a6b8 commit ddf924c

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

tests/ui/test_ui_tools.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,11 +1232,13 @@ def test_keypress_navigation(self, mocker,
12321232
class TestEditHistoryView:
12331233
@pytest.fixture(autouse=True)
12341234
def mock_external_classes(self, mocker, message_fixture,
1235-
message_history_fixture):
1235+
message_history_fixture, user_dict):
12361236
self.controller = mocker.Mock()
12371237
self.controller.model.get_message_history = (
12381238
mocker.Mock(return_value='')
12391239
)
1240+
self.controller.model.user_id_email_dict = {1001: '[email protected]'}
1241+
self.controller.model.user_dict = user_dict
12401242
message_fixture['message_history'] = message_history_fixture
12411243
mocker.patch(VIEWS + '.urwid.SimpleFocusListWalker', return_value=[])
12421244
self.edit_history_view = EditHistoryView(self.controller,
@@ -1248,6 +1250,11 @@ def test_init(self, mocker, message_fixture):
12481250
(self.controller.model.get_message_history.
12491251
assert_called_once_with(message_fixture))
12501252

1253+
@pytest.mark.parametrize('user_id, full_name', [(1001, 'Human Myself')])
1254+
def test_get_author(self, user_id, full_name):
1255+
result = self.edit_history_view.get_author(user_id)
1256+
assert result == full_name
1257+
12511258
def test_keypress_exit_popup_any_key(self):
12521259
key = 'a'
12531260
size = (200, 20)
@@ -1282,7 +1289,8 @@ def test_build_pile(self, message_history_fixture):
12821289
assert isinstance(contents[0][0], Text) # Header: Topic.
12831290
assert isinstance(contents[0][1], Text) # Header: Timestamp.
12841291
assert isinstance(contents[1], Columns) # Subheader.
1285-
assert isinstance(contents[1][0], Text) # Subheader: Tag.
1292+
assert isinstance(contents[1][0], Text) # Subheader: Author.
1293+
assert isinstance(contents[1][1], Text) # Subheader: Tag.
12861294
assert isinstance(contents[2], Text) # Message.
12871295

12881296

zulipterminal/ui_tools/views.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,8 @@ def __init__(self, controller: Any, msg: Any) -> None:
984984
self.widgets.append(self.build_pile(snapshot, 'Current'))
985985
continue
986986
elif index == 0:
987-
self.widgets.append(self.build_pile(snapshot, 'Original'))
987+
self.widgets.append(self.build_pile(snapshot, 'Original',
988+
'Posted'))
988989
else:
989990
self.widgets.append(self.build_pile(snapshot))
990991
# Add a blank line after an edit block/pile.
@@ -999,9 +1000,11 @@ def __init__(self, controller: Any, msg: Any) -> None:
9991000
super().__init__(controller, self.widgets, 'MSG_INFO')
10001001

10011002
def build_pile(self, snapshot: Dict[str, Any], tag: str='',
1002-
) -> Any:
1003+
author_prefix: str='Edited') -> Any:
10031004
timestamp = time.ctime(snapshot['timestamp'])[:-5]
10041005
tag = '({} Version)'.format(tag) if tag else ''
1006+
author = '{} by {}'.format(author_prefix,
1007+
self.get_author(snapshot['user_id']))
10051008
topic = snapshot['topic']
10061009

10071010
# Add suffix to the topic if it has been edited.
@@ -1015,14 +1018,20 @@ def build_pile(self, snapshot: Dict[str, Any], tag: str='',
10151018
], dividechars=2,
10161019
)
10171020
subheader = urwid.Columns([
1021+
urwid.Text(('edit_author', author)),
10181022
# 18 = max(len(tag)); len('(Original Version)').
1019-
(18, urwid.Text(('edit_tag', tag))),
1023+
(18, urwid.Text(('edit_tag', tag), align='right')),
10201024
], dividechars=2,
10211025
)
10221026
message = urwid.Text(snapshot['content'])
10231027
return urwid.Pile([urwid.AttrWrap(header, 'popup_contrast'), subheader,
10241028
message])
10251029

1030+
def get_author(self, user_id: int) -> str:
1031+
user_email = self.controller.model.user_id_email_dict[user_id]
1032+
full_name = self.controller.model.user_dict[user_email]['full_name']
1033+
return full_name
1034+
10261035
def keypress(self, size: urwid_Size, key: str) -> str:
10271036
if (is_command_key('GO_BACK', key)
10281037
or is_command_key('EDIT_HISTORY', key)):

0 commit comments

Comments
 (0)