Skip to content

Commit a616169

Browse files
committed
model: Improve reporting upon moving topic.
1 parent 62d2e75 commit a616169

File tree

2 files changed

+94
-5
lines changed

2 files changed

+94
-5
lines changed

tests/model/test_model.py

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ def test_update_private_message(
827827
],
828828
)
829829
@pytest.mark.parametrize(
830-
"req, old_topic, footer_updated",
830+
"req, old_topic, new_topic, stream_name, no_of_messages, footer_updated",
831831
[
832832
(
833833
{
@@ -837,6 +837,15 @@ def test_update_private_message(
837837
"topic": "Some topic",
838838
},
839839
"Some topic",
840+
"Some topic",
841+
"stream",
842+
{
843+
"1": 1,
844+
"2": 2,
845+
"3": 3,
846+
"4": 4,
847+
"5": 5,
848+
},
840849
False,
841850
),
842851
(
@@ -846,11 +855,33 @@ def test_update_private_message(
846855
"topic": "Topic change",
847856
},
848857
"Old topic",
858+
"Topic change",
859+
"stream",
860+
{
861+
"1": 1,
862+
"2": 2,
863+
"3": 3,
864+
"4": 4,
865+
"5": 5,
866+
},
849867
True,
850868
),
851869
(
852-
{"message_id": 1, "propagate_mode": "change_all", "topic": "Old topic"},
870+
{
871+
"message_id": 1,
872+
"propagate_mode": "change_all",
873+
"topic": "Old topic",
874+
},
875+
"Old topic",
853876
"Old topic",
877+
"stream",
878+
{
879+
"1": 1,
880+
"2": 2,
881+
"3": 3,
882+
"4": 4,
883+
"5": 5,
884+
},
854885
False,
855886
),
856887
(
@@ -861,6 +892,15 @@ def test_update_private_message(
861892
"topic": "terminal",
862893
},
863894
"terminal",
895+
"terminal",
896+
"stream",
897+
{
898+
"1": 1,
899+
"2": 2,
900+
"3": 3,
901+
"4": 4,
902+
"5": 5,
903+
},
864904
False,
865905
),
866906
(
@@ -871,6 +911,15 @@ def test_update_private_message(
871911
"topic": "grett",
872912
},
873913
"greet",
914+
"grett",
915+
"stream",
916+
{
917+
"1": 1,
918+
"2": 2,
919+
"3": 3,
920+
"4": 4,
921+
"5": 5,
922+
},
874923
True,
875924
),
876925
(
@@ -881,15 +930,37 @@ def test_update_private_message(
881930
"topic": "party",
882931
},
883932
"lets_party",
933+
"party",
934+
"stream",
935+
{
936+
"1": 1,
937+
"2": 2,
938+
"3": 3,
939+
"4": 4,
940+
"5": 5,
941+
},
884942
True,
885943
),
886944
],
887945
)
888946
def test_update_stream_message(
889-
self, mocker, model, response, return_value, req, old_topic, footer_updated
947+
self,
948+
mocker,
949+
model,
950+
response,
951+
return_value,
952+
req,
953+
old_topic,
954+
new_topic,
955+
stream_name,
956+
no_of_messages,
957+
footer_updated,
890958
):
891959
self.client.update_message = mocker.Mock(return_value=response)
892960
model.index["messages"][req["message_id"]]["subject"] = old_topic
961+
req["topic"] = new_topic
962+
model.index["messages"][req["message_id"]]["display_recipient"] = stream_name
963+
model.index["edited_messages"] = no_of_messages
893964

894965
result = model.update_stream_message(**req)
895966

@@ -898,7 +969,19 @@ def test_update_stream_message(
898969
self.display_error_if_present.assert_called_once_with(response, self.controller)
899970
report_success = model.controller.report_success
900971
if result and footer_updated:
901-
report_success.assert_called_once_with("You changed a message's topic.")
972+
report_success.assert_called_once_with(
973+
"You changed "
974+
+ str(len(no_of_messages))
975+
+ " message's topic from #"
976+
+ stream_name
977+
+ " > "
978+
+ old_topic
979+
+ " to #"
980+
+ stream_name
981+
+ " > "
982+
+ new_topic
983+
+ "."
984+
)
902985
else:
903986
report_success.assert_not_called()
904987

zulipterminal/model.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,14 @@ def update_stream_message(
567567
if response["result"] == "success":
568568
old_topic = self.index["messages"][message_id].get("subject", None)
569569
new_topic = request["topic"]
570+
stream_name = self.index["messages"][message_id].get(
571+
"display_recipient", None
572+
)
573+
no_of_messages = len(self.index["edited_messages"])
570574
if old_topic != new_topic:
571-
self.controller.report_success("You changed a message's topic.")
575+
self.controller.report_success(
576+
f"You changed {no_of_messages} message's topic from #{stream_name} > {old_topic} to #{stream_name} > {new_topic}."
577+
)
572578

573579
return response["result"] == "success"
574580

0 commit comments

Comments
 (0)