@@ -568,64 +568,38 @@ 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" )
583
+ mocker .patch (VIEWS + ".urwid.Frame.keypress" )
578
584
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
583
-
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 )
585
+ stream_view .streams_btn_list = ["FOO" , "foo" , "fan" , "boo" , "BOO" ]
586
+ stream_view .focus_index_before_search = 3
610
587
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
588
+ # Simulate search
589
+ stream_view .log .clear ()
590
+ stream_view .log .extend (stream_view .streams_btn_list [3 ])
591
+ stream_view .log .set_focus (0 )
592
+ stream_view .keypress (size , "down" )
593
+ assert stream_view .log .get_focus ()[1 ] != stream_view .focus_index_before_search
616
594
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 )
595
+ # Exit search
596
+ stream_view .keypress (size , key )
623
597
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
598
+ # Check state reset after search
599
+ stream_view .set_focus . assert_called_once_with ( "body" )
600
+ assert stream_view .stream_search_box . reset_search_text . called
601
+ assert stream_view . log == stream_view . streams_btn_list
602
+ assert stream_view . log . get_focus ()[ 1 ] == stream_view . focus_index_before_search
629
603
630
604
631
605
class TestTopicsView :
@@ -741,65 +715,39 @@ def test_keypress_GO_RIGHT(self, mocker, topic_view, key, widget_size):
741
715
def test_keypress_SEARCH_TOPICS (self , mocker , topic_view , key , widget_size ):
742
716
size = widget_size (topic_view )
743
717
mocker .patch (VIEWS + ".TopicsView.set_focus" )
718
+ topic_view .log .extend (["FOO" , "foo" , "fan" , "boo" , "BOO" ])
719
+ topic_view .log .set_focus (3 )
720
+
744
721
topic_view .keypress (size , key )
722
+
745
723
topic_view .set_focus .assert_called_once_with ("header" )
746
724
topic_view .header_list .set_focus .assert_called_once_with (2 )
725
+ assert topic_view .focus_index_before_search == 3
747
726
748
727
@pytest .mark .parametrize ("key" , keys_for_command ("GO_BACK" ))
749
728
def test_keypress_GO_BACK (self , mocker , topic_view , key , widget_size ):
750
729
size = widget_size (topic_view )
751
730
mocker .patch (VIEWS + ".TopicsView.set_focus" )
731
+ mocker .patch (VIEWS + ".urwid.Frame.keypress" )
752
732
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
757
-
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 )
733
+ topic_view .topics_btn_list = ["FOO" , "foo" , "fan" , "boo" , "BOO" ]
734
+ topic_view .focus_index_before_search = 3
784
735
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
736
+ # Simulate search
737
+ topic_view .log .clear ()
738
+ topic_view .log .extend (topic_view .topics_btn_list [3 ])
739
+ topic_view .log .set_focus (0 )
740
+ topic_view .keypress (size , "down" )
741
+ assert topic_view .log .get_focus ()[1 ] != topic_view .focus_index_before_search
790
742
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 )
743
+ # Exit search
744
+ topic_view .keypress (size , key )
797
745
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
746
+ # Check state reset after search
747
+ topic_view .set_focus . assert_called_once_with ( "body" )
748
+ assert topic_view .topic_search_box . reset_search_text . called
749
+ assert topic_view . log == topic_view . topics_btn_list
750
+ assert topic_view . log . get_focus ()[ 1 ] == topic_view . focus_index_before_search
803
751
804
752
805
753
class TestUsersView :
0 commit comments