@@ -718,7 +718,6 @@ def focus_val(x: str) -> int:
718
718
if write_box .focus_position == write_box .FOCUS_CONTAINER_HEADER :
719
719
write_box .header_write_box .focus_col = (focus_val (
720
720
initial_focus_col_name ))
721
- write_box .model .get_invalid_recipient_emails .return_value = []
722
721
write_box .model .user_dict = mocker .MagicMock ()
723
722
724
723
write_box .keypress (size , tab_key )
@@ -732,6 +731,99 @@ def focus_val(x: str) -> int:
732
731
assert (write_box .FOCUS_MESSAGE_BOX_BODY
733
732
== focus_val (expected_focus_col_name ))
734
733
734
+ @pytest .mark .parametrize (['raw_recipients' , 'tidied_recipients' ], [
735
+
736
+ ('Human 2 [email protected] random text' ,
737
+
738
+ ('Human Myself [email protected] random, Human 1 <[email protected] >' ,
739
+
740
+ ('Human Myself <[email protected] >, Human 1 [email protected] random' ,
741
+
742
+ ('Human Myself [email protected] random,'
743
+ 'Human 1 [email protected] random' ,
744
+
745
+ ('Human Myself [email protected] random, Human 1 [email protected] '
746
+ 'random, Human 2 [email protected] random' ,
747
+
748
+
749
+ ('Human Myself [email protected] , Human 1 [email protected] random, '
750
+
751
+
752
+
753
+ ], ids = [
754
+ 'untidy_with_improper_formatting' ,
755
+ 'untidy_with_extra_text' ,
756
+ 'untidy_first_recipient_out_of_two' ,
757
+ 'untidy_second_recipient_out_of_two' ,
758
+ 'two_untidy_recipients' ,
759
+ 'three_untidy_recipients' ,
760
+ 'untidy_middle_recipient_out_of_three'
761
+ ])
762
+ @pytest .mark .parametrize ("tab_key" ,
763
+ keys_for_command ("CYCLE_COMPOSE_FOCUS" ))
764
+ def test_tidying_recipients_on_cycling_out (self , write_box , widget_size ,
765
+ mocker , raw_recipients ,
766
+ tidied_recipients , tab_key ):
767
+ write_box .private_box_view ()
768
+ write_box .focus_position = write_box .FOCUS_CONTAINER_HEADER
769
+ write_box .header_write_box .focus_col = (
770
+ write_box .FOCUS_HEADER_BOX_RECIPIENT
771
+ )
772
+
773
+ write_box .to_write_box .set_edit_text (raw_recipients )
774
+ write_box .to_write_box .set_edit_pos (len (raw_recipients ))
775
+
776
+ size = widget_size (write_box )
777
+ write_box .keypress (size , tab_key )
778
+
779
+ assert write_box .to_write_box .edit_text == tidied_recipients
780
+
781
+ @pytest .mark .parametrize (['raw_recipients' , 'invalid_recipients' ], [
782
+
783
+
784
+ ('Human 1' , 'Human 1' )
785
+ ], ids = [
786
+ 'name_email_mismatch' ,
787
+ 'no_name_specified' ,
788
+ 'no_email_specified'
789
+ ])
790
+ @pytest .mark .parametrize ("tab_key" ,
791
+ keys_for_command ("CYCLE_COMPOSE_FOCUS" ))
792
+ def test_footer_notification_on_invalid_recipients (self , write_box ,
793
+ tab_key , mocker ,
794
+ widget_size ,
795
+ raw_recipients ,
796
+ invalid_recipients ):
797
+
798
+ write_box .model .check_recipient_validity = mocker .Mock (
799
+ return_value = False
800
+ )
801
+
802
+ write_box .private_box_view ()
803
+ write_box .focus_position = write_box .FOCUS_CONTAINER_HEADER
804
+ write_box .header_write_box .focus_col = (
805
+ write_box .FOCUS_HEADER_BOX_RECIPIENT
806
+ )
807
+
808
+ write_box .to_write_box .edit_text = raw_recipients
809
+ write_box .to_write_box .set_edit_pos (len (raw_recipients ))
810
+ size = widget_size (write_box )
811
+ write_box .keypress (size , tab_key )
812
+
813
+ expected_lines = [
814
+ 'Invalid recipient(s) - ' + invalid_recipients , ' - Use ' ,
815
+ ('code' , primary_key_for_command ('AUTOCOMPLETE' )), ' or ' ,
816
+ ('code' , primary_key_for_command ('AUTOCOMPLETE_REVERSE' )),
817
+ ' to autocomplete.'
818
+ ]
819
+
820
+ self .view .set_footer_text .assert_called_once_with (expected_lines , 3 )
821
+ # If there are invalid recipients, we expect the focus
822
+ # to remain in the to_write_box.
823
+ assert write_box .focus_position == write_box .FOCUS_CONTAINER_HEADER
824
+ assert (write_box .header_write_box .focus_col
825
+ == write_box .FOCUS_HEADER_BOX_RECIPIENT )
826
+
735
827
@pytest .mark .parametrize (["msg_type" , "expected_box_size" ], [
736
828
('private' , 1 ),
737
829
('stream' , 4 ),
0 commit comments