Skip to content

Commit 3bb47ca

Browse files
committed
views: Show author name in EditHistoryView.
Test added.
1 parent f17be77 commit 3bb47ca

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
@@ -1225,11 +1225,13 @@ def test_keypress_navigation(self, mocker,
12251225
class TestEditHistoryView:
12261226
@pytest.fixture(autouse=True)
12271227
def mock_external_classes(self, mocker, message_fixture,
1228-
message_history_fixture):
1228+
message_history_fixture, user_dict):
12291229
self.controller = mocker.Mock()
12301230
self.controller.model.get_message_history = (
12311231
mocker.Mock(return_value='')
12321232
)
1233+
self.controller.model.user_id_email_dict = {1001: '[email protected]'}
1234+
self.controller.model.user_dict = user_dict
12331235
message_fixture['message_history'] = message_history_fixture
12341236
mocker.patch(VIEWS + '.urwid.SimpleFocusListWalker', return_value=[])
12351237
self.edit_history_view = EditHistoryView(self.controller,
@@ -1241,6 +1243,11 @@ def test_init(self, mocker, message_fixture):
12411243
(self.controller.model.get_message_history.
12421244
assert_called_once_with(message_fixture))
12431245

1246+
@pytest.mark.parametrize('user_id, full_name', [(1001, 'Human Myself')])
1247+
def test_get_author(self, user_id, full_name):
1248+
result = self.edit_history_view.get_author(user_id)
1249+
assert result == full_name
1250+
12441251
def test_keypress_exit_popup_any_key(self):
12451252
key = 'a'
12461253
size = (200, 20)
@@ -1275,7 +1282,8 @@ def test_build_pile(self, message_history_fixture):
12751282
assert isinstance(contents[0][0], Text) # Header: Topic.
12761283
assert isinstance(contents[0][1], Text) # Header: Timestamp.
12771284
assert isinstance(contents[1], Columns) # Subheader.
1278-
assert isinstance(contents[1][0], Text) # Subheader: Tag.
1285+
assert isinstance(contents[1][0], Text) # Subheader: Author.
1286+
assert isinstance(contents[1][1], Text) # Subheader: Tag.
12791287
assert isinstance(contents[2], Text) # Message.
12801288

12811289

zulipterminal/ui_tools/views.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,8 @@ def __init__(self, controller: Any, msg: Any) -> None:
952952
self.widgets.append(self.build_pile(snapshot, 'Current'))
953953
continue
954954
elif index == 0:
955-
self.widgets.append(self.build_pile(snapshot, 'Original'))
955+
self.widgets.append(self.build_pile(snapshot, 'Original',
956+
'Posted'))
956957
else:
957958
self.widgets.append(self.build_pile(snapshot))
958959
# Add a blank line after an edit block/pile.
@@ -967,9 +968,11 @@ def __init__(self, controller: Any, msg: Any) -> None:
967968
super().__init__(controller, self.widgets, 'MSG_INFO')
968969

969970
def build_pile(self, snapshot: Dict[str, Any], tag: str='',
970-
) -> Any:
971+
author_prefix: str='Edited') -> Any:
971972
timestamp = time.ctime(snapshot['timestamp'])[:-5]
972973
tag = '({} Version)'.format(tag) if tag else ''
974+
author = '{} by {}'.format(author_prefix,
975+
self.get_author(snapshot['user_id']))
973976
topic = snapshot['topic']
974977

975978
# Add suffix to the topic if it has been edited.
@@ -983,14 +986,20 @@ def build_pile(self, snapshot: Dict[str, Any], tag: str='',
983986
], dividechars=2,
984987
)
985988
subheader = urwid.Columns([
989+
urwid.Text(('edit_author', author)),
986990
# 18 = max(len(tag)); len('(Original Version)').
987-
(18, urwid.Text(('edit_tag', tag))),
991+
(18, urwid.Text(('edit_tag', tag), align='right')),
988992
], dividechars=2,
989993
)
990994
message = urwid.Text(snapshot['content'])
991995
return urwid.Pile([urwid.AttrWrap(header, 'popup_contrast'), subheader,
992996
message])
993997

998+
def get_author(self, user_id: int) -> str:
999+
user_email = self.controller.model.user_id_email_dict[user_id]
1000+
full_name = self.controller.model.user_dict[user_email]['full_name']
1001+
return full_name
1002+
9941003
def keypress(self, size: urwid_Size, key: str) -> str:
9951004
if (is_command_key('GO_BACK', key)
9961005
or is_command_key('EDIT_HISTORY', key)):

0 commit comments

Comments
 (0)