Skip to content

Commit 1a940dc

Browse files
Subhasish-Beheraneiljp
authored andcommitted
test_helper: Added tests for analyse_edit_history.
It tests the possible scenarios for the function as expressed in the test ids.
1 parent 47b451d commit 1a940dc

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

tests/helper/test_helper.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from zulipterminal.config.keys import primary_key_for_command
99
from zulipterminal.helper import (
1010
Index,
11+
analyse_edit_history,
1112
canonicalize_color,
1213
classify_unread_counts,
1314
display_error_if_present,
@@ -112,6 +113,133 @@ def test_index_messages_narrow_user_multiple(
112113
assert index_messages(messages, model, model.index) == index_user_multiple
113114

114115

116+
@pytest.mark.parametrize(
117+
("content_changed, stream_changed, old_topic, current_topic, expected_result"),
118+
[
119+
case(
120+
False,
121+
True,
122+
None,
123+
None,
124+
{"edited_messages": {12345}, "moved_messages": set()},
125+
id="only_stream_changed",
126+
),
127+
case(
128+
True,
129+
False,
130+
None,
131+
None,
132+
{"edited_messages": {12345}, "moved_messages": set()},
133+
id="only_content_changed",
134+
),
135+
case(
136+
True,
137+
True,
138+
"Topic B",
139+
"Topic C",
140+
{"edited_messages": {12345}, "moved_messages": set()},
141+
id="both_stream_and_content_changed",
142+
),
143+
case(
144+
True,
145+
False,
146+
"Topic B",
147+
"Topic C",
148+
{"edited_messages": {12345}, "moved_messages": set()},
149+
id="both_content_and_topic_changed",
150+
),
151+
case(
152+
False,
153+
False,
154+
"Topic D",
155+
"Topic E",
156+
{"edited_messages": set(), "moved_messages": {12345}},
157+
id="actual_topic_change",
158+
),
159+
case(
160+
False,
161+
True,
162+
"Topic F",
163+
"Topic G",
164+
{"edited_messages": {12345}, "moved_messages": set()},
165+
id="topic_and_stream_changed",
166+
),
167+
case(
168+
False,
169+
False,
170+
"✔ Topic I",
171+
"✔ Topic J",
172+
{"edited_messages": set(), "moved_messages": {12345}},
173+
id="topic_changed_from_resolved_to resolved_but_different_topic",
174+
),
175+
case(
176+
False,
177+
False,
178+
"Topic K",
179+
"Topic L",
180+
{"edited_messages": set(), "moved_messages": {12345}},
181+
id="topic_changed_when_both_are_unresolved",
182+
),
183+
case(
184+
False,
185+
False,
186+
"✔ Topic M",
187+
"Topic M",
188+
{"edited_messages": set(), "moved_messages": set()},
189+
id="only_resolved_topic_to_unresolved_topic",
190+
),
191+
case(
192+
False,
193+
False,
194+
"Topic M",
195+
"✔ Topic M",
196+
{"edited_messages": set(), "moved_messages": set()},
197+
id="only_unresolved_topic_to_resolved_topic",
198+
),
199+
case(
200+
False,
201+
False,
202+
"✔ Topic N",
203+
"Topic M",
204+
{"edited_messages": set(), "moved_messages": {12345}},
205+
id="resolved_topic_to_changed_unresolved_topic",
206+
),
207+
case(
208+
False,
209+
False,
210+
"Topic M",
211+
"✔ Topic N",
212+
{"edited_messages": set(), "moved_messages": {12345}},
213+
id="unresolved_topic_to_changed_resolved_topic",
214+
),
215+
],
216+
)
217+
def test_analyse_edit_history(
218+
content_changed: bool,
219+
stream_changed: bool,
220+
current_topic: str,
221+
old_topic: str,
222+
expected_result: Dict[str, Any],
223+
initial_index: Index,
224+
) -> None:
225+
msg_id = 12345
226+
expected_index = dict(
227+
initial_index,
228+
edited_messages=expected_result["edited_messages"],
229+
moved_messages=expected_result["moved_messages"],
230+
)
231+
analyse_edit_history(
232+
msg_id,
233+
initial_index,
234+
content_changed,
235+
stream_changed,
236+
current_topic,
237+
old_topic,
238+
)
239+
240+
assert initial_index == expected_index
241+
242+
115243
@pytest.mark.parametrize(
116244
"edited_msgs",
117245
[

0 commit comments

Comments
 (0)