def test_keypress_EXIT_TOGGLE_TOPIC( self, mocker: MockerFixture, topic_button: TopicButton, key: str, widget_size: Callable[[Widget], urwid_Size], ) -> None: size = widget_size(topic_button) topic_button.view.left_panel = mocker.Mock() topic_button.keypress(size, key) topic_button.view.left_panel.show_stream_view.assert_called_once_with()
def topics_view(self, stream_button: Any) -> Any: stream_id = stream_button.stream_id topics_btn_list = [ TopicButton(stream_id=stream_id, topic=topic, controller=self.controller, width=self.width, count=self.model.unread_counts['unread_topics'].get( (stream_id, topic), 0)) for topic in self.model.index['topics'][stream_id] ] self.view.topic_w = TopicsView(topics_btn_list, self.view, stream_button) w = urwid.LineBox(self.view.topic_w, title="Topics", tlcorner=u'━', tline=u'━', lline=u'', trcorner=u'━', blcorner=u'', rline=u'', bline=u'', brcorner=u'─') return w
def keypress(self, size: Tuple[int, int], key: str) -> str: if is_command_key('GO_BACK', key): self.header.keypress(size, 'esc') self.footer.keypress(size, 'esc') self.set_focus('body') elif self.focus_position in ['footer', 'header']: return super(MiddleColumnView, self).keypress(size, key) elif is_command_key('SEARCH_MESSAGES', key): self.controller.editor_mode = True self.controller.editor = self.search_box self.set_focus('header') return key elif is_command_key('REPLY_MESSAGE', key): self.body.keypress(size, 'enter') self.set_focus('footer') self.footer.focus_position = 1 return key elif is_command_key('STREAM_MESSAGE', key): self.body.keypress(size, 'c') self.set_focus('footer') self.footer.focus_position = 0 return key elif is_command_key('REPLY_AUTHOR', key): self.body.keypress(size, 'R') self.set_focus('footer') self.footer.focus_position = 1 return key elif is_command_key('NEXT_UNREAD_TOPIC', key): # narrow to next unread topic stream_topic = self.get_next_unread_topic() if stream_topic is None: return key stream, topic = stream_topic self.controller.narrow_to_topic(TopicButton(stream, topic, self.model)) return key elif is_command_key('NEXT_UNREAD_PM', key): # narrow to next unread pm pm = self.get_next_unread_pm() if pm is None: return key email = self.model.user_id_email_dict[pm] self.controller.narrow_to_user(UnreadPMButton(pm, email)) elif is_command_key('PRIVATE_MESSAGE', key): # Create new PM message self.footer.private_box_view() self.set_focus('footer') self.footer.focus_position = 0 return key elif is_command_key('GO_LEFT', key): self.view.show_left_panel(visible=True) elif is_command_key('GO_RIGHT', key): self.view.show_right_panel(visible=True) return super(MiddleColumnView, self).keypress(size, key)
def test_init_calls_top_button(self, mocker, count, title, stream_id, stream_name): controller = mocker.Mock() controller.model.stream_dict = { 205: {"name": "PTEST"}, 86: {"name": "Django"}, 14: {"name": "GSoC"}, } controller.model.is_muted_topic = mocker.Mock(return_value=False) view = mocker.Mock() top_button = mocker.patch(MODULE + ".TopButton.__init__") params = dict(controller=controller, count=count) topic_button = TopicButton( stream_id=stream_id, topic=title, view=view, **params ) top_button.assert_called_once_with( caption=title, prefix_character="", show_function=mocker.ANY, # partial count_style="unread_count", **params, ) assert topic_button.stream_name == stream_name assert topic_button.stream_id == stream_id assert topic_button.topic_name == title
def test_init_calls_top_button(self, mocker, width, count, title, stream_id, stream_name): controller = mocker.Mock() controller.model.stream_dict = { 205: { 'name': 'PTEST' }, 86: { 'name': 'Django' }, 14: { 'name': 'GSoC' }, } controller.model.is_muted_topic = mocker.Mock(return_value=False) top_button = mocker.patch(TOPBUTTON + '.__init__') params = dict(controller=controller, width=width, count=count) topic_button = TopicButton(stream_id=stream_id, topic=title, **params) top_button.assert_called_once_with( caption=title, prefix_character='', show_function=mocker.ANY, # partial **params) assert topic_button.stream_name == stream_name assert topic_button.stream_id == stream_id assert topic_button.topic_name == title
def test_init_calls_mark_muted( self, mocker: MockerFixture, stream_name: str, title: str, is_muted_topic_return_value: bool, is_muted_called: bool, ) -> None: mark_muted = mocker.patch(MODULE + ".TopicButton.mark_muted") controller = mocker.Mock() controller.model.is_muted_topic = mocker.Mock( return_value=is_muted_topic_return_value) controller.model.stream_dict = {205: {"name": stream_name}} view = mocker.Mock() topic_button = TopicButton( stream_id=205, topic=title, controller=controller, view=view, count=0, ) if is_muted_called: mark_muted.assert_called_once_with() else: mark_muted.assert_not_called()
def keypress(self, size: Tuple[int, int], key: str) -> str: if key == 'esc': self.header.keypress(size, 'esc') self.footer.keypress(size, 'esc') self.set_focus('body') elif self.focus_position in ['footer', 'header']: return super(MiddleColumnView, self).keypress(size, key) elif key == '/': self.controller.editor_mode = True self.controller.editor = self.search_box self.set_focus('header') return key elif key == 'r': self.body.keypress(size, 'enter') self.set_focus('footer') self.footer.focus_position = 1 return key elif key == 'c': self.body.keypress(size, 'c') self.set_focus('footer') self.footer.focus_position = 0 return key elif key == 'R': self.body.keypress(size, 'R') self.set_focus('footer') self.footer.focus_position = 1 return key elif key == 'n': # narrow to next unread topic stream_topic = self.get_next_unread_topic() if stream_topic is None: return key stream, topic = stream_topic self.controller.narrow_to_topic( TopicButton(stream, topic, self.model)) return key elif key == 'p': # narrow to next unread pm pm = self.get_next_unread_pm() if pm is None: return key email = self.model.user_id_email_dict[pm] self.controller.narrow_to_user(UnreadPMButton(pm, email)) return super(MiddleColumnView, self).keypress(size, key)
def topic_button(mocker): """ Mocked topic button. """ view_mock = mocker.Mock() view_mock.palette = [(None, "black", "white")] button = TopicButton( stream_id=100, topic="PTEST", controller=mocker.patch("zulipterminal.core.Controller"), view=view_mock, count=30, ) return button
def test_init_calls_mark_muted(self, mocker, stream_name, title, is_muted_topic_return_value, is_muted_called): mark_muted = mocker.patch( 'zulipterminal.ui_tools.buttons.TopicButton.mark_muted') controller = mocker.Mock() controller.model.is_muted_topic = (mocker.Mock( return_value=is_muted_topic_return_value)) controller.model.stream_dict = {205: {'name': stream_name}} topic_button = TopicButton(stream_id=205, topic=title, controller=controller, width=40, count=0) if is_muted_called: mark_muted.assert_called_once_with() else: mark_muted.assert_not_called()
def update_topics_list(self, stream_id: int, topic_name: str, sender_id: int) -> None: # More recent topics are found towards the beginning # of the list. for topic_iterator, topic_button in enumerate(self.log): if topic_button.topic_name == topic_name: self.log.insert(0, self.log.pop(topic_iterator)) self.list_box.set_focus_valign('bottom') if sender_id == self.view.model.user_id: self.list_box.set_focus(0) return # No previous topics with same topic names are found # hence we create a new topic button for it. new_topic_button = TopicButton(stream_id, topic_name, self.view.controller, self.view.LEFT_WIDTH, 0) self.log.insert(0, new_topic_button) self.list_box.set_focus_valign('bottom') if sender_id == self.view.model.user_id: self.list_box.set_focus(0)
def keypress(self, size: urwid_Size, key: str) -> Optional[str]: if is_command_key('GO_BACK', key): self.header.keypress(size, 'esc') self.footer.keypress(size, 'esc') self.set_focus('body') elif self.focus_position in ['footer', 'header']: return super().keypress(size, key) elif is_command_key('SEARCH_MESSAGES', key): self.controller.editor_mode = True self.controller.editor = self.search_box self.set_focus('header') return key elif is_command_key('REPLY_MESSAGE', key): self.body.keypress(size, 'enter') if self.footer.focus is not None: self.set_focus('footer') self.footer.focus_position = 1 return key elif is_command_key('STREAM_MESSAGE', key): self.body.keypress(size, 'c') # For new streams with no previous conversation. if self.footer.focus is None: stream_id = self.model.stream_id stream_dict = self.model.stream_dict self.footer.stream_box_view( caption=stream_dict[stream_id]['name']) self.set_focus('footer') self.footer.focus_position = 0 return key elif is_command_key('REPLY_AUTHOR', key): self.body.keypress(size, 'R') if self.footer.focus is not None: self.set_focus('footer') self.footer.focus_position = 1 return key elif is_command_key('NEXT_UNREAD_TOPIC', key): # narrow to next unread topic stream_topic = self.get_next_unread_topic() if stream_topic is None: return key stream, topic = stream_topic self.controller.narrow_to_topic( TopicButton(stream, topic, self.controller)) return key elif is_command_key('NEXT_UNREAD_PM', key): # narrow to next unread pm pm = self.get_next_unread_pm() if pm is None: return key email = self.model.user_id_email_dict[pm] self.controller.narrow_to_user(UnreadPMButton(pm, email)) elif is_command_key('PRIVATE_MESSAGE', key): # Create new PM message self.footer.private_box_view() self.set_focus('footer') self.footer.focus_position = 0 return key elif is_command_key('GO_LEFT', key): self.view.show_left_panel(visible=True) elif is_command_key('GO_RIGHT', key): self.view.show_right_panel(visible=True) return super().keypress(size, key)