Skip to content

Commit 675a180

Browse files
committed
tests: helper: Test set_count for group pms.
Add test for verifying unread_counts when marking group pms as read/unread. Add group pm message entries to index fixture.
1 parent 3d7c946 commit 675a180

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

tests/conftest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,26 @@ def index_multiple_messages():
808808
'display_recipient': [{'id': 202}]},
809809
16: {'id': 16, 'type': 'private', 'sender_id': 200,
810810
'display_recipient': [{'id': 202}, {'id': 200}]},
811+
# group-pms
812+
17: {'id': 17, 'type': 'private', 'sender_id': 202,
813+
'display_recipient': [{'id': 202}, {'id': 201}, {'id': 200}]},
814+
18: {'id': 18, 'type': 'private', 'sender_id': 200,
815+
'display_recipient': [{'id': 202}, {'id': 200}, {'id': 201}]},
816+
19: {'id': 19, 'type': 'private', 'sender_id': 201,
817+
'display_recipient': [{'id': 202}, {'id': 201}, {'id': 200}]},
818+
20: {'id': 21, 'type': 'private', 'sender_id': 200,
819+
'display_recipient': [{'id': 202}, {'id': 200}, {'id': 201}]},
820+
21: {'id': 20, 'type': 'private', 'sender_id': 202,
821+
'display_recipient': [{'id': 202}, {'id': 200}, {'id': 199}]},
822+
22: {'id': 20, 'type': 'private', 'sender_id': 202,
823+
'display_recipient': [{'id': 202}, {'id': 200}, {'id': 199}]},
824+
23: {'id': 20, 'type': 'private', 'sender_id': 202,
825+
'display_recipient': [{'id': 202}, {'id': 200}, {'id': 199}]},
826+
24: {'id': 20, 'type': 'private', 'sender_id': 202,
827+
'display_recipient': [{'id': 202}, {'id': 200}, {'id': 199},
828+
{'id': 198}]},
811829
}})
830+
812831
# --------------- UI Fixtures -----------------------------------------
813832

814833

tests/helper/test_helper.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,43 @@ def test_set_count_pms(mocker, initial_unread_counts, all_msg,
7979
assert controller.model.unread_counts == expected_unread_counts
8080

8181

82+
@pytest.mark.parametrize('all_msg, all_pms, unread_huddles', [
83+
(4, 3, {frozenset({202, 200, 201}): 2, frozenset({202, 200, 199, 198}): 1})
84+
])
85+
@pytest.mark.parametrize(('new_count, id_list, expected_all_msg,'
86+
'expected_all_pms, expected_unread_huddles'), [
87+
(-1, [20, 18], 2, 1, {frozenset({202, 200, 199, 198}): 1}),
88+
(-1, [20, 18, 24], 1, 0, {}),
89+
(-1, [], 4, 3, {frozenset({202, 200, 201}): 2,
90+
frozenset({202, 200, 199, 198}): 1}),
91+
(1, [17, 19], 6, 5, {frozenset({202, 200, 201}): 4,
92+
frozenset({202, 200, 199, 198}): 1}),
93+
(1, [17, 19, 23], 7, 6, {frozenset({202, 200, 201}): 4,
94+
frozenset({202, 200, 199, 198}): 1,
95+
frozenset({202, 200, 199}): 1}),
96+
(1, [], 4, 3, {frozenset({202, 200, 201}): 2,
97+
frozenset({202, 200, 199, 198}): 1}),
98+
])
99+
def test_set_count_group_pms(mocker, initial_unread_counts, all_msg, new_count,
100+
all_pms, unread_huddles, user_id, id_list,
101+
expected_unread_huddles, expected_all_pms,
102+
expected_all_msg, index_multiple_messages):
103+
controller = mocker.patch('zulipterminal.core.Controller.__init__')
104+
controller.model.index = index_multiple_messages
105+
106+
unread_counts = deepcopy(dict(initial_unread_counts,
107+
**{'all_msg': all_msg, 'all_pms': all_pms,
108+
'unread_huddles': unread_huddles}))
109+
expected_unread_counts = dict(initial_unread_counts,
110+
**{'all_msg': expected_all_msg,
111+
'all_pms': expected_all_pms,
112+
'unread_huddles': expected_unread_huddles
113+
})
114+
controller.model.unread_counts = unread_counts
115+
set_count(id_list, controller, new_count)
116+
assert controller.model.unread_counts == expected_unread_counts
117+
118+
82119
def test_index_messages_narrow_all_messages(mocker,
83120
messages_successful_response,
84121
index_all_messages,

0 commit comments

Comments
 (0)