1
1
from typing import Any , Dict
2
2
3
3
import pytest
4
+ from typing_extensions import Literal
4
5
from urwid import AttrMap , Overlay
5
6
6
7
from zulipterminal .config .keys import keys_for_command
@@ -406,6 +407,34 @@ def test__decode_stream_data(self, stream_data, expected_response):
406
407
407
408
assert return_value == expected_response
408
409
410
+ @pytest .mark .parametrize ('pm_data, expected_response' , [
411
+ ('1,2-pm' , dict (recipient_ids = [1 , 2 ], type = Literal ['pm' ])),
412
+ ('1,2-group' , dict (recipient_ids = [1 , 2 ], type = Literal ['pm' ])),
413
+ ('1,2,3-pm' , dict (recipient_ids = [1 , 2 , 3 ],
414
+ type = Literal ['group' ])),
415
+ ('1,2,3-group' , dict (recipient_ids = [1 , 2 , 3 ],
416
+ type = Literal ['group' ])),
417
+ ('1-user1' , dict (recipient_ids = [1 ], type = Literal ['pm' ])),
418
+ ('1-user2' , dict (recipient_ids = [1 ], type = Literal ['pm' ])),
419
+ ('1-bot-name' , dict (recipient_ids = [1 ], type = Literal ['pm' ])),
420
+ ('1-bot;name' , dict (recipient_ids = [1 ], type = Literal ['pm' ])),
421
+ ],
422
+ ids = [
423
+ 'pm_with_two_recipients' ,
424
+ 'group_pm_with_two_recipients' ,
425
+ 'pm_with_more_than_two_recipients' ,
426
+ 'group_pm_with_more_than_two_recipients' ,
427
+ 'pm_exposed_format_1_ordinary' ,
428
+ 'pm_exposed_format_1_ambigous' ,
429
+ 'pm_with_bot_exposed_format_1_ordinary' ,
430
+ 'pm_with_bot_exposed_format_1_ambigous' ,
431
+ ]
432
+ )
433
+ def test__decode_pm_data (self , pm_data , expected_response ):
434
+ return_value = MessageLinkButton ._decode_pm_data (pm_data )
435
+
436
+ assert return_value == expected_response
437
+
409
438
@pytest .mark .parametrize ('message_id, expected_return_value' , [
410
439
('1' , 1 ),
411
440
('foo' , None ),
@@ -431,6 +460,27 @@ def test__decode_message_id(self, message_id, expected_return_value):
431
460
(SERVER_URL + '/#narrow/stream/1-Stream-1/topic/foo/near/1' ,
432
461
{'narrow' : 'stream:topic:near' , 'topic_name' : 'foo' , 'message_id' : 1 ,
433
462
'stream' : {'stream_id' : 1 , 'stream_name' : None }}),
463
+ (SERVER_URL + '/#narrow/pm-with/1,2-pm' ,
464
+ {'narrow' : 'pm-with' ,
465
+ 'pm_with' : {'type' : Literal ['pm' ], 'recipient_ids' : [1 , 2 ]}}),
466
+ (SERVER_URL + '/#narrow/pm-with/1,2-group' ,
467
+ {'narrow' : 'pm-with' ,
468
+ 'pm_with' : {'type' : Literal ['pm' ], 'recipient_ids' : [1 , 2 ]}}),
469
+ (SERVER_URL + '/#narrow/pm-with/1-user1' ,
470
+ {'narrow' : 'pm-with' ,
471
+ 'pm_with' : {'type' : Literal ['pm' ], 'recipient_ids' : [1 ]}}),
472
+ (SERVER_URL + '/#narrow/pm-with/1-bot-name' ,
473
+ {'narrow' : 'pm-with' ,
474
+ 'pm_with' : {'type' : Literal ['pm' ], 'recipient_ids' : [1 ]}}),
475
+ (SERVER_URL + '/#narrow/pm-with/1,2-pm/near/1' ,
476
+ {'narrow' : 'pm-with:near' , 'message_id' : 1 ,
477
+ 'pm_with' : {'type' : Literal ['pm' ], 'recipient_ids' : [1 , 2 ]}}),
478
+ (SERVER_URL + '/#narrow/pm-with/1,2,3-pm' ,
479
+ {'narrow' : 'pm-with' ,
480
+ 'pm_with' : {'type' : Literal ['group' ], 'recipient_ids' : [1 , 2 , 3 ]}}),
481
+ (SERVER_URL + '/#narrow/pm-with/1,2,3-group' ,
482
+ {'narrow' : 'pm-with' ,
483
+ 'pm_with' : {'type' : Literal ['group' ], 'recipient_ids' : [1 , 2 , 3 ]}}),
434
484
(SERVER_URL + '/#narrow/foo' ,
435
485
{}),
436
486
(SERVER_URL + '/#narrow/stream/' ,
@@ -448,6 +498,13 @@ def test__decode_message_id(self, message_id, expected_return_value):
448
498
'topic_narrow_link' ,
449
499
'stream_near_narrow_link' ,
450
500
'topic_near_narrow_link' ,
501
+ 'pm_with_two_recipients_narrow_link' ,
502
+ 'group_pm_with_two_recipients_narrow_link' ,
503
+ 'pm_exposed_format_1_narrow_link' ,
504
+ 'pm_with_bot_exposed_format_1_narrow_link' ,
505
+ 'common_pm_near_narrow_link' ,
506
+ 'pm_with_more_than_two_recipients_narrow_link' ,
507
+ 'group_pm_with_more_than_two_recipients_narrow_link' ,
451
508
'invalid_narrow_link_1' ,
452
509
'invalid_narrow_link_2' ,
453
510
'invalid_narrow_link_3' ,
@@ -630,44 +687,83 @@ def test__validate_and_patch_stream_data(self, stream_dict, parsed_link,
630
687
'parsed_link' ,
631
688
'narrow_to_stream_called' ,
632
689
'narrow_to_topic_called' ,
690
+ 'narrow_to_user_called' ,
633
691
],
634
692
[
635
693
({'narrow' : 'stream' ,
636
694
'stream' : {'stream_id' : 1 , 'stream_name' : 'Stream 1' }},
637
695
True ,
696
+ False ,
638
697
False ),
639
698
({'narrow' : 'stream:topic' , 'topic_name' : 'Foo' ,
640
699
'stream' : {'stream_id' : 1 , 'stream_name' : 'Stream 1' }},
641
700
False ,
642
- True ),
701
+ True ,
702
+ False ),
643
703
({'narrow' : 'stream:near' , 'message_id' : 1 ,
644
704
'stream' : {'stream_id' : 1 , 'stream_name' : 'Stream 1' }},
645
705
True ,
706
+ False ,
646
707
False ),
647
708
({'narrow' : 'stream:topic:near' , 'topic_name' : 'Foo' ,
648
709
'message_id' : 1 ,
649
710
'stream' : {'stream_id' : 1 , 'stream_name' : 'Stream 1' }},
650
711
False ,
712
+ True ,
713
+ False ),
714
+ ({'narrow' : 'pm-with' ,
715
+ 'pm_with' : {'type' : Literal ['pm' ], 'recipient_ids' : [1 , 2 ]}},
716
+ False ,
717
+ False ,
718
+ True ),
719
+ ({'narrow' : 'pm-with' ,
720
+ 'pm_with' : {'type' : Literal ['group' ],
721
+ 'recipient_ids' : [1 , 2 , 3 ]}},
722
+ False ,
723
+ False ,
724
+ True ),
725
+ ({'narrow' : 'pm-with:near' , 'message_id' : 1 ,
726
+ 'pm_with' : {'type' : Literal ['pm' ], 'recipient_ids' : [1 , 2 ]}},
727
+ False ,
728
+ False ,
729
+ True ),
730
+ ({'narrow' : 'pm-with:near' , 'message_id' : 1 ,
731
+ 'pm_with' : {'type' : Literal ['group' ],
732
+ 'recipient_ids' : [1 , 2 , 3 ]}},
733
+ False ,
734
+ False ,
651
735
True ),
652
736
],
653
737
ids = [
654
738
'stream_narrow' ,
655
739
'topic_narrow' ,
656
740
'stream_near_narrow' ,
657
741
'topic_near_narrow' ,
742
+ 'pm_narrow' ,
743
+ 'group_pm_narrow' ,
744
+ 'pm_near_narrow' ,
745
+ 'group_pm_near_narrow' ,
658
746
]
659
747
)
660
748
def test__switch_narrow_to (self , parsed_link , narrow_to_stream_called ,
661
- narrow_to_topic_called ,
749
+ narrow_to_topic_called , narrow_to_user_called ,
662
750
):
663
751
mocked_button = self .message_link_button ()
752
+ # For PM narrow switch
753
+ mocked_button .model .user_id_email_dict = {
754
+
755
+
756
+
757
+ }
664
758
665
759
mocked_button ._switch_narrow_to (parsed_link )
666
760
667
761
assert (mocked_button .controller .narrow_to_stream .called
668
762
== narrow_to_stream_called )
669
763
assert (mocked_button .controller .narrow_to_topic .called
670
764
== narrow_to_topic_called )
765
+ assert (mocked_button .controller .narrow_to_user .called
766
+ == narrow_to_user_called )
671
767
672
768
@pytest .mark .parametrize (['error' , 'set_footer_text_called' ,
673
769
'_switch_narrow_to_called' ,
0 commit comments