-
Notifications
You must be signed in to change notification settings - Fork 114
tests(checkbox): Add kitchensink tests for checkbox and checkbox_group #1702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4fd0ecc
Add kitchensink tests for checkbox and checkbox_group
karangattu b245382
remove unused imports
karangattu 0dd3963
remove incorrect expect_width in tests
karangattu b41a5e2
Update CHANGELOG.md
karangattu 6230a54
use a single width mixin instead of every component using their own
karangattu 0a3d123
Apply suggestions from code review
schloerke 5da09ea
Move new mixin to `_base.py`
schloerke ae713d8
Discard changes to shiny/api-examples/input_checkbox/app-core.py
schloerke 69e4b5b
Merge branch 'main' into add-kitchensink-tests-checkbox
schloerke 1ca380a
Add output code for each checkbox group. Test many round trips values
schloerke 264a60e
Discard changes to tests/playwright/shiny/inputs/test_input_checkbox.py
schloerke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
tests/playwright/shiny/inputs/input_controls_kitchensink/input_checkbox/app.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from shiny.express import input, render, ui | ||
|
||
ui.page_opts(title="Checkbox Kitchen Sink", fillable=True) | ||
|
||
with ui.layout_columns(): | ||
with ui.card(): | ||
ui.card_header("Default checkbox with label") | ||
ui.input_checkbox("default", "Basic Checkbox") | ||
|
||
@render.code | ||
def default_txt(): | ||
return str(input.default()) | ||
|
||
with ui.card(): | ||
ui.card_header("Checkbox With Value") | ||
ui.input_checkbox("value", "Checkbox with Value", value=True) | ||
|
||
@render.code | ||
def value_txt(): | ||
return str(input.value()) | ||
|
||
with ui.card(): | ||
ui.card_header("Checkbox With Width") | ||
ui.input_checkbox("width", "Checkbox with Width", width="10px") | ||
|
||
@render.code | ||
def width_txt(): | ||
return str(input.width()) |
26 changes: 26 additions & 0 deletions
26
...shiny/inputs/input_controls_kitchensink/input_checkbox/test_input_checkbox_kitchensink.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from playwright.sync_api import Page | ||
|
||
from shiny.playwright import controller | ||
from shiny.run import ShinyAppProc | ||
|
||
|
||
def test_checkbox_kitchen(page: Page, local_app: ShinyAppProc) -> None: | ||
page.goto(local_app.url) | ||
|
||
default = controller.InputCheckbox(page, "default") | ||
default.expect_label("Basic Checkbox") | ||
default.expect_checked(False) | ||
default_code = controller.OutputCode(page, "default_txt") | ||
default_code.expect_value("False") | ||
default.set(True) | ||
default_code.expect_value("True") | ||
default.set(False) | ||
default_code.expect_value("False") | ||
|
||
value = controller.InputCheckbox(page, "value") | ||
value.expect_checked(True) | ||
controller.OutputCode(page, "value_txt").expect_value("True") | ||
|
||
width = controller.InputCheckbox(page, "width") | ||
width.expect_width("10px") | ||
controller.OutputCode(page, "width_txt").expect_value("False") |
64 changes: 64 additions & 0 deletions
64
tests/playwright/shiny/inputs/input_controls_kitchensink/input_checkbox_group/app.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from shiny.express import input, render, ui | ||
|
||
ui.page_opts(title="Checkbox Group Kitchen Sink", fillable=True) | ||
|
||
choices = ["Option A", "Option B", "Option C", "Option D"] | ||
|
||
choices_dict = { | ||
"value1": "Option A", | ||
"value2": "Option B", | ||
"value3": "Option C", | ||
"value4": "Option D", | ||
} | ||
|
||
with ui.layout_columns(): | ||
with ui.card(): | ||
ui.card_header("Default Checkbox Group with label") | ||
ui.input_checkbox_group("default", "Basic Checkbox Group", choices=choices) | ||
|
||
@render.code | ||
def default_txt(): | ||
return str(input.default()) | ||
|
||
with ui.card(): | ||
ui.card_header("With Selected Values") | ||
ui.input_checkbox_group( | ||
"selected", | ||
"Selected Values", | ||
choices=choices, | ||
selected=["Option B", "Option C"], | ||
) | ||
|
||
@render.code | ||
def selected_txt(): | ||
return str(input.selected()) | ||
|
||
with ui.card(): | ||
ui.card_header("With Width") | ||
ui.input_checkbox_group("width", "Custom Width", choices=choices, width="30px") | ||
|
||
@render.code | ||
def width_txt(): | ||
return str(input.width()) | ||
|
||
with ui.card(): | ||
ui.card_header("Inline") | ||
ui.input_checkbox_group( | ||
"inline", "Inline Checkbox Group", choices=choices, inline=True | ||
) | ||
|
||
@render.code | ||
def inline_txt(): | ||
return str(input.inline()) | ||
|
||
with ui.card(): | ||
ui.card_header("With dict of values") | ||
ui.input_checkbox_group( | ||
"dict_values", | ||
"Dict Values", | ||
choices=choices_dict, | ||
) | ||
|
||
@render.code | ||
def dict_values_txt(): | ||
return str(input.dict_values()) |
36 changes: 36 additions & 0 deletions
36
.../input_controls_kitchensink/input_checkbox_group/test_input_checkbox_group_kitchensink.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from playwright.sync_api import Page | ||
|
||
from shiny.playwright import controller | ||
from shiny.run import ShinyAppProc | ||
|
||
|
||
def test_checkbox_group_kitchen(page: Page, local_app: ShinyAppProc) -> None: | ||
page.goto(local_app.url) | ||
|
||
default = controller.InputCheckboxGroup(page, "default") | ||
default.expect_label("Basic Checkbox Group") | ||
default.expect_selected([]) | ||
controller.OutputCode(page, "default_txt").expect_value("()") | ||
|
||
selected = controller.InputCheckboxGroup(page, "selected") | ||
selected.expect_selected(["Option B", "Option C"]) | ||
controller.OutputCode(page, "selected_txt").expect_value("('Option B', 'Option C')") | ||
|
||
width = controller.InputCheckboxGroup(page, "width") | ||
width.expect_width("30px") | ||
|
||
inline = controller.InputCheckboxGroup(page, "inline") | ||
inline.expect_inline(True) | ||
inline_txt = controller.OutputCode(page, "inline_txt") | ||
inline_txt.expect_value("()") | ||
# Set in wrong order | ||
inline.set(["Option D", "Option A"]) | ||
inline.expect_selected(["Option A", "Option D"]) | ||
inline_txt.expect_value("('Option A', 'Option D')") | ||
|
||
dict_values = controller.InputCheckboxGroup(page, "dict_values") | ||
dict_values.expect_selected([]) | ||
dict_values.set(["value1", "value4"]) | ||
dict_values.expect_selected(["value1", "value4"]) | ||
dict_values_txt = controller.OutputCode(page, "dict_values_txt") | ||
dict_values_txt.expect_value("('value1', 'value4')") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.