2
2
3
3
import pytest
4
4
from pytest import param as case
5
+ from typing_extensions import Literal
5
6
from urwid import AttrMap , Overlay
6
7
7
8
from zulipterminal .config .keys import keys_for_command
@@ -364,6 +365,34 @@ def test__decode_stream_data(self, stream_data, expected_response):
364
365
365
366
assert return_value == expected_response
366
367
368
+ @pytest .mark .parametrize (
369
+ "pm_data, expected_response" ,
370
+ [
371
+ ("1,2-pm" , dict (recipient_ids = [1 , 2 ], type = Literal ["pm" ])),
372
+ ("1,2-group" , dict (recipient_ids = [1 , 2 ], type = Literal ["pm" ])),
373
+ ("1,2,3-pm" , dict (recipient_ids = [1 , 2 , 3 ], type = Literal ["group" ])),
374
+ ("1,2,3-group" , dict (recipient_ids = [1 , 2 , 3 ], type = Literal ["group" ])),
375
+ ("1-user1" , dict (recipient_ids = [1 ], type = Literal ["pm" ])),
376
+ ("1-user2" , dict (recipient_ids = [1 ], type = Literal ["pm" ])),
377
+ ("1-bot-name" , dict (recipient_ids = [1 ], type = Literal ["pm" ])),
378
+ ("1-bot;name" , dict (recipient_ids = [1 ], type = Literal ["pm" ])),
379
+ ],
380
+ ids = [
381
+ "pm_with_two_recipients" ,
382
+ "group_pm_with_two_recipients" ,
383
+ "pm_with_more_than_two_recipients" ,
384
+ "group_pm_with_more_than_two_recipients" ,
385
+ "pm_exposed_format_1_ordinary" ,
386
+ "pm_exposed_format_1_ambigous" ,
387
+ "pm_with_bot_exposed_format_1_ordinary" ,
388
+ "pm_with_bot_exposed_format_1_ambigous" ,
389
+ ],
390
+ )
391
+ def test__decode_pm_data (self , pm_data , expected_response ):
392
+ return_value = MessageLinkButton ._decode_pm_data (pm_data , 2 )
393
+
394
+ assert return_value == expected_response
395
+
367
396
@pytest .mark .parametrize (
368
397
"message_id, expected_return_value" ,
369
398
[
@@ -415,6 +444,56 @@ def test__decode_message_id(self, message_id, expected_return_value):
415
444
"stream" : {"stream_id" : 1 , "stream_name" : None },
416
445
},
417
446
),
447
+ (
448
+ SERVER_URL + "/#narrow/pm-with/1,2-pm" ,
449
+ {
450
+ "narrow" : "pm-with" ,
451
+ "pm_with" : {"type" : Literal ["pm" ], "recipient_ids" : [1 , 2 ]},
452
+ },
453
+ ),
454
+ (
455
+ SERVER_URL + "/#narrow/pm-with/1,2-group" ,
456
+ {
457
+ "narrow" : "pm-with" ,
458
+ "pm_with" : {"type" : Literal ["pm" ], "recipient_ids" : [1 , 2 ]},
459
+ },
460
+ ),
461
+ (
462
+ SERVER_URL + "/#narrow/pm-with/1-user1" ,
463
+ {
464
+ "narrow" : "pm-with" ,
465
+ "pm_with" : {"type" : Literal ["pm" ], "recipient_ids" : [1 ]},
466
+ },
467
+ ),
468
+ (
469
+ SERVER_URL + "/#narrow/pm-with/1-bot-name" ,
470
+ {
471
+ "narrow" : "pm-with" ,
472
+ "pm_with" : {"type" : Literal ["pm" ], "recipient_ids" : [1 ]},
473
+ },
474
+ ),
475
+ (
476
+ SERVER_URL + "/#narrow/pm-with/1,2-pm/near/1" ,
477
+ {
478
+ "narrow" : "pm-with:near" ,
479
+ "message_id" : 1 ,
480
+ "pm_with" : {"type" : Literal ["pm" ], "recipient_ids" : [1 , 2 ]},
481
+ },
482
+ ),
483
+ (
484
+ SERVER_URL + "/#narrow/pm-with/1,2,3-pm" ,
485
+ {
486
+ "narrow" : "pm-with" ,
487
+ "pm_with" : {"type" : Literal ["group" ], "recipient_ids" : [1 , 2 , 3 ]},
488
+ },
489
+ ),
490
+ (
491
+ SERVER_URL + "/#narrow/pm-with/1,2,3-group" ,
492
+ {
493
+ "narrow" : "pm-with" ,
494
+ "pm_with" : {"type" : Literal ["group" ], "recipient_ids" : [1 , 2 , 3 ]},
495
+ },
496
+ ),
418
497
(SERVER_URL + "/#narrow/foo" , {}),
419
498
(SERVER_URL + "/#narrow/stream/" , {}),
420
499
(SERVER_URL + "/#narrow/stream/1-Stream-1/topic/" , {}),
@@ -427,6 +506,13 @@ def test__decode_message_id(self, message_id, expected_return_value):
427
506
"topic_narrow_link" ,
428
507
"stream_near_narrow_link" ,
429
508
"topic_near_narrow_link" ,
509
+ "pm_with_two_recipients_narrow_link" ,
510
+ "group_pm_with_two_recipients_narrow_link" ,
511
+ "pm_exposed_format_1_narrow_link" ,
512
+ "pm_with_bot_exposed_format_1_narrow_link" ,
513
+ "common_pm_near_narrow_link" ,
514
+ "pm_with_more_than_two_recipients_narrow_link" ,
515
+ "group_pm_with_more_than_two_recipients_narrow_link" ,
430
516
"invalid_narrow_link_1" ,
431
517
"invalid_narrow_link_2" ,
432
518
"invalid_narrow_link_3" ,
@@ -435,7 +521,7 @@ def test__decode_message_id(self, message_id, expected_return_value):
435
521
],
436
522
)
437
523
def test__parse_narrow_link (self , link , expected_parsed_link ):
438
- return_value = MessageLinkButton ._parse_narrow_link (link )
524
+ return_value = MessageLinkButton ._parse_narrow_link (link , 1 )
439
525
440
526
assert return_value == expected_parsed_link
441
527
@@ -667,7 +753,12 @@ def test__validate_and_patch_stream_data(
667
753
assert error == expected_error
668
754
669
755
@pytest .mark .parametrize (
670
- "parsed_link, narrow_to_stream_called, narrow_to_topic_called" ,
756
+ [
757
+ "parsed_link" ,
758
+ "narrow_to_stream_called" ,
759
+ "narrow_to_topic_called" ,
760
+ "narrow_to_user_called" ,
761
+ ],
671
762
[
672
763
(
673
764
{
@@ -676,6 +767,7 @@ def test__validate_and_patch_stream_data(
676
767
},
677
768
True ,
678
769
False ,
770
+ False ,
679
771
),
680
772
(
681
773
{
@@ -685,6 +777,7 @@ def test__validate_and_patch_stream_data(
685
777
},
686
778
False ,
687
779
True ,
780
+ False ,
688
781
),
689
782
(
690
783
{
@@ -694,6 +787,7 @@ def test__validate_and_patch_stream_data(
694
787
},
695
788
True ,
696
789
False ,
790
+ False ,
697
791
),
698
792
(
699
793
{
@@ -704,29 +798,80 @@ def test__validate_and_patch_stream_data(
704
798
},
705
799
False ,
706
800
True ,
801
+ False ,
802
+ ),
803
+ (
804
+ {
805
+ "narrow" : "pm-with" ,
806
+ "pm_with" : {"type" : Literal ["pm" ], "recipient_ids" : [1 , 2 ]},
807
+ },
808
+ False ,
809
+ False ,
810
+ True ,
811
+ ),
812
+ (
813
+ {
814
+ "narrow" : "pm-with" ,
815
+ "pm_with" : {"type" : Literal ["group" ], "recipient_ids" : [1 , 2 , 3 ]},
816
+ },
817
+ False ,
818
+ False ,
819
+ True ,
820
+ ),
821
+ (
822
+ {
823
+ "narrow" : "pm-with:near" ,
824
+ "message_id" : 1 ,
825
+ "pm_with" : {"type" : Literal ["pm" ], "recipient_ids" : [1 , 2 ]},
826
+ },
827
+ False ,
828
+ False ,
829
+ True ,
830
+ ),
831
+ (
832
+ {
833
+ "narrow" : "pm-with:near" ,
834
+ "message_id" : 1 ,
835
+ "pm_with" : {"type" : Literal ["group" ], "recipient_ids" : [1 , 2 , 3 ]},
836
+ },
837
+ False ,
838
+ False ,
839
+ True ,
707
840
),
708
841
],
709
842
ids = [
710
843
"stream_narrow" ,
711
844
"topic_narrow" ,
712
845
"stream_near_narrow" ,
713
846
"topic_near_narrow" ,
847
+ "pm_narrow" ,
848
+ "group_pm_narrow" ,
849
+ "pm_near_narrow" ,
850
+ "group_pm_near_narrow" ,
714
851
],
715
852
)
716
853
def test__switch_narrow_to (
717
854
self ,
718
855
parsed_link ,
719
856
narrow_to_stream_called ,
720
857
narrow_to_topic_called ,
858
+ narrow_to_user_called ,
721
859
):
722
860
mocked_button = self .message_link_button ()
861
+ # For PM narrow switch
862
+ mocked_button .model .user_id_email_dict = {
863
+
864
+
865
+
866
+ }
723
867
724
868
mocked_button ._switch_narrow_to (parsed_link )
725
869
726
870
assert (
727
871
mocked_button .controller .narrow_to_stream .called == narrow_to_stream_called
728
872
)
729
873
assert mocked_button .controller .narrow_to_topic .called == narrow_to_topic_called
874
+ assert mocked_button .controller .narrow_to_user .called == narrow_to_user_called
730
875
731
876
@pytest .mark .parametrize (
732
877
"error, report_error_called, _switch_narrow_to_called, exit_popup_called" ,
0 commit comments