Skip to content

Commit 6a6b896

Browse files
committed
tests: helper: Test set_count for muted topics.
Add test for verifying unread_counts when marking muted topics read/unread. The 'all_msg' attribute in unread counts does not change while changing the read status of such messages.
1 parent 2e31dc6 commit 6a6b896

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/helper/test_helper.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,45 @@ def test_set_count_muted_streams(mocker, initial_unread_counts, muted_streams,
154154
assert controller.model.unread_counts == expected_unread_counts
155155

156156

157+
@pytest.mark.parametrize('all_msg, unread_topics', [
158+
(6, {(1001, 'Topic 1'): 3, (1002, 'Topic 3'): 1, (1003, 'Topic 10'): 2}),
159+
])
160+
@pytest.mark.parametrize(
161+
'new_count, expected_unread_topics, id_list, muted_topics,\
162+
expected_all_msg', [
163+
(1, {(1001, 'Topic 1'): 4, (1002, 'Topic 3'): 1,
164+
(1003, 'Topic 10'): 4}, [7, 8, 9], [['stream 1', 'Topic 1'],
165+
['stream 10', 'Topic 10']], 6),
166+
(1, {(1001, 'Topic 1'): 4, (1002, 'Topic 3'): 2, (1003, 'Topic 10'): 4},
167+
[7, 8, 9, 4], [['stream 1', 'Topic 1'], ['stream 10', 'Topic 10']], 7),
168+
(-1, {(1001, 'Topic 1'): 2, (1002, 'Topic 3'): 1,
169+
(1003, 'Topic 10'): 2}, [2], [['stream 1', 'Topic 1']], 6),
170+
(-1, {(1001, 'Topic 1'): 2, (1003, 'Topic 10'): 2}, [2, 4],
171+
[['stream 1', 'Topic 1']], 5),
172+
])
173+
def test_set_count_muted_topics(mocker, initial_unread_counts, muted_topics,
174+
unread_topics, all_msg, id_list, new_count,
175+
expected_unread_topics, expected_all_msg,
176+
index_multiple_messages):
177+
# all_msg does not change for muted topics.
178+
controller = mocker.patch('zulipterminal.core.Controller.__init__')
179+
controller.model.index = index_multiple_messages
180+
controller.view.left_panel.is_in_topic_view = False
181+
controller.model.is_muted_stream = mocker.patch(
182+
'zulipterminal.model.Model.is_muted_stream', return_value=False)
183+
controller.model.muted_topics = muted_topics
184+
185+
unread_counts = deepcopy(dict(initial_unread_counts,
186+
**{'all_msg': all_msg,
187+
'unread_topics': unread_topics}))
188+
expected_unread_counts = dict(initial_unread_counts,
189+
**{'all_msg': expected_all_msg,
190+
'unread_topics': expected_unread_topics})
191+
controller.model.unread_counts = unread_counts
192+
set_count(id_list, controller, new_count)
193+
assert controller.model.unread_counts == expected_unread_counts
194+
195+
157196
def test_index_messages_narrow_all_messages(mocker,
158197
messages_successful_response,
159198
index_all_messages,

0 commit comments

Comments
 (0)