@@ -568,64 +568,35 @@ def test_mouse_event(self, mocker, stream_view, widget_size):
568
568
def test_keypress_SEARCH_STREAMS (self , mocker , stream_view , key , widget_size ):
569
569
size = widget_size (stream_view )
570
570
mocker .patch .object (stream_view , "set_focus" )
571
+ stream_view .log .extend (["FOO" , "foo" , "fan" , "boo" , "BOO" ])
572
+ stream_view .log .set_focus (3 )
573
+
571
574
stream_view .keypress (size , key )
575
+
576
+ assert stream_view .focus_index_before_search == 3
572
577
stream_view .set_focus .assert_called_once_with ("header" )
573
578
574
579
@pytest .mark .parametrize ("key" , keys_for_command ("GO_BACK" ))
575
580
def test_keypress_GO_BACK (self , mocker , stream_view , key , widget_size ):
576
581
size = widget_size (stream_view )
577
582
mocker .patch .object (stream_view , "set_focus" )
578
583
mocker .patch .object (stream_view .stream_search_box , "reset_search_text" )
579
- stream_view .keypress (size , key )
580
- stream_view .set_focus .assert_called_once_with ("body" )
581
- assert stream_view .stream_search_box .reset_search_text .called
582
- assert stream_view .log == self .streams_btn_list
584
+ stream_view .streams_btn_list = ["FOO" , "foo" , "fan" , "boo" , "BOO" ]
585
+ stream_view .focus_index_before_search = 3
583
586
584
- @pytest .mark .parametrize ("search_streams_key" , keys_for_command ("SEARCH_STREAMS" ))
585
- @pytest .mark .parametrize ("go_back_key" , keys_for_command ("GO_BACK" ))
586
- @pytest .mark .parametrize (
587
- "current_focus, stream" ,
588
- [
589
- (0 , "FOO" ),
590
- (2 , "fan" ),
591
- (4 , "BOO" ),
592
- ],
593
- )
594
- def test_return_to_focus_after_search (
595
- self ,
596
- mocker ,
597
- stream_view ,
598
- widget_size ,
599
- current_focus ,
600
- stream ,
601
- search_streams_key ,
602
- go_back_key ,
603
- ):
604
- # Initialize log
605
- stream_view .streams_btn_list = [
606
- mocker .Mock (stream_name = stream_name )
607
- for stream_name in ["FOO" , "foo" , "fan" , "boo" , "BOO" ]
608
- ]
609
- stream_view .log .extend (stream_view .streams_btn_list )
610
-
611
- # Set initial stream focus to 'current_focus' and name to 'stream'
612
- stream_view .log .set_focus (current_focus )
613
- stream_view .focus_index_before_search = current_focus
614
- previous_focus = stream_view .log .get_focus ()[1 ]
615
- previous_focus_stream_name = stream
587
+ # During search
588
+ stream_view .log .clear ()
589
+ stream_view .log .extend (stream_view .streams_btn_list [3 ])
590
+ stream_view .log .set_focus (1 )
616
591
617
- # Toggle Stream Search
618
- size = widget_size (stream_view )
619
- stream_view .keypress (size , search_streams_key )
620
-
621
- # Exit Stream Search
622
- stream_view .keypress (size , go_back_key )
592
+ # Exit search
593
+ stream_view .keypress (size , key )
623
594
624
- # Obtain new stream focus
625
- new_focus = stream_view .log . get_focus ()[ 1 ]
626
- new_focus_stream_name = stream_view .log [ new_focus ]. stream_name
627
- assert new_focus == previous_focus
628
- assert previous_focus_stream_name == new_focus_stream_name
595
+ # Check state reset after search
596
+ stream_view .set_focus . assert_called_once_with ( "body" )
597
+ assert stream_view .stream_search_box . reset_search_text . called
598
+ assert stream_view . log == stream_view . streams_btn_list
599
+ assert stream_view . log . get_focus ()[ 1 ] == stream_view . focus_index_before_search
629
600
630
601
631
602
class TestTopicsView :
@@ -741,65 +712,36 @@ def test_keypress_GO_RIGHT(self, mocker, topic_view, key, widget_size):
741
712
def test_keypress_SEARCH_TOPICS (self , mocker , topic_view , key , widget_size ):
742
713
size = widget_size (topic_view )
743
714
mocker .patch (VIEWS + ".TopicsView.set_focus" )
715
+ topic_view .log .extend (["FOO" , "foo" , "fan" , "boo" , "BOO" ])
716
+ topic_view .log .set_focus (3 )
717
+
744
718
topic_view .keypress (size , key )
719
+
745
720
topic_view .set_focus .assert_called_once_with ("header" )
746
721
topic_view .header_list .set_focus .assert_called_once_with (2 )
722
+ assert topic_view .focus_index_before_search == 3
747
723
748
724
@pytest .mark .parametrize ("key" , keys_for_command ("GO_BACK" ))
749
725
def test_keypress_GO_BACK (self , mocker , topic_view , key , widget_size ):
750
726
size = widget_size (topic_view )
751
727
mocker .patch (VIEWS + ".TopicsView.set_focus" )
752
728
mocker .patch .object (topic_view .topic_search_box , "reset_search_text" )
753
- topic_view .keypress (size , key )
754
- topic_view .set_focus .assert_called_once_with ("body" )
755
- assert topic_view .topic_search_box .reset_search_text .called
756
- assert topic_view .log == self .topics_btn_list
729
+ topic_view .topics_btn_list = ["FOO" , "foo" , "fan" , "boo" , "BOO" ]
730
+ topic_view .focus_index_before_search = 3
757
731
758
- @pytest .mark .parametrize ("search_topics_key" , keys_for_command ("SEARCH_TOPICS" ))
759
- @pytest .mark .parametrize ("go_back_key" , keys_for_command ("GO_BACK" ))
760
- @pytest .mark .parametrize (
761
- "current_focus, topic" ,
762
- [
763
- (0 , "FOO" ),
764
- (2 , "fan" ),
765
- (4 , "BOO" ),
766
- ],
767
- )
768
- def test_return_to_focus_after_search (
769
- self ,
770
- mocker ,
771
- topic_view ,
772
- widget_size ,
773
- current_focus ,
774
- topic ,
775
- search_topics_key ,
776
- go_back_key ,
777
- ):
778
- # Initialize log
779
- topic_view .topics_btn_list = [
780
- mocker .Mock (topic_name = topic_name )
781
- for topic_name in ["FOO" , "foo" , "fan" , "boo" , "BOO" ]
782
- ]
783
- topic_view .log .extend (topic_view .topics_btn_list )
784
-
785
- # Set initial focus to 'current_focus' and name to 'topic'
786
- topic_view .log .set_focus (current_focus )
787
- topic_view .focus_index_before_search = current_focus
788
- previous_focus = topic_view .log .get_focus ()[1 ]
789
- previous_focus_topic_name = topic
732
+ # During search
733
+ topic_view .log .clear ()
734
+ topic_view .log .extend (topic_view .topics_btn_list [3 ])
735
+ topic_view .log .set_focus (1 )
790
736
791
- # Toggle Search
792
- size = widget_size (topic_view )
793
- topic_view .keypress (size , search_topics_key )
794
-
795
- # Exit Search
796
- topic_view .keypress (size , go_back_key )
737
+ # Exit search
738
+ topic_view .keypress (size , key )
797
739
798
- # Obtain new focus
799
- new_focus = topic_view .log . get_focus ()[ 1 ]
800
- new_focus_topic_name = topic_view .log [ new_focus ]. topic_name
801
- assert new_focus == previous_focus
802
- assert previous_focus_topic_name == new_focus_topic_name
740
+ # Check state reset after search
741
+ topic_view .set_focus . assert_called_once_with ( "body" )
742
+ assert topic_view .topic_search_box . reset_search_text . called
743
+ assert topic_view . log == topic_view . topics_btn_list
744
+ assert topic_view . log . get_focus ()[ 1 ] == topic_view . focus_index_before_search
803
745
804
746
805
747
class TestUsersView :
0 commit comments