Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions tests/ui_tools/test_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from pytest import param

from zulipterminal.config.keys import keys_for_command, primary_key_for_command
from zulipterminal.config.symbols import (
STREAM_MARKER_INVALID, STREAM_MARKER_PRIVATE, STREAM_MARKER_PUBLIC,
)
from zulipterminal.ui_tools.boxes import PanelSearchBox, WriteBox


Expand Down Expand Up @@ -311,13 +314,47 @@ def test__stream_box_autocomplete(self, mocker, write_box, text, state,
_process_typeaheads.assert_called_once_with(matching_streams, state,
matching_streams)

@pytest.mark.parametrize([
'stream_name',
'stream_id',
'is_valid_stream',
'expected_marker',
'expected_color'], [
('Secret stream', 99, True, STREAM_MARKER_PRIVATE, '#ccc'),
('Stream 1', 1, True, STREAM_MARKER_PUBLIC, '#b0a5fd'),
('Stream 0', 0, False, STREAM_MARKER_INVALID, 'general_bar'),
], ids=[
'private_stream',
'public_stream',
'invalid_stream_name',
])
def test__set_stream_write_box_style_markers(self, write_box, stream_id,
stream_name, is_valid_stream,
expected_marker, stream_dict,
mocker, expected_color):
# FIXME: Needs refactoring?
write_box.model.stream_dict = stream_dict
write_box.model.is_valid_stream.return_value = is_valid_stream
write_box.model.stream_id_from_name.return_value = stream_id

write_box.stream_box_view(stream_id)

write_box._set_stream_write_box_style(write_box, stream_name)

stream_marker = (write_box.header_write_box
[write_box.FOCUS_HEADER_PREFIX_STREAM])

assert stream_marker.text == expected_marker
assert stream_marker.attrib[0][0] == expected_color

@pytest.mark.parametrize('text, expected_text', [
('Som', 'Some general stream'),
('Some gen', 'Some general stream'),
])
def test__stream_box_autocomplete_with_spaces(self, mocker, write_box,
widget_size,
text, expected_text):
write_box.model.is_valid_stream.return_value = False
write_box.stream_box_view(1000)
stream_focus = write_box.FOCUS_HEADER_BOX_STREAM
write_box.header_write_box[stream_focus].set_edit_text(text)
Expand Down Expand Up @@ -561,6 +598,27 @@ def focus_val(x: str) -> int:
assert (write_box.FOCUS_MESSAGE_BOX_BODY
== focus_val(expected_focus_col_name))

@pytest.mark.parametrize(["msg_type", "expected_box_size"], [
('private', 1),
('stream', 4),
('stream_edit', 5),
], ids=[
'private_message',
'stream_message',
'stream_edit_message_box',
])
def test_write_box_header_contents(self, write_box, expected_box_size,
mocker, msg_type):
mocker.patch(BOXES + '.WriteBox.set_editor_mode')
if msg_type == 'stream':
write_box.stream_box_view(1000)
elif msg_type == 'stream_edit':
write_box.stream_box_edit_view(1000)
else:
write_box.private_box_view(None, '[email protected]')

assert len(write_box.header_write_box.widget_list) == expected_box_size


class TestPanelSearchBox:
search_caption = "Search Results "
Expand Down
1 change: 1 addition & 0 deletions tests/ui_tools/test_popups.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ def mock_external_classes(self, mocker, monkeypatch):
mocker.patch(VIEWS + ".urwid.SimpleFocusListWalker", return_value=[])
stream_id = 10
self.controller.model.stream_dict = {stream_id: {'name': 'books',
'invite_only': False,
'description': 'hey'}}
self.stream_info_view = StreamInfoView(self.controller, stream_id)

Expand Down
3 changes: 3 additions & 0 deletions zulipterminal/config/symbols.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
STREAM_MARKER_INVALID = '✗'
STREAM_MARKER_PRIVATE = 'P'
STREAM_MARKER_PUBLIC = '#'
STREAM_TOPIC_SEPARATOR = '▶'
# Used as a separator between messages and 'EDITED'
MESSAGE_CONTENT_MARKER = '▒' # Options are '█', '▓', '▒', '░'
Expand Down
50 changes: 37 additions & 13 deletions zulipterminal/ui_tools/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
)
from zulipterminal.config.symbols import (
MESSAGE_CONTENT_MARKER, MESSAGE_HEADER_DIVIDER, QUOTED_TEXT_MARKER,
STREAM_MARKER_INVALID, STREAM_MARKER_PRIVATE, STREAM_MARKER_PUBLIC,
STREAM_TOPIC_SEPARATOR, TIME_MENTION_MARKER,
)
from zulipterminal.helper import (
Expand All @@ -42,11 +43,13 @@ def __init__(self, view: Any) -> None:
self.msg_body_edit_enabled = True
self.FOCUS_CONTAINER_HEADER = 0
self.FOCUS_HEADER_BOX_RECIPIENT = 0
self.FOCUS_HEADER_BOX_STREAM = 0
self.FOCUS_HEADER_BOX_TOPIC = 1
self.FOCUS_HEADER_BOX_EDIT = 2
self.FOCUS_HEADER_BOX_STREAM = 1
self.FOCUS_HEADER_BOX_TOPIC = 3
self.FOCUS_HEADER_BOX_EDIT = 4
self.FOCUS_CONTAINER_MESSAGE = 1
self.FOCUS_MESSAGE_BOX_BODY = 0
self.FOCUS_HEADER_PREFIX_STREAM = 0
self.FOCUS_HEADER_PREFIX_TOPIC = 2 # FIXME: Is it required?

def main_view(self, new: bool) -> Any:
if new:
Expand Down Expand Up @@ -96,30 +99,33 @@ def stream_box_view(self, stream_id: int, caption: str='', title: str='',
key=primary_key_for_command('AUTOCOMPLETE'),
key_reverse=primary_key_for_command('AUTOCOMPLETE_REVERSE')
)
self.stream_write_box = ReadlineEdit(
caption="Stream: ",
edit_text=caption
)
self.stream_write_box = ReadlineEdit(edit_text=caption)
self.stream_write_box.enable_autocomplete(
func=self._stream_box_autocomplete,
key=primary_key_for_command('AUTOCOMPLETE'),
key_reverse=primary_key_for_command('AUTOCOMPLETE_REVERSE')
)
self.stream_write_box.set_completer_delims("")

self.title_write_box = ReadlineEdit(caption="Topic: ",
edit_text=title)
self.title_write_box = ReadlineEdit(edit_text=title)
self.title_write_box.enable_autocomplete(
func=self._topic_box_autocomplete,
key=primary_key_for_command('AUTOCOMPLETE'),
key_reverse=primary_key_for_command('AUTOCOMPLETE_REVERSE')
)
self.title_write_box.set_completer_delims("")

self.header_write_box = urwid.Columns(
[self.stream_write_box, self.title_write_box],
dividechars=1
)
stream_marker = STREAM_MARKER_PUBLIC
color = None
if caption:
color = self.model.stream_dict[self.stream_id]['color']
if self.model.stream_dict[self.stream_id]['invite_only']:
stream_marker = STREAM_MARKER_PRIVATE
self.header_write_box = urwid.Columns([
('pack', urwid.Text((color, STREAM_MARKER_PUBLIC))),
self.stream_write_box,
('pack', urwid.Text(STREAM_TOPIC_SEPARATOR)),
self.title_write_box], dividechars=1)
header_line_box = urwid.LineBox(
self.header_write_box,
tlcorner='━', tline='━', trcorner='━', lline='',
Expand All @@ -130,6 +136,8 @@ def stream_box_view(self, stream_id: int, caption: str='', title: str='',
(self.msg_write_box, self.options()),
]
self.contents = write_box
urwid.connect_signal(self.stream_write_box, 'change',
self._set_stream_write_box_style)

def stream_box_edit_view(self, stream_id: int, caption: str='',
title: str='') -> None:
Expand All @@ -138,6 +146,22 @@ def stream_box_edit_view(self, stream_id: int, caption: str='',

self.header_write_box.widget_list.append(self.edit_mode_button)

def _set_stream_write_box_style(self, widget: ReadlineEdit,
new_text: str) -> None:
# FIXME: Needs refactoring?
stream_marker = STREAM_MARKER_INVALID
color = 'general_bar'
if self.model.is_valid_stream(new_text):
stream = self.model.stream_dict[
self.model.stream_id_from_name(new_text)]
if stream['invite_only']:
stream_marker = STREAM_MARKER_PRIVATE
else:
stream_marker = STREAM_MARKER_PUBLIC
color = stream['color']
(self.header_write_box[self.FOCUS_HEADER_PREFIX_STREAM]
.set_text((color, stream_marker)))

def _topic_box_autocomplete(self, text: str, state: Optional[int]
) -> Optional[str]:
topic_names = self.model.topics_in_stream(self.stream_id)
Expand Down
8 changes: 6 additions & 2 deletions zulipterminal/ui_tools/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from typing_extensions import TypedDict

from zulipterminal.config.keys import is_command_key, primary_key_for_command
from zulipterminal.config.symbols import MUTE_MARKER
from zulipterminal.config.symbols import (
MUTE_MARKER, STREAM_MARKER_PRIVATE, STREAM_MARKER_PUBLIC,
)
from zulipterminal.helper import (
StreamData, edit_mode_captions, hash_util_decode,
)
Expand Down Expand Up @@ -168,11 +170,13 @@ def __init__(self, properties: StreamData,
view.palette.append((
's' + self.color, '', '', 'standout', inverse_text, self.color))

stream_marker = (STREAM_MARKER_PRIVATE if is_private
else STREAM_MARKER_PUBLIC)
super().__init__(controller,
caption=self.stream_name,
show_function=controller.narrow_to_stream,
prefix_character=(
self.color, 'P' if is_private else '#'),
self.color, stream_marker),
width=width,
count=count)

Expand Down
7 changes: 5 additions & 2 deletions zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
)
from zulipterminal.config.symbols import (
CHECK_MARK, LIST_TITLE_BAR_LINE, PINNED_STREAMS_DIVIDER, STATUS_ACTIVE,
STATUS_IDLE, STATUS_INACTIVE, STATUS_OFFLINE,
STATUS_IDLE, STATUS_INACTIVE, STATUS_OFFLINE, STREAM_MARKER_PRIVATE,
STREAM_MARKER_PUBLIC,
)
from zulipterminal.helper import (
Message, asynch, edit_mode_captions, match_stream, match_user,
Expand Down Expand Up @@ -1077,7 +1078,9 @@ def __init__(self, controller: Any, stream_id: int) -> None:
self.stream_id = stream_id
self.controller = controller
stream = controller.model.stream_dict[stream_id]
title = '# {}'.format(stream['name'])
stream_marker = (STREAM_MARKER_PRIVATE if stream['invite_only']
else STREAM_MARKER_PUBLIC)
title = '{} {}'.format(stream_marker, stream['name'])
desc = stream['description']
stream_info_content = [('', [desc]), ('Stream settings', [])]
popup_width, column_widths = self.calculate_table_widths(
Expand Down