From d5ffc5a71941b0ead7dd204052687998d26812d3 Mon Sep 17 00:00:00 2001 From: rsashank Date: Mon, 11 Dec 2023 16:40:01 +0530 Subject: [PATCH] tests: boxes: Update tests for handling Esc during message compose. --- tests/ui_tools/test_boxes.py | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/ui_tools/test_boxes.py b/tests/ui_tools/test_boxes.py index 869cc981b9..1ef5947092 100644 --- a/tests/ui_tools/test_boxes.py +++ b/tests/ui_tools/test_boxes.py @@ -235,15 +235,39 @@ def test__compose_attributes_reset_for_private_compose( mocker.patch("urwid.connect_signal") write_box.model.user_id_email_dict = user_id_email_dict write_box.private_box_view(recipient_user_ids=[11]) + + # Testing input less than 15 characters; >15 prompts confirmation popup write_box.msg_write_box.edit_text = "random text" size = widget_size(write_box) write_box.keypress(size, key) + write_box.view.controller.exit_compose_confirmation_popup.assert_not_called() assert write_box.to_write_box is None assert write_box.msg_write_box.edit_text == "" assert write_box.compose_box_status == "closed" + @pytest.mark.parametrize("key", keys_for_command("GO_BACK")) + def test__compose_attributes_reset_for_private_compose_popup( + self, + key: str, + mocker: MockerFixture, + write_box: WriteBox, + widget_size: Callable[[Widget], urwid_Size], + user_id_email_dict: Dict[int, str], + ) -> None: + mocker.patch("urwid.connect_signal") + write_box.model.user_id_email_dict = user_id_email_dict + write_box.private_box_view(recipient_user_ids=[11]) + + # Testing input more than 15 characters; >15 prompts confirmation popup + write_box.msg_write_box.edit_text = "random text (>15 characters)" + + size = widget_size(write_box) + write_box.keypress(size, key) + + write_box.view.controller.exit_compose_confirmation_popup.assert_called_once() + @pytest.mark.parametrize("key", keys_for_command("GO_BACK")) def test__compose_attributes_reset_for_stream_compose( self, @@ -254,15 +278,37 @@ def test__compose_attributes_reset_for_stream_compose( ) -> None: mocker.patch(WRITEBOX + "._set_stream_write_box_style") write_box.stream_box_view(stream_id=1) + + # Testing input less than 15 characters; >15 prompts confirmation popup write_box.msg_write_box.edit_text = "random text" size = widget_size(write_box) write_box.keypress(size, key) + write_box.view.controller.exit_compose_confirmation_popup.assert_not_called() assert write_box.stream_id is None assert write_box.msg_write_box.edit_text == "" assert write_box.compose_box_status == "closed" + @pytest.mark.parametrize("key", keys_for_command("GO_BACK")) + def test__compose_attributes_reset_for_stream_compose_popup( + self, + key: str, + mocker: MockerFixture, + write_box: WriteBox, + widget_size: Callable[[Widget], urwid_Size], + ) -> None: + mocker.patch(WRITEBOX + "._set_stream_write_box_style") + write_box.stream_box_view(stream_id=1) + + # Testing input more than 15 characters; >15 prompts confirmation popup + write_box.msg_write_box.edit_text = "random text (>15 characters)" + + size = widget_size(write_box) + write_box.keypress(size, key) + + write_box.view.controller.exit_compose_confirmation_popup.assert_called_once_with() + @pytest.mark.parametrize( ["raw_recipients", "tidied_recipients"], [ @@ -1508,6 +1554,7 @@ def test_keypress_SEND_MESSAGE_no_topic( ) def test_keypress_typeahead_mode_autocomplete_key( self, + mocker: MockerFixture, write_box: WriteBox, widget_size: Callable[[Widget], urwid_Size], current_typeahead_mode: bool, @@ -1515,6 +1562,7 @@ def test_keypress_typeahead_mode_autocomplete_key( expect_footer_was_reset: bool, key: str, ) -> None: + write_box.msg_write_box = mocker.Mock(edit_text="") write_box.is_in_typeahead_mode = current_typeahead_mode size = widget_size(write_box)