@@ -518,8 +518,8 @@ def test_stream_muting_confirmation_popup(
518518 "search_within_topic_narrow" ,
519519 ],
520520 )
521- @pytest .mark .parametrize ("msg_ids" , [({200 , 300 , 400 }), (set ()), ( {100 })])
522- def test_search_message (
521+ @pytest .mark .parametrize ("msg_ids" , [({200 , 300 , 400 }), ({100 })])
522+ def test_search_message__hits (
523523 self ,
524524 initial_narrow : List [Any ],
525525 final_narrow : List [Any ],
@@ -550,6 +550,60 @@ def set_msg_ids(*args: Any, **kwargs: Any) -> None:
550550 create_msg .assert_called_once_with (controller .model , msg_ids )
551551 assert controller .model .index == dict (index_search_messages , search = msg_ids )
552552
553+ @pytest .mark .parametrize (
554+ "initial_narrow, final_narrow" ,
555+ [
556+ ([], [["search" , "FOO" ]]),
557+ ([["search" , "BOO" ]], [["search" , "FOO" ]]),
558+ ([["stream" , "PTEST" ]], [["stream" , "PTEST" ], ["search" , "FOO" ]]),
559+ (
560+ [["pm-with" , "[email protected] " ], ["search" , "BOO" ]], 561+ [["pm-with" , "[email protected] " ], ["search" , "FOO" ]], 562+ ),
563+ (
564+ [["stream" , "PTEST" ], ["topic" , "RDS" ]],
565+ [["stream" , "PTEST" ], ["topic" , "RDS" ], ["search" , "FOO" ]],
566+ ),
567+ ],
568+ ids = [
569+ "Default_all_msg_search" ,
570+ "redo_default_search" ,
571+ "search_within_stream" ,
572+ "pm_search_again" ,
573+ "search_within_topic_narrow" ,
574+ ],
575+ )
576+ def test_search_message__no_hits (
577+ self ,
578+ initial_narrow : List [Any ],
579+ final_narrow : List [Any ],
580+ controller : Controller ,
581+ mocker : MockerFixture ,
582+ index_search_messages : Index ,
583+ msg_ids : Set [int ] = set (),
584+ ) -> None :
585+ get_message = mocker .patch (MODEL + ".get_messages" )
586+ create_msg = mocker .patch (MODULE + ".create_msg_box_list" )
587+ mocker .patch (MODEL + ".get_message_ids_in_current_narrow" , return_value = msg_ids )
588+ controller .model .index = index_search_messages # Any initial search index
589+ controller .view .message_view = mocker .patch ("urwid.ListBox" )
590+ controller .model .narrow = initial_narrow
591+
592+ def set_msg_ids (* args : Any , ** kwargs : Any ) -> None :
593+ controller .model .index ["search" ].update (msg_ids )
594+
595+ get_message .side_effect = set_msg_ids
596+ assert controller .model .index ["search" ] == {500 }
597+
598+ controller .search_messages ("FOO" )
599+
600+ assert controller .model .narrow == final_narrow
601+ get_message .assert_called_once_with (
602+ num_after = 0 , num_before = 30 , anchor = 10000000000
603+ )
604+ create_msg .assert_not_called ()
605+ assert controller .model .index == dict (index_search_messages , search = msg_ids )
606+
553607 @pytest .mark .parametrize (
554608 "screen_size, expected_popup_size" ,
555609 [
0 commit comments