25
25
)
26
26
from zulipterminal .config .ui_mappings import StreamAccessType
27
27
from zulipterminal .helper import Index , MinimalUserData
28
- from zulipterminal .ui_tools .boxes import PanelSearchBox , WriteBox , _MessageEditState
28
+ from zulipterminal .ui_tools .boxes import (
29
+ MAX_MESSAGE_LENGTH_CONFIRMATION_POPUP ,
30
+ PanelSearchBox ,
31
+ WriteBox ,
32
+ _MessageEditState ,
33
+ )
29
34
from zulipterminal .urwid_types import urwid_Size
30
35
31
36
@@ -236,7 +241,7 @@ def test_not_calling_send_private_message_without_recipients(
236
241
assert not write_box .model .send_private_message .called
237
242
238
243
@pytest .mark .parametrize ("key" , keys_for_command ("EXIT_COMPOSE" ))
239
- def test__compose_attributes_reset_for_private_compose (
244
+ def test__compose_attributes_reset_for_private_compose__no_popup (
240
245
self ,
241
246
key : str ,
242
247
mocker : MockerFixture ,
@@ -247,17 +252,41 @@ def test__compose_attributes_reset_for_private_compose(
247
252
mocker .patch ("urwid.connect_signal" )
248
253
write_box .model .user_id_email_dict = user_id_email_dict
249
254
write_box .private_box_view (recipient_user_ids = [11 ])
250
- write_box .msg_write_box .edit_text = "random text"
255
+
256
+ write_box .msg_write_box .edit_text = "." * (
257
+ MAX_MESSAGE_LENGTH_CONFIRMATION_POPUP - 1
258
+ )
251
259
252
260
size = widget_size (write_box )
253
261
write_box .keypress (size , key )
254
262
263
+ write_box .view .controller .exit_compose_confirmation_popup .assert_not_called ()
255
264
assert write_box .to_write_box is None
256
265
assert write_box .msg_write_box .edit_text == ""
257
266
assert write_box .compose_box_status == "closed"
258
267
259
268
@pytest .mark .parametrize ("key" , keys_for_command ("EXIT_COMPOSE" ))
260
- def test__compose_attributes_reset_for_stream_compose (
269
+ def test__compose_attributes_reset_for_private_compose__popup (
270
+ self ,
271
+ key : str ,
272
+ mocker : MockerFixture ,
273
+ write_box : WriteBox ,
274
+ widget_size : Callable [[Widget ], urwid_Size ],
275
+ user_id_email_dict : Dict [int , str ],
276
+ ) -> None :
277
+ mocker .patch ("urwid.connect_signal" )
278
+ write_box .model .user_id_email_dict = user_id_email_dict
279
+ write_box .private_box_view (recipient_user_ids = [11 ])
280
+
281
+ write_box .msg_write_box .edit_text = "." * MAX_MESSAGE_LENGTH_CONFIRMATION_POPUP
282
+
283
+ size = widget_size (write_box )
284
+ write_box .keypress (size , key )
285
+
286
+ write_box .view .controller .exit_compose_confirmation_popup .assert_called_once ()
287
+
288
+ @pytest .mark .parametrize ("key" , keys_for_command ("EXIT_COMPOSE" ))
289
+ def test__compose_attributes_reset_for_stream_compose__no_popup (
261
290
self ,
262
291
key : str ,
263
292
mocker : MockerFixture ,
@@ -266,15 +295,37 @@ def test__compose_attributes_reset_for_stream_compose(
266
295
) -> None :
267
296
mocker .patch (WRITEBOX + "._set_stream_write_box_style" )
268
297
write_box .stream_box_view (stream_id = 1 )
269
- write_box .msg_write_box .edit_text = "random text"
298
+
299
+ write_box .msg_write_box .edit_text = "." * (
300
+ MAX_MESSAGE_LENGTH_CONFIRMATION_POPUP - 1
301
+ )
270
302
271
303
size = widget_size (write_box )
272
304
write_box .keypress (size , key )
273
305
306
+ write_box .view .controller .exit_compose_confirmation_popup .assert_not_called ()
274
307
assert write_box .stream_id is None
275
308
assert write_box .msg_write_box .edit_text == ""
276
309
assert write_box .compose_box_status == "closed"
277
310
311
+ @pytest .mark .parametrize ("key" , keys_for_command ("EXIT_COMPOSE" ))
312
+ def test__compose_attributes_reset_for_stream_compose__popup (
313
+ self ,
314
+ key : str ,
315
+ mocker : MockerFixture ,
316
+ write_box : WriteBox ,
317
+ widget_size : Callable [[Widget ], urwid_Size ],
318
+ ) -> None :
319
+ mocker .patch (WRITEBOX + "._set_stream_write_box_style" )
320
+ write_box .stream_box_view (stream_id = 1 )
321
+
322
+ write_box .msg_write_box .edit_text = "." * MAX_MESSAGE_LENGTH_CONFIRMATION_POPUP
323
+
324
+ size = widget_size (write_box )
325
+ write_box .keypress (size , key )
326
+
327
+ write_box .view .controller .exit_compose_confirmation_popup .assert_called_once_with ()
328
+
278
329
@pytest .mark .parametrize (
279
330
["raw_recipients" , "tidied_recipients" ],
280
331
[
@@ -1523,23 +1574,26 @@ def test_keypress_SEND_MESSAGE_no_topic(
1523
1574
)
1524
1575
def test_keypress_typeahead_mode_autocomplete_key (
1525
1576
self ,
1577
+ mocker : MockerFixture ,
1526
1578
write_box : WriteBox ,
1527
1579
widget_size : Callable [[Widget ], urwid_Size ],
1528
1580
current_typeahead_mode : bool ,
1529
1581
expected_typeahead_mode : bool ,
1530
1582
expect_footer_was_reset : bool ,
1531
1583
key : str ,
1532
1584
) -> None :
1585
+ write_box .msg_write_box = mocker .Mock (edit_text = "" )
1533
1586
write_box .is_in_typeahead_mode = current_typeahead_mode
1534
1587
size = widget_size (write_box )
1535
1588
1536
1589
write_box .keypress (size , key )
1537
1590
1538
1591
assert write_box .is_in_typeahead_mode == expected_typeahead_mode
1539
1592
if expect_footer_was_reset :
1540
- self .view .set_footer_text .assert_called_once_with ()
1593
+ # We may prefer called-once in future, but the key part is that we do reset
1594
+ assert self .view .set_footer_text .called
1541
1595
else :
1542
- self .view .set_footer_text .assert_not_called ()
1596
+ assert not self .view .set_footer_text .called
1543
1597
1544
1598
@pytest .mark .parametrize (
1545
1599
[
0 commit comments