Skip to content

Commit 7bd53f7

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 2c211bb commit 7bd53f7

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

tests/conftest.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
from zulipterminal.config.keys import keys_for_command
8+
from zulipterminal.helper import UnreadCounts
89
from zulipterminal.helper import initial_index as helper_initial_index
910
from zulipterminal.ui_tools.boxes import MessageBox
1011
from zulipterminal.ui_tools.buttons import (
@@ -758,6 +759,39 @@ def classified_unread_counts():
758759
}
759760
}
760761

762+
763+
@pytest.fixture
764+
def initial_unread_counts():
765+
return UnreadCounts(all_msg=0, all_pms=0,
766+
unread_topics=dict(), unread_pms=dict(),
767+
unread_huddles=dict(), streams=dict())
768+
769+
770+
@pytest.fixture
771+
def index_multiple_messages():
772+
"""
773+
Index fixture filled with multiple entries for messages.
774+
"""
775+
return dict(helper_initial_index, **{'messages': {
776+
1: {'id': 1, 'type': 'stream', 'subject': 'Topic 1', 'sender_id': 99,
777+
'stream_id': 1001, 'display_recipient': 'stream 1'},
778+
2: {'id': 2, 'type': 'stream', 'subject': 'Topic 1', 'sender_id': 100,
779+
'stream_id': 1001, 'display_recipient': 'stream 1'},
780+
3: {'id': 3, 'type': 'stream', 'subject': 'Topic 2', 'sender_id': 98,
781+
'stream_id': 1002, 'display_recipient': 'stream 2'},
782+
4: {'id': 4, 'type': 'stream', 'subject': 'Topic 3', 'sender_id': 101,
783+
'stream_id': 1002, 'display_recipient': 'stream 3'},
784+
5: {'id': 5, 'type': 'stream', 'subject': 'Topic 3', 'sender_id': 101,
785+
'stream_id': 1002, 'display_recipient': 'stream 3'},
786+
6: {'id': 6, 'type': 'stream', 'subject': 'Topic 1', 'sender_id': 101,
787+
'stream_id': 1001, 'display_recipient': 'stream 1'},
788+
7: {'id': 7, 'type': 'stream', 'subject': 'Topic 1', 'sender_id': 101,
789+
'stream_id': 1001, 'display_recipient': 'stream 1'},
790+
8: {'id': 8, 'type': 'stream', 'subject': 'Topic 10', 'sender_id': 101,
791+
'stream_id': 1003, 'display_recipient': 'stream 10'},
792+
9: {'id': 9, 'type': 'stream', 'subject': 'Topic 10', 'sender_id': 101,
793+
'stream_id': 1003, 'display_recipient': 'stream 10'},
794+
}})
761795
# --------------- UI Fixtures -----------------------------------------
762796

763797

tests/helper/test_helper.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,52 @@
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 10'): 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.index = index_multiple_messages
36+
controller.model.is_muted_stream = mocker.patch(
37+
'zulipterminal.model.Model.is_muted_stream', return_value=False)
38+
39+
unread_counts = deepcopy(dict(initial_unread_counts,
40+
**{'all_msg': all_msg,
41+
'unread_topics': unread_topics}))
42+
expected_unread_counts = dict(initial_unread_counts,
43+
**{'all_msg': expected_all_msg,
44+
'unread_topics': expected_unread_topics})
45+
controller.model.unread_counts = unread_counts
46+
set_count(id_list, controller, new_count)
47+
assert controller.model.unread_counts == expected_unread_counts
48+
49+
1150
def test_index_messages_narrow_all_messages(mocker,
1251
messages_successful_response,
1352
index_all_messages,

0 commit comments

Comments
 (0)