Skip to content

Commit

Permalink
Add additional tests to select and checkbox (#131)
Browse files Browse the repository at this point in the history
- Test when a `Choice` instance is passed as `default`
   or `initial_choice`.

 - Test when a `Choice` instance and string have the
   same value and `default` or `initial_choice` is
   set to the `Choice` instance.
  • Loading branch information
kiancross committed Jun 19, 2021
1 parent 0bb1a6d commit 2979fb8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/prompts/test_checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ def test_list_ctr_c():


def test_checkbox_initial_choice():
message = "Foo message"
choice = Choice("bazz")
kwargs = {"choices": ["foo", choice], "initial_choice": choice}
text = KeyInputs.SPACE + KeyInputs.ENTER + "\r"

result, cli = feed_cli_with_input("checkbox", message, text, **kwargs)
assert result == ["bazz"]


def test_select_initial_choice_string():
message = "Foo message"
kwargs = {"choices": ["foo", "bazz"], "initial_choice": "bazz"}
text = KeyInputs.SPACE + KeyInputs.ENTER + "\r"
Expand All @@ -193,6 +203,16 @@ def test_checkbox_initial_choice():
assert result == ["bazz"]


def test_select_initial_choice_duplicate():
message = "Foo message"
choice = Choice("foo")
kwargs = {"choices": ["foo", choice, "bazz"], "initial_choice": choice}
text = KeyInputs.DOWN + KeyInputs.SPACE + KeyInputs.ENTER + "\r"

result, cli = feed_cli_with_input("checkbox", message, text, **kwargs)
assert result == ["bazz"]


def test_checkbox_initial_choice_not_selectable():
message = "Foo message"
separator = Separator()
Expand Down
20 changes: 20 additions & 0 deletions tests/prompts/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ def test_allow_shortcut_key_with_True():


def test_select_initial_choice():
message = "Foo message"
choice = Choice("bazz")
kwargs = {"choices": ["foo", choice], "default": choice}
text = KeyInputs.ENTER + "\r"

result, cli = feed_cli_with_input("select", message, text, **kwargs)
assert result == "bazz"


def test_select_initial_choice_string():
message = "Foo message"
kwargs = {"choices": ["foo", "bazz"], "default": "bazz"}
text = KeyInputs.ENTER + "\r"
Expand All @@ -181,6 +191,16 @@ def test_select_initial_choice():
assert result == "bazz"


def test_select_initial_choice_duplicate():
message = "Foo message"
choice = Choice("foo")
kwargs = {"choices": ["foo", choice, "bazz"], "default": choice}
text = KeyInputs.DOWN + KeyInputs.ENTER + "\r"

result, cli = feed_cli_with_input("select", message, text, **kwargs)
assert result == "bazz"


def test_select_initial_choice_not_selectable():
message = "Foo message"
separator = Separator()
Expand Down

0 comments on commit 2979fb8

Please sign in to comment.