@@ -444,6 +444,56 @@ def test__decode_message_id(self, message_id, expected_return_value):
444
444
"stream" : {"stream_id" : 1 , "stream_name" : None },
445
445
},
446
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
+ ),
447
497
(SERVER_URL + "/#narrow/foo" , {}),
448
498
(SERVER_URL + "/#narrow/stream/" , {}),
449
499
(SERVER_URL + "/#narrow/stream/1-Stream-1/topic/" , {}),
@@ -456,6 +506,13 @@ def test__decode_message_id(self, message_id, expected_return_value):
456
506
"topic_narrow_link" ,
457
507
"stream_near_narrow_link" ,
458
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" ,
459
516
"invalid_narrow_link_1" ,
460
517
"invalid_narrow_link_2" ,
461
518
"invalid_narrow_link_3" ,
@@ -464,7 +521,7 @@ def test__decode_message_id(self, message_id, expected_return_value):
464
521
],
465
522
)
466
523
def test__parse_narrow_link (self , link , expected_parsed_link ):
467
- return_value = MessageLinkButton ._parse_narrow_link (link )
524
+ return_value = MessageLinkButton ._parse_narrow_link (link , 1 )
468
525
469
526
assert return_value == expected_parsed_link
470
527
@@ -696,7 +753,12 @@ def test__validate_and_patch_stream_data(
696
753
assert error == expected_error
697
754
698
755
@pytest .mark .parametrize (
699
- "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
+ ],
700
762
[
701
763
(
702
764
{
@@ -705,6 +767,7 @@ def test__validate_and_patch_stream_data(
705
767
},
706
768
True ,
707
769
False ,
770
+ False ,
708
771
),
709
772
(
710
773
{
@@ -714,6 +777,7 @@ def test__validate_and_patch_stream_data(
714
777
},
715
778
False ,
716
779
True ,
780
+ False ,
717
781
),
718
782
(
719
783
{
@@ -723,6 +787,7 @@ def test__validate_and_patch_stream_data(
723
787
},
724
788
True ,
725
789
False ,
790
+ False ,
726
791
),
727
792
(
728
793
{
@@ -733,29 +798,83 @@ def test__validate_and_patch_stream_data(
733
798
},
734
799
False ,
735
800
True ,
801
+ False ,
802
+ ),
803
+ (
804
+ {
805
+ "narrow" : "pm-with" ,
806
+ "pm_with" : {"type" : Literal ["pm" ], "recipient_ids" : [11 , 12 ]},
807
+ },
808
+ False ,
809
+ False ,
810
+ True ,
811
+ ),
812
+ (
813
+ {
814
+ "narrow" : "pm-with" ,
815
+ "pm_with" : {
816
+ "type" : Literal ["group" ],
817
+ "recipient_ids" : [11 , 12 , 13 ],
818
+ },
819
+ },
820
+ False ,
821
+ False ,
822
+ True ,
823
+ ),
824
+ (
825
+ {
826
+ "narrow" : "pm-with:near" ,
827
+ "message_id" : 1 ,
828
+ "pm_with" : {"type" : Literal ["pm" ], "recipient_ids" : [11 , 12 ]},
829
+ },
830
+ False ,
831
+ False ,
832
+ True ,
833
+ ),
834
+ (
835
+ {
836
+ "narrow" : "pm-with:near" ,
837
+ "message_id" : 1 ,
838
+ "pm_with" : {
839
+ "type" : Literal ["group" ],
840
+ "recipient_ids" : [11 , 12 , 13 ],
841
+ },
842
+ },
843
+ False ,
844
+ False ,
845
+ True ,
736
846
),
737
847
],
738
848
ids = [
739
849
"stream_narrow" ,
740
850
"topic_narrow" ,
741
851
"stream_near_narrow" ,
742
852
"topic_near_narrow" ,
853
+ "pm_narrow" ,
854
+ "group_pm_narrow" ,
855
+ "pm_near_narrow" ,
856
+ "group_pm_near_narrow" ,
743
857
],
744
858
)
745
859
def test__switch_narrow_to (
746
860
self ,
747
861
parsed_link ,
748
862
narrow_to_stream_called ,
749
863
narrow_to_topic_called ,
864
+ narrow_to_user_called ,
865
+ _all_users_by_id ,
750
866
):
751
867
mocked_button = self .message_link_button ()
868
+ # For PM narrow switch
869
+ mocked_button .model ._all_users_by_id = _all_users_by_id
752
870
753
871
mocked_button ._switch_narrow_to (parsed_link )
754
872
755
873
assert (
756
874
mocked_button .controller .narrow_to_stream .called == narrow_to_stream_called
757
875
)
758
876
assert mocked_button .controller .narrow_to_topic .called == narrow_to_topic_called
877
+ assert mocked_button .controller .narrow_to_user .called == narrow_to_user_called
759
878
760
879
@pytest .mark .parametrize (
761
880
"error, report_error_called, _switch_narrow_to_called, exit_popup_called" ,
0 commit comments