Skip to content

Commit

Permalink
refactor: tests: boxes: Split typeahead mode keypress test.
Browse files Browse the repository at this point in the history
The typeahead mode keypress test has been divided into two separate tests:
one where the footer is reset and another where the footer is not reset.
This makes the test clearer and eliminates the need for a conditional.
  • Loading branch information
rsashank authored and neiljp committed Jul 14, 2024
1 parent 11f8d9f commit 59f2935
Showing 1 changed file with 35 additions and 17 deletions.
52 changes: 35 additions & 17 deletions tests/ui_tools/test_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1559,27 +1559,21 @@ def test_keypress_SEND_MESSAGE_no_topic(
)

@pytest.mark.parametrize(
"key, current_typeahead_mode, expected_typeahead_mode, expect_footer_was_reset",
"key, current_typeahead_mode, expected_typeahead_mode",
[
# footer does not reset
(primary_key_for_command("AUTOCOMPLETE"), False, False, False),
(primary_key_for_command("AUTOCOMPLETE_REVERSE"), False, False, False),
(primary_key_for_command("AUTOCOMPLETE"), True, True, False),
(primary_key_for_command("AUTOCOMPLETE_REVERSE"), True, True, False),
# footer resets
(primary_key_for_command("EXIT_COMPOSE"), True, False, True),
("space", True, False, True),
("k", True, False, True),
(primary_key_for_command("AUTOCOMPLETE"), False, False),
(primary_key_for_command("AUTOCOMPLETE_REVERSE"), False, False),
(primary_key_for_command("AUTOCOMPLETE"), True, True),
(primary_key_for_command("AUTOCOMPLETE_REVERSE"), True, True),
],
)
def test_keypress_typeahead_mode_autocomplete_key(
def test__keypress_typeahead_mode_autocomplete_key_footer_no_reset(
self,
mocker: MockerFixture,
write_box: WriteBox,
widget_size: Callable[[Widget], urwid_Size],
current_typeahead_mode: bool,
expected_typeahead_mode: bool,
expect_footer_was_reset: bool,
key: str,
) -> None:
write_box.msg_write_box = mocker.Mock(edit_text="")
Expand All @@ -1589,11 +1583,35 @@ def test_keypress_typeahead_mode_autocomplete_key(
write_box.keypress(size, key)

assert write_box.is_in_typeahead_mode == expected_typeahead_mode
if expect_footer_was_reset:
# We may prefer called-once in future, but the key part is that we do reset
assert self.view.set_footer_text.called
else:
assert not self.view.set_footer_text.called
assert not self.view.set_footer_text.called

@pytest.mark.parametrize(
"key, current_typeahead_mode, expected_typeahead_mode",
[
(primary_key_for_command("EXIT_COMPOSE"), True, False),
("space", True, False),
("k", True, False),
],
)
def test__keypress_typeahead_mode_autocomplete_key_footer_reset(
self,
mocker: MockerFixture,
write_box: WriteBox,
widget_size: Callable[[Widget], urwid_Size],
current_typeahead_mode: bool,
expected_typeahead_mode: 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)

write_box.keypress(size, key)

assert write_box.is_in_typeahead_mode == expected_typeahead_mode

# We may prefer called-once in future, but the key part is that we do reset
assert self.view.set_footer_text.called

@pytest.mark.parametrize(
[
Expand Down

0 comments on commit 59f2935

Please sign in to comment.