|
7 | 7 | from pytest import param as case
|
8 | 8 | from zulip import Client, ZulipError
|
9 | 9 |
|
| 10 | +from zulipterminal.api_types import RESOLVED_TOPIC_PREFIX |
10 | 11 | from zulipterminal.config.symbols import STREAM_TOPIC_SEPARATOR
|
11 | 12 | from zulipterminal.helper import initial_index, powerset
|
12 | 13 | from zulipterminal.model import (
|
@@ -1259,6 +1260,87 @@ def test_can_user_edit_topic(
|
1259 | 1260 | else:
|
1260 | 1261 | report_error.assert_called_once_with(expected_response[user_type][0])
|
1261 | 1262 |
|
| 1263 | + @pytest.mark.parametrize( |
| 1264 | + "topic_name, msg_response, server_feature_level, topic_editing_limit_seconds," |
| 1265 | + " expected_new_topic_name, expected_footer_error", |
| 1266 | + [ |
| 1267 | + case( |
| 1268 | + "hi!", |
| 1269 | + { |
| 1270 | + "subject": "hi!", |
| 1271 | + "timestamp": 11662271397, |
| 1272 | + "id": 1, |
| 1273 | + }, |
| 1274 | + 12, |
| 1275 | + 259200, |
| 1276 | + RESOLVED_TOPIC_PREFIX + "hi!", |
| 1277 | + None, |
| 1278 | + id="topic_resolved:Zulip2.1+:ZFL12", |
| 1279 | + ), |
| 1280 | + case( |
| 1281 | + "hi!", |
| 1282 | + { |
| 1283 | + "subject": "hi!", |
| 1284 | + "timestamp": 0, |
| 1285 | + "id": 1, |
| 1286 | + }, |
| 1287 | + None, |
| 1288 | + None, |
| 1289 | + RESOLVED_TOPIC_PREFIX + "hi!", |
| 1290 | + None, |
| 1291 | + id="no_time_limit:Zulip2.1+:None", |
| 1292 | + ), |
| 1293 | + case( |
| 1294 | + RESOLVED_TOPIC_PREFIX + "hi!", |
| 1295 | + { |
| 1296 | + "subject": RESOLVED_TOPIC_PREFIX + "hi!", |
| 1297 | + "timestamp": 11662271397, |
| 1298 | + "id": 1, |
| 1299 | + }, |
| 1300 | + 10, |
| 1301 | + 86400, |
| 1302 | + "hi!", |
| 1303 | + None, |
| 1304 | + id="topic_unresolved:Zulip2.1+:ZFL10", |
| 1305 | + ), |
| 1306 | + ], |
| 1307 | + ) |
| 1308 | + def test_toggle_topic_resolve_status( |
| 1309 | + self, |
| 1310 | + mocker, |
| 1311 | + model, |
| 1312 | + initial_data, |
| 1313 | + topic_name, |
| 1314 | + msg_response, |
| 1315 | + server_feature_level, |
| 1316 | + topic_editing_limit_seconds, |
| 1317 | + expected_new_topic_name, |
| 1318 | + expected_footer_error, |
| 1319 | + stream_id=1, |
| 1320 | + ): |
| 1321 | + model.initial_data = initial_data |
| 1322 | + model.server_feature_level = server_feature_level |
| 1323 | + initial_data[ |
| 1324 | + "realm_community_topic_editing_limit_seconds" |
| 1325 | + ] = topic_editing_limit_seconds |
| 1326 | + # If user can't edit topic, topic (un)resolve is disabled. Therefore, |
| 1327 | + # default return_value=True |
| 1328 | + model.can_user_edit_topic = mocker.Mock(return_value=True) |
| 1329 | + model.get_latest_message_in_topic = mocker.Mock(return_value=msg_response) |
| 1330 | + model.update_stream_message = mocker.Mock(return_value={"result": "success"}) |
| 1331 | + report_error = model.controller.report_error |
| 1332 | + |
| 1333 | + model.toggle_topic_resolve_status(stream_id, topic_name) |
| 1334 | + |
| 1335 | + if not expected_footer_error: |
| 1336 | + model.update_stream_message.assert_called_once_with( |
| 1337 | + message_id=msg_response["id"], |
| 1338 | + topic=expected_new_topic_name, |
| 1339 | + propagate_mode="change_all", |
| 1340 | + ) |
| 1341 | + else: |
| 1342 | + report_error.assert_called_once_with(expected_footer_error) |
| 1343 | + |
1262 | 1344 | # NOTE: This tests only getting next-unread, not a fixed anchor
|
1263 | 1345 | def test_success_get_messages(
|
1264 | 1346 | self,
|
|
0 commit comments