Skip to content

Commit c80774f

Browse files
author
Subhasish-Behera
committed
test_helper: Added tests for analyse_edit_history.
It tests the possible scenarios for the function.
1 parent a447fed commit c80774f

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

tests/helper/test_helper.py

Lines changed: 130 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,135 @@ 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+
(
119+
False,
120+
True,
121+
None,
122+
None,
123+
{"edited_messages": {12345}, "moved_messages": set()},
124+
),
125+
(
126+
True,
127+
False,
128+
None,
129+
None,
130+
{"edited_messages": {12345}, "moved_messages": set()},
131+
),
132+
(
133+
True,
134+
True,
135+
"Topic B",
136+
"Topic C",
137+
{"edited_messages": {12345}, "moved_messages": set()},
138+
),
139+
(
140+
True,
141+
False,
142+
"Topic B",
143+
"Topic C",
144+
{"edited_messages": {12345}, "moved_messages": set()},
145+
),
146+
(
147+
False,
148+
False,
149+
"Topic D",
150+
"Topic E",
151+
{"edited_messages": set(), "moved_messages": {12345}},
152+
),
153+
(
154+
False,
155+
True,
156+
"Topic F",
157+
"Topic G",
158+
{"edited_messages": {12345}, "moved_messages": set()},
159+
),
160+
(
161+
False,
162+
False,
163+
"✔ Topic I",
164+
"✔ Topic J",
165+
{"edited_messages": set(), "moved_messages": {12345}},
166+
),
167+
(
168+
False,
169+
False,
170+
"Topic K",
171+
"Topic L",
172+
{"edited_messages": set(), "moved_messages": {12345}},
173+
),
174+
(
175+
False,
176+
False,
177+
"✔ Topic M",
178+
"Topic M",
179+
{"edited_messages": set(), "moved_messages": set()},
180+
),
181+
(
182+
False,
183+
False,
184+
"Topic M",
185+
"✔ Topic M",
186+
{"edited_messages": set(), "moved_messages": set()},
187+
),
188+
(
189+
False,
190+
False,
191+
"✔ Topic N",
192+
"Topic M",
193+
{"edited_messages": set(), "moved_messages": {12345}},
194+
),
195+
(
196+
False,
197+
False,
198+
"Topic M",
199+
"✔ Topic N",
200+
{"edited_messages": set(), "moved_messages": {12345}},
201+
),
202+
],
203+
ids=[
204+
"only stream changed",
205+
"only content changed",
206+
"both stream and content changed",
207+
"both content and topic changed",
208+
"actual topic change",
209+
"topic and stream changed",
210+
"topic changed from resolved to resolved but different topic",
211+
"topic changed when both are unresolved",
212+
"only resolved topic to unresolved topic",
213+
"only unresolved topic to resolved topic",
214+
"resolved topic to changed unresolved topic",
215+
"unresolved topic to changed resolved topic",
216+
],
217+
)
218+
def test_analyse_edit_history(
219+
content_changed: bool,
220+
stream_changed: bool,
221+
current_topic: str,
222+
old_topic: str,
223+
expected_result: Dict[str, Any],
224+
initial_index: Index,
225+
) -> None:
226+
msg_id = 12345
227+
expected_index = dict(
228+
initial_index,
229+
edited_messages=expected_result["edited_messages"],
230+
moved_messages=expected_result["moved_messages"],
231+
)
232+
analyse_edit_history(
233+
msg_id,
234+
initial_index,
235+
content_changed,
236+
stream_changed,
237+
current_topic,
238+
old_topic,
239+
)
240+
241+
assert initial_index == expected_index
242+
243+
114244
@pytest.mark.parametrize(
115245
"edited_msgs",
116246
[

0 commit comments

Comments
 (0)