Skip to content

Commit e74353b

Browse files
author
Subhasish-Behera
committed
test_helper: Added tests for analyse_edit_history.
It tests the possible scenarios for the function as expressed in the test ids.
1 parent 1057990 commit e74353b

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,
@@ -111,6 +112,133 @@ def test_index_messages_narrow_user_multiple(
111112
assert index_messages(messages, model, model.index) == index_user_multiple
112113

113114

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

0 commit comments

Comments
 (0)