Skip to content

Commit 812a667

Browse files
committed
tests: helper: Test set_count for stream messages.
Add test for verifying unread_counts when marking streams as read/unread. Added new index fixture that contains a large number of messages.
1 parent 914fc53 commit 812a667

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

tests/conftest.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest
66

7+
from zulipterminal.helper import UnreadCounts
78
from zulipterminal.helper import initial_index as helper_initial_index
89
from zulipterminal.ui_tools.boxes import MessageBox
910
from zulipterminal.ui_tools.buttons import (
@@ -743,3 +744,37 @@ def classified_unread_counts():
743744
99: 1
744745
}
745746
}
747+
748+
749+
@pytest.fixture
750+
def initial_unread_counts():
751+
return UnreadCounts(all_msg=0, all_pms=0,
752+
unread_topics=dict(), unread_pms=dict(),
753+
unread_huddles=dict(), streams=dict())
754+
755+
756+
@pytest.fixture
757+
def index_multiple_messages():
758+
"""
759+
Index fixture filled with multiple entries for messages
760+
"""
761+
return dict(helper_initial_index, **{'messages': {
762+
1: {'id': 1, 'type': 'stream', 'subject': 'Topic 1',
763+
'sender_id': 99, 'stream_id': 1001, 'display_recipient': []},
764+
2: {'id': 2, 'type': 'stream', 'subject': 'Topic 1',
765+
'sender_id': 100, 'stream_id': 1001, 'display_recipient': []},
766+
3: {'id': 3, 'type': 'stream', 'subject': 'Topic 2',
767+
'sender_id': 98, 'stream_id': 1002, 'display_recipient': []},
768+
4: {'id': 4, 'type': 'stream', 'subject': 'Topic 3',
769+
'sender_id': 101, 'stream_id': 1002, 'display_recipient': []},
770+
5: {'id': 5, 'type': 'stream', 'subject': 'Topic 3',
771+
'sender_id': 101, 'stream_id': 1002, 'display_recipient': []},
772+
6: {'id': 6, 'type': 'stream', 'subject': 'Topic 1',
773+
'sender_id': 101, 'stream_id': 1001, 'display_recipient': []},
774+
7: {'id': 7, 'type': 'stream', 'subject': 'Topic 1',
775+
'sender_id': 101, 'stream_id': 1001, 'display_recipient': []},
776+
8: {'id': 8, 'type': 'stream', 'subject': 'Topic 100',
777+
'sender_id': 101, 'stream_id': 1003, 'display_recipient': []},
778+
9: {'id': 9, 'type': 'stream', 'subject': 'Topic 100',
779+
'sender_id': 101, 'stream_id': 1003, 'display_recipient': []},
780+
}})

tests/helper/test_helper.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,55 @@
1+
from copy import deepcopy
12
from typing import Any
23

34
import pytest
45

56
from zulipterminal.helper import (
67
canonicalize_color, classify_unread_counts, index_messages, notify,
7-
powerset,
8+
powerset, set_count,
89
)
910

1011

12+
@pytest.mark.parametrize('all_msg, unread_topics', [
13+
(6, {(1001, 'Topic 1'): 3, (1002, 'Topic 2'): 1, (1002, 'Topic 3'): 2}),
14+
])
15+
@pytest.mark.parametrize(
16+
'new_count, id_list, expected_all_msg, expected_unread_topics', [
17+
(1, [], 6, {(1001, 'Topic 1'): 3, (1002, 'Topic 2'): 1,
18+
(1002, 'Topic 3'): 2}),
19+
(1, [7], 7, {(1001, 'Topic 1'): 4, (1002, 'Topic 2'): 1,
20+
(1002, 'Topic 3'): 2}),
21+
(1, [7, 8, 9], 9, {(1001, 'Topic 1'): 4, (1002, 'Topic 2'): 1,
22+
(1002, 'Topic 3'): 2, (1003, 'Topic 100'): 2}),
23+
(-1, [], 6, {(1001, 'Topic 1'): 3, (1002, 'Topic 2'): 1,
24+
(1002, 'Topic 3'): 2}),
25+
(-1, [5], 5, {(1001, 'Topic 1'): 3, (1002, 'Topic 2'): 1,
26+
(1002, 'Topic 3'): 1}),
27+
(-1, [1, 2, 4, 6], 2, {(1002, 'Topic 2'): 1, (1002, 'Topic 3'): 1}),
28+
(-1, [1, 2, 3, 4, 5, 6], 0, {}),
29+
])
30+
def test_set_count_stream(mocker, initial_unread_counts,
31+
unread_topics, all_msg, id_list, new_count,
32+
expected_unread_topics, expected_all_msg,
33+
index_multiple_messages):
34+
controller = mocker.patch('zulipterminal.core.Controller.__init__')
35+
controller.model.is_muted_stream = mocker.patch(
36+
'zulipterminal.model.Model.is_muted_stream', return_value=False)
37+
38+
unread_counts = deepcopy(dict(initial_unread_counts,
39+
**{'all_msg': all_msg,
40+
'unread_topics': unread_topics}))
41+
42+
controller.model.index = index_multiple_messages
43+
controller.model.unread_counts = unread_counts
44+
set_count(id_list, controller, new_count)
45+
46+
expected_unread_counts = dict(initial_unread_counts,
47+
**{'all_msg': expected_all_msg,
48+
'unread_topics': expected_unread_topics})
49+
50+
assert controller.model.unread_counts == expected_unread_counts
51+
52+
1153
def test_index_messages_narrow_all_messages(mocker,
1254
messages_successful_response,
1355
index_all_messages,

0 commit comments

Comments
 (0)