Skip to content

Commit 9e87f9e

Browse files
committed
conftest/helper/views: Use canonical_topic() for unread_counts.
Tests amended.
1 parent 1c54d9d commit 9e87f9e

File tree

5 files changed

+23
-17
lines changed

5 files changed

+23
-17
lines changed

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,8 @@ def classified_unread_counts():
800800
'all_msg': 12,
801801
'all_pms': 8,
802802
'unread_topics': {
803-
(1000, 'Some general unread topic'): 3,
804-
(99, 'Some private unread topic'): 1
803+
(1000, 'some general unread topic'): 3,
804+
(99, 'some private unread topic'): 1
805805
},
806806
'unread_pms': {
807807
1: 2,

tests/helper/test_helper.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,16 @@ def test_powerset(iterable, map_func, expected_powerset):
189189

190190

191191
@pytest.mark.parametrize('muted_streams, muted_topics, vary_in_unreads', [
192-
([99], [['Some general stream', 'Some general unread topic']], {
192+
([99], [['Some general stream', 'some general unread topic']], {
193193
'all_msg': 8,
194194
'streams': {99: 1},
195-
'unread_topics': {(99, 'Some private unread topic'): 1},
195+
'unread_topics': {(99, 'some private unread topic'): 1},
196196
'all_mentions': 0,
197197
}),
198-
([1000], [['Secret stream', 'Some private unread topic']], {
198+
([1000], [['Secret stream', 'some private unread topic']], {
199199
'all_msg': 8,
200200
'streams': {1000: 3},
201-
'unread_topics': {(1000, 'Some general unread topic'): 3},
201+
'unread_topics': {(1000, 'some general unread topic'): 3},
202202
'all_mentions': 0,
203203
}),
204204
([1], [], {'all_mentions': 0})
@@ -214,7 +214,7 @@ def test_classify_unread_counts(mocker, initial_data, stream_dict,
214214
model.initial_data = initial_data
215215
model.is_muted_topic = mocker.Mock(side_effect=(
216216
lambda stream_id, topic:
217-
[model.stream_dict[stream_id]['name'], topic] in muted_topics
217+
[model.stream_dict[stream_id]['name'], topic.lower()] in muted_topics
218218
))
219219
model.muted_streams = muted_streams
220220
assert classify_unread_counts(model) == dict(classified_unread_counts,

tests/ui/test_ui_tools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,8 +1144,8 @@ def mock_external_classes(self, mocker):
11441144
1000: 1,
11451145
},
11461146
'unread_topics': {
1147-
(205, 'TOPIC1'): 34,
1148-
(205, 'TOPIC2'): 100,
1147+
(205, 'topic1'): 34,
1148+
(205, 'topic2'): 100,
11491149
},
11501150
'all_mentions': 1,
11511151
}
@@ -1200,7 +1200,7 @@ def test_topics_view(self, mocker, stream_button, width=40):
12001200
topic_button = mocker.patch(VIEWS + '.TopicButton')
12011201
topics_view = mocker.patch(VIEWS + '.TopicsView')
12021202
line_box = mocker.patch(VIEWS + '.urwid.LineBox')
1203-
topic_list = ['TOPIC1', 'TOPIC2', 'TOPIC3']
1203+
topic_list = ['topic1', 'topic2', 'topic3']
12041204
unread_count_list = [34, 100, 0]
12051205
self.view.model.topics_in_stream = (
12061206
mocker.Mock(return_value=topic_list)

zulipterminal/helper.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
'all_msg': int,
9494
'all_pms': int,
9595
'all_mentions': int,
96-
'unread_topics': Dict[Tuple[int, str], int], # stream_id, topic
96+
'unread_topics': Dict[Tuple[int, str], int], # stream_id, canonical topic
9797
'unread_pms': Dict[int, int], # sender_id
9898
'unread_huddles': Dict[FrozenSet[int], int], # Group pms
9999
'streams': Dict[int, int], # stream_id
@@ -139,8 +139,10 @@ def update_unreads(unreads: Dict[KeyT, int], key: KeyT) -> None:
139139
for message in changed_messages:
140140
if message['type'] == 'stream':
141141
stream_id = message['stream_id']
142+
# Use lowercase topic names in unread_topics to backup the
143+
# invariant in index.
142144
update_unreads(unread_counts['unread_topics'],
143-
(stream_id, message['subject']))
145+
(stream_id, canonicalize_topic(message['subject'])))
144146
update_unreads(unread_counts['streams'], stream_id)
145147
# self-pm has only one display_recipient
146148
# 1-1 pms have 2 display_recipient
@@ -201,7 +203,7 @@ def _set_count_in_view(controller: Any, new_count: int,
201203
# If topic_view is open for incoming messages's stream,
202204
# We update the respective TopicButton count accordingly.
203205
for topic_button in topic_buttons_log:
204-
if topic_button.topic_name == msg_topic:
206+
if compare_lowercase(topic_button.topic_name, msg_topic):
205207
topic_button.update_count(topic_button.count
206208
+ new_count)
207209
else:
@@ -459,8 +461,10 @@ def classify_unread_counts(model: Any) -> UnreadCounts:
459461
continue
460462
if model.is_muted_topic(stream_id, stream['topic']):
461463
continue
462-
stream_topic = (stream_id, stream['topic'])
463-
unread_counts['unread_topics'][stream_topic] = count
464+
stream_topic = (stream_id, canonicalize_topic(stream['topic']))
465+
unread_counts['unread_topics'][stream_topic] = (
466+
count + unread_counts['unread_topics'].get(stream_topic, 0)
467+
)
464468
if not unread_counts['streams'].get(stream_id):
465469
unread_counts['streams'][stream_id] = count
466470
else:

zulipterminal/ui_tools/views.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
from zulipterminal.config.symbols import (
1212
CHECK_MARK, LIST_TITLE_BAR_LINE, PINNED_STREAMS_DIVIDER,
1313
)
14-
from zulipterminal.helper import Message, asynch, match_stream, match_user
14+
from zulipterminal.helper import (
15+
Message, asynch, canonicalize_topic, match_stream, match_user,
16+
)
1517
from zulipterminal.ui_tools.boxes import PanelSearchBox
1618
from zulipterminal.ui_tools.buttons import (
1719
HomeButton, MentionedButton, MessageLinkButton, PMButton, StarredButton,
@@ -790,7 +792,7 @@ def topics_view(self, stream_button: Any) -> Any:
790792
controller=self.controller,
791793
width=self.width,
792794
count=self.model.unread_counts['unread_topics'].
793-
get((stream_id, topic), 0)
795+
get((stream_id, canonicalize_topic(topic)), 0)
794796
)
795797
for topic in topics
796798
]

0 commit comments

Comments
 (0)