Skip to content

Commit

Permalink
Merge branch 'main' into machow-feat-data-grid-polars
Browse files Browse the repository at this point in the history
* main:
  api(playwright): Code review of complete playwright API (posit-dev#1501)
  fix: Move `www/shared/py-shiny` to `www/py-shiny` (posit-dev#1499)
  • Loading branch information
schloerke committed Jul 8, 2024
2 parents dd2f867 + bdb5935 commit 9cfc3ec
Show file tree
Hide file tree
Showing 36 changed files with 152 additions and 162 deletions.
2 changes: 1 addition & 1 deletion js/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ process.argv.forEach((val, index) => {
}
});

const outDir = "../shiny/www/shared/py-shiny";
const outDir = "../shiny/www/py-shiny";

async function bundle_helper(
options: BuildOptions
Expand Down
119 changes: 55 additions & 64 deletions shiny/playwright/controller/_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,14 +1174,14 @@ def expect_page_mode(self, value: str, *, timeout: Timeout = None):
)
return self

def expect_wc_attribute(self, value: str, *, timeout: Timeout = None):
def expect_attribute(self, value: str, *, timeout: Timeout = None):
"""
Expect the `wc` attribute of the input dark mode to have a specific value.
Expect the attribute named `attribute` of the input dark mode to have a specific value.
Parameters
----------
value
The expected value of the `wc` attribute.
The expected value of the `attribute` attribute.
timeout
The maximum time to wait for the expectation to be fulfilled. Defaults to `None`.
"""
Expand Down Expand Up @@ -1398,7 +1398,8 @@ def set(self, value: bool, *, timeout: Timeout = None, **kwargs: object) -> None
value, timeout=timeout, **kwargs # pyright: ignore[reportArgumentType]
)

def toggle(self, *, timeout: Timeout = None, **kwargs: object) -> None:
# TODO-karan-test: Convert usage of _toggle() to set()
def _toggle(self, *, timeout: Timeout = None, **kwargs: object) -> None:
"""
Toggles the input checkbox.
Expand Down Expand Up @@ -1480,6 +1481,7 @@ def __init__(
)


# TODO-future: Move class methods to a separate module
class _MultipleDomItems:
@staticmethod
def assert_arr_is_unique(
Expand Down Expand Up @@ -1811,7 +1813,7 @@ def __init__(

def set(
self,
# Allow `selected` to be a single Pattern to perform matching against many items
# TODO-future: Allow `selected` to be a single Pattern to perform matching against many items
selected: list[str],
*,
timeout: Timeout = None,
Expand Down Expand Up @@ -2072,19 +2074,6 @@ class InputFile(
Playwright `Locator` of the progress bar.
"""

# id: str,
# label: TagChild,
# *,
# multiple: bool = False,
# accept: Optional[Union[str, list[str]]] = None,
# width: Optional[str] = None,
# button_label: str = "Browse...",
# placeholder: str = "No file selected",
# capture: Optional[Literal["environment", "user"]] = None,
# with page.expect_file_chooser() as fc_info:
# page.get_by_text("Upload").click()
# file_chooser = fc_info.value
# file_chooser.set_files("myfile.pdf")
def __init__(
self,
page: Page,
Expand Down Expand Up @@ -3697,7 +3686,12 @@ class _OutputImageBase(_OutputInlineContainerM, _OutputBase):
Playwright `Locator` of the image.
"""

def __init__(self, page: Page, id: str, loc_classes: str = "") -> None:
def __init__(
self,
page: Page,
id: str,
loc_classes: str = "",
) -> None:
"""
Initializes an image output.
Expand Down Expand Up @@ -3904,20 +3898,6 @@ def expect_empty(self, value: bool, *, timeout: Timeout = None) -> None:
else:
self.expect.not_to_be_empty(timeout=timeout)

def expect_text(self, value: str, *, timeout: Timeout = None) -> None:
"""
Asserts that the output has the expected text.
Parameters
----------
value
The expected text.
timeout
The maximum time to wait for the text to appear. Defaults to `None`.
"""

self.expect.to_have_text(value, timeout=timeout)


# When making selectors, use `xpath` so that direct decendents can be checked
class OutputTable(_OutputBase):
Expand Down Expand Up @@ -4022,7 +4002,7 @@ def expect_column_text(
timeout=timeout,
)

def expect_n_col(
def expect_ncol(
self,
value: int,
*,
Expand All @@ -4046,7 +4026,7 @@ def expect_n_col(
timeout=timeout,
)

def expect_n_row(
def expect_nrow(
self,
value: int,
*,
Expand Down Expand Up @@ -4188,9 +4168,9 @@ def set(self, open: bool, *, timeout: Timeout = None) -> None:
The maximum time to wait for the sidebar to open or close. Defaults to `None`.
"""
if open ^ (self.loc_handle.get_attribute("aria-expanded") == "true"):
self.toggle(timeout=timeout)
self._toggle(timeout=timeout)

def toggle(self, *, timeout: Timeout = None) -> None:
def _toggle(self, *, timeout: Timeout = None) -> None:
"""
Toggles the sidebar open or closed.
Expand Down Expand Up @@ -4782,7 +4762,7 @@ def expect_panels(

def set(
self,
selected: str | list[str],
open: str | list[str],
*,
timeout: Timeout = None,
) -> None:
Expand All @@ -4791,13 +4771,13 @@ def set(
Parameters
----------
selected
The selected accordion panel(s).
open
The open accordion panel(s).
timeout
The maximum time to wait for the accordion panel to be visible and interactable. Defaults to `None`.
"""
if isinstance(selected, str):
selected = [selected]
if isinstance(open, str):
open = [open]
for element in self.loc.element_handles():
element.wait_for_element_state(state="visible", timeout=timeout)
element.scroll_into_view_if_needed(timeout=timeout)
Expand All @@ -4806,9 +4786,7 @@ def set(
raise ValueError(
"Accordion panel does not have a `data-value` attribute"
)
self.accordion_panel(elem_value).set(
elem_value in selected, timeout=timeout
)
self.accordion_panel(elem_value).set(elem_value in open, timeout=timeout)

def accordion_panel(
self,
Expand Down Expand Up @@ -4955,9 +4933,9 @@ def set(self, open: bool, *, timeout: Timeout = None) -> None:
self.loc.scroll_into_view_if_needed(timeout=timeout)
expect_not_to_have_class(self.loc_body, "collapsing", timeout=timeout)
if self._loc_body_visible.count() != int(open):
self.toggle(timeout=timeout)
self._toggle(timeout=timeout)

def toggle(self, *, timeout: Timeout = None) -> None:
def _toggle(self, *, timeout: Timeout = None) -> None:
"""
Toggles the state of the control.
Expand Down Expand Up @@ -5156,9 +5134,9 @@ def set(self, open: bool, timeout: Timeout = None) -> None:
The maximum time to wait for the popover to be visible and interactable. Defaults to `None`.
"""
if open ^ self.get_loc_overlay_body(timeout=timeout).count() > 0:
self.toggle()
self._toggle()

def toggle(self, timeout: Timeout = None) -> None:
def _toggle(self, timeout: Timeout = None) -> None:
"""
Toggles the state of the popover.
Expand Down Expand Up @@ -5227,11 +5205,11 @@ def set(self, open: bool, timeout: Timeout = None) -> None:
The maximum time to wait for the tooltip to be visible and interactable. Defaults to `None`.
"""
if open ^ self.get_loc_overlay_body(timeout=timeout).count() > 0:
self.toggle(timeout=timeout)
self._toggle(timeout=timeout)
if not open:
self.get_loc_overlay_body(timeout=timeout).click()

def toggle(self, timeout: Timeout = None) -> None:
def _toggle(self, timeout: Timeout = None) -> None:
"""
Toggles the state of the tooltip.
Expand Down Expand Up @@ -5304,7 +5282,9 @@ def get_loc_active_content(self, *, timeout: Timeout = None) -> Locator:
f"div.tab-content[data-tabsetid='{datatab_id}'] > div.tab-pane.active"
)

def expect_content(self, value: PatternOrStr, *, timeout: Timeout = None) -> None:
def _expect_content_text(
self, value: PatternOrStr, *, timeout: Timeout = None
) -> None:
"""
Expects the control to have the specified content.
Expand Down Expand Up @@ -5439,7 +5419,9 @@ def expect_active(self, value: bool, *, timeout: Timeout = None) -> None:
"""
_expect_class_value(self.loc, "active", value, timeout=timeout)

def expect_content(self, value: PatternOrStr, *, timeout: Timeout = None) -> None:
def _expect_content_text(
self, value: PatternOrStr, *, timeout: Timeout = None
) -> None:
"""
Expects the nav item content to have the specified text.
Expand Down Expand Up @@ -5876,7 +5858,7 @@ def cell_locator(self, row: int, col: int) -> Locator:
)

# TODO-barret; Should this be called `expect_row_count()`?
def expect_n_row(self, value: int, *, timeout: Timeout = None):
def expect_nrow(self, value: int, *, timeout: Timeout = None):
"""
Expects the number of rows in the data frame.
Expand All @@ -5891,7 +5873,7 @@ def expect_n_row(self, value: int, *, timeout: Timeout = None):
value, timeout=timeout
)

def expect_selected_n_row(self, value: int, *, timeout: Timeout = None):
def expect_selected_num_rows(self, value: int, *, timeout: Timeout = None):
"""
Expects the number of selected rows in the data frame.
Expand Down Expand Up @@ -5953,7 +5935,7 @@ def expect_selected_rows(self, rows: list[int], *, timeout: Timeout = None):
# Could not find the reason why. Raising the original error.
raise e

def expect_row_focus_state(
def _expect_row_focus_state(
self, in_focus: bool = True, *, row: int, timeout: Timeout = None
):
"""
Expand Down Expand Up @@ -6077,7 +6059,7 @@ def _cell_scroll_if_needed(self, *, row: int, col: int, timeout: Timeout):
break
cell.scroll_into_view_if_needed(timeout=timeout)

def expect_column_label(
def _expect_column_label(
self,
value: ListPatternOrStr,
*,
Expand All @@ -6103,7 +6085,7 @@ def expect_column_label(
timeout=timeout,
)

def expect_n_col(
def expect_ncol(
self,
value: int,
*,
Expand Down Expand Up @@ -6231,7 +6213,7 @@ def expect_class_state(
"Invalid state. Select one of 'success', 'failure', 'saving', 'editing', 'ready'"
)

def edit_cell(
def _edit_cell_no_save(
self,
text: str,
*,
Expand Down Expand Up @@ -6421,13 +6403,15 @@ def set_filter(
"Invalid filter value. Must be a string or a tuple/list of two numbers."
)

def save_cell(
def set_cell(
self,
text: str,
*,
row: int,
col: int,
save_key: str,
finish_key: (
Literal["Enter", "Shift+Enter", "Tab", "Shift+Tab", "Escape"] | None
) = None,
timeout: Timeout = None,
) -> None:
"""
Expand All @@ -6441,11 +6425,17 @@ def save_cell(
The row number of the cell.
col
The column number of the cell.
finish_key
The key to save the value of the cell. If `None` (the default), no key will
be pressed and instead the page body will be clicked.
timeout
The maximum time to wait for the action to complete. Defaults to `None`.
"""
self.edit_cell(text, row=row, col=col, timeout=timeout)
self.cell_locator(row=row, col=col).locator("> textarea").press(save_key)
self._edit_cell_no_save(text, row=row, col=col, timeout=timeout)
if finish_key is None:
self.page.locator("body").click()
else:
self.cell_locator(row=row, col=col).locator("> textarea").press(finish_key)

def expect_cell_title(
self,
Expand All @@ -6456,7 +6446,8 @@ def expect_cell_title(
timeout: Timeout = None,
) -> None:
"""
Expects the validation message of the cell in the data frame.
Expects the validation message of the cell in the data frame, which will be in
the `title` attribute of the element.
Parameters
----------
Expand Down
10 changes: 5 additions & 5 deletions shiny/ui/_html_deps_py_shiny.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def data_frame_deps() -> HTMLDependency:
version=__version__,
source={
"package": "shiny",
"subdir": "www/shared/py-shiny/data-frame",
"subdir": "www/py-shiny/data-frame",
},
script={"src": "data-frame.js", "type": "module"},
)
Expand All @@ -33,7 +33,7 @@ def chat_deps() -> list[HTMLDependency]:
version=__version__,
source={
"package": "shiny",
"subdir": "www/shared/py-shiny/chat",
"subdir": "www/py-shiny/chat",
},
script={"src": "chat.js", "type": "module"},
stylesheet={"href": "chat.css"},
Expand All @@ -46,7 +46,7 @@ def autoresize_dependency() -> HTMLDependency:
return HTMLDependency(
"shiny-textarea-autoresize",
__version__,
source={"package": "shiny", "subdir": "www/shared/py-shiny/text-area"},
source={"package": "shiny", "subdir": "www/py-shiny/text-area"},
script={"src": "textarea-autoresize.js", "type": "module"},
stylesheet={"href": "textarea-autoresize.css"},
)
Expand All @@ -56,7 +56,7 @@ def page_output_dependency() -> HTMLDependency:
return HTMLDependency(
"shiny-page-output",
__version__,
source={"package": "shiny", "subdir": "www/shared/py-shiny/page-output"},
source={"package": "shiny", "subdir": "www/py-shiny/page-output"},
script={"src": "page-output.js", "type": "module"},
)

Expand All @@ -65,7 +65,7 @@ def spin_dependency() -> HTMLDependency:
return HTMLDependency(
"shiny-spin",
__version__,
source={"package": "shiny", "subdir": "www/shared/py-shiny/spin"},
source={"package": "shiny", "subdir": "www/py-shiny/spin"},
stylesheet={"href": "spin.css"},
)

Expand Down
File renamed without changes.
Loading

0 comments on commit 9cfc3ec

Please sign in to comment.