Skip to content
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

Make input_selectize work correctly within a module #1091

Merged
merged 6 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fixed `render.download` not working in Express. (#1085)

* `express.ui.hold()` can now accept any type of object, instead of just `TagChild` objects. (#1089)
* Fixed an issue where `input_selectize` would not initialize correctly when created within a Shiny module. (#1091)


## [0.7.0] - 2024-01-25

Expand Down Expand Up @@ -57,12 +59,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* `shiny.render.transformer.OutputRendererSync`
* `shiny.render.transformer.OutputRendererAsync`


### Other changes

* Pinned Starlette to version <0.35.0; versions 0.35.0 and 0.35.1 caused problems when deploying on Posit Connect. (#1009
)


## [0.6.1.1] - 2023-12-22

### Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion shiny/ui/_input_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def input_select(
tags.script(
dumps(opts),
type="application/json",
data_for=id,
data_for=resolved_id,
data_eval=dumps(extract_js_keys(opts)),
),
selectize_deps(),
Expand Down
2 changes: 1 addition & 1 deletion tests/playwright/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ def __init__(self, page: Page, id: str) -> None:
super().__init__(
page,
id=id,
select_class="",
select_class=".selectized",
)


Expand Down
10 changes: 5 additions & 5 deletions tests/playwright/shiny/components/data_frame/test_data_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pytest
from conftest import ShinyAppProc, create_example_fixture, expect_to_change
from controls import InputSelectize, InputSwitch
from controls import InputSelect, InputSwitch
from playwright.sync_api import Locator, Page, expect

RERUNS = 3
Expand Down Expand Up @@ -111,7 +111,7 @@ def test_table_switch(
scroll_to_end: Callable[[], None],
):
page.goto(data_frame_app.url)
select_dataset = InputSelectize(page, "dataset")
select_dataset = InputSelect(page, "dataset")

scroll_to_end()

Expand Down Expand Up @@ -141,7 +141,7 @@ def test_sort(
grid_container: Locator,
):
page.goto(data_frame_app.url)
select_dataset = InputSelectize(page, "dataset")
select_dataset = InputSelect(page, "dataset")
select_dataset.set("diamonds")
select_dataset.expect.to_have_value("diamonds")

Expand Down Expand Up @@ -206,7 +206,7 @@ def test_single_selection(
page: Page, data_frame_app: ShinyAppProc, grid_container: Locator, snapshot: Any
):
page.goto(data_frame_app.url)
InputSelectize(page, "selection_mode").set("single")
InputSelect(page, "selection_mode").set("single")
first_cell = grid_container.locator("tbody tr:first-child td:first-child")

def detail_text():
Expand Down Expand Up @@ -346,7 +346,7 @@ def _filter_test_impl(
expect(grid.locator("tbody tr")).to_have_count(5)

# Ensure changing dataset resets filters
select_dataset = InputSelectize(page, "dataset")
select_dataset = InputSelect(page, "dataset")
select_dataset.set("attention")
select_dataset.expect.to_have_value("attention")
expect(page.get_by_text("Unnamed: 0")).to_be_attached()
Expand Down
53 changes: 28 additions & 25 deletions tests/playwright/shiny/inputs/test_input_selectize.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from controls import InputSelectize
from playwright.sync_api import Page, expect

app = create_doc_example_core_fixture("input_select")
app = create_doc_example_core_fixture("input_selectize")


def test_input_selectize_kitchen(page: Page, app: ShinyAppProc) -> None:
Expand All @@ -13,27 +13,30 @@ def test_input_selectize_kitchen(page: Page, app: ShinyAppProc) -> None:
expect(state.loc_label).to_have_text("Choose a state:")
state.expect_label("Choose a state:")

state.expect_choices(["NY", "NJ", "CT", "WA", "OR", "CA", "MN", "WI", "IA"])
state.expect_choice_labels(
[
"New York",
"New Jersey",
"Connecticut",
"Washington",
"Oregon",
"California",
"Minnesota",
"Wisconsin",
"Iowa",
]
)
state.expect_choice_groups(["East Coast", "West Coast", "Midwest"])

state.expect_selected("NY")
state.expect_multiple(False)

state.expect_width(None)

state.set("IA")

state.expect_selected("IA")
# TODO: This test was being run against input_select, not input_selectize
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels off to me. I'd like double check this in the morning before we merge the PR.

Everything else is great!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. To my knowledge, selectize.js changed how it stores options / selected values.

Either way, if we would have used the correct selectize testing class, the error would have been surfaced earlier.

Yes, we should do this in a followup PR as the changes are not related to this Issue

# and none of these expectations pass. We need to add additional test methods
# for the InputSelectize class to test this behaviour.
# https://github.com/posit-dev/py-shiny/issues/1100

# state.expect_choices(["NY", "NJ", "CT", "WA", "OR", "CA", "MN", "WI", "IA"])
# state.expect_choice_labels(
# [
# "New York",
# "New Jersey",
# "Connecticut",
# "Washington",
# "Oregon",
# "California",
# "Minnesota",
# "Wisconsin",
# "Iowa",
# ]
# state.expect_choice_groups(["East Coast", "West Coast", "Midwest"])

# state.expect_multiple(True)

# state.expect_width(None)

# state.set("Iowa")

# state.expect_selected("IA")
Loading