-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(dataframe): Add additional tests for dataframe (#1487)
Co-authored-by: Barret Schloerke <barret@posit.co>
- Loading branch information
1 parent
d1e19b9
commit 83568a2
Showing
5 changed files
with
191 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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
26 changes: 26 additions & 0 deletions
26
tests/playwright/shiny/components/data_frame/validate_row_selection_edit_mode/app.py
This file contains 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 palmerpenguins import load_penguins_raw # pyright: ignore[reportMissingTypeStubs] | ||
|
||
from shiny import App, Inputs, Outputs, Session, render, ui | ||
|
||
df = load_penguins_raw() | ||
|
||
df["Species"] = df["Species"].apply(lambda x: ui.HTML(f"<u>{x}</u>")) # pyright: ignore | ||
|
||
|
||
app_ui = ui.page_fluid( | ||
ui.h2("Palmer Penguins"), | ||
ui.output_data_frame("penguins_df"), | ||
) | ||
|
||
|
||
def server(input: Inputs, output: Outputs, session: Session) -> None: | ||
@render.data_frame | ||
def penguins_df(): | ||
return render.DataGrid( | ||
data=df, # pyright: ignore[reportUnknownArgumentType] | ||
editable=True, | ||
selection_mode="rows", | ||
) | ||
|
||
|
||
app = App(app_ui, server) |
71 changes: 71 additions & 0 deletions
71
...ents/data_frame/validate_row_selection_edit_mode/test_validate_row_selection_edit_mode.py
This file contains 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,71 @@ | ||
from playwright.sync_api import Page | ||
|
||
from shiny.playwright import controller | ||
from shiny.run import ShinyAppProc | ||
|
||
|
||
def test_validate_row_selection_in_edit_mode( | ||
page: Page, local_app: ShinyAppProc | ||
) -> None: | ||
page.goto(local_app.url) | ||
|
||
# Select (and verify) a row. Edit a cell content in that row. | ||
# Verify the row is not focused. Hit escape key. Verify the cell value is not updated. | ||
# Verify the row is focused. Hit escape key again. | ||
# Verify the row is not focused. (Possibly verify the container div is focused?) | ||
data_frame = controller.OutputDataFrame(page, "penguins_df") | ||
|
||
data_frame.expect_cell("N1A2", row=1, col=6) | ||
data_frame.edit_cell("N2A2", row=1, col=6) | ||
data_frame.expect_row_focus_state(False, row=1) | ||
data_frame.expect_class_state("editing", row=1, col=6) | ||
data_frame.expect_selected_n_row(1) | ||
data_frame.expect_selected_rows([1]) | ||
data_frame.save_cell("N3A2", row=1, col=6, save_key="Escape") | ||
data_frame.expect_cell("N1A2", row=1, col=6) | ||
data_frame.expect_row_focus_state(True, row=1) | ||
page.keyboard.press("Escape") | ||
data_frame.expect_row_focus_state(False, row=1) | ||
|
||
# Enable rows selection and editable. | ||
# Select (and verify) a row. Edit a cell content in that row. | ||
# Click a cell in another row. Verify the new row is selected and focused. | ||
# Verify the old row is not selected. Verify the old row cell value was updated. | ||
data_frame.expect_cell("N1A2", row=1, col=6) | ||
data_frame.edit_cell("N2A2", row=1, col=6) | ||
data_frame.expect_row_focus_state(False, row=1) | ||
data_frame.expect_class_state("editing", row=1, col=6) | ||
data_frame.cell_locator(row=2, col=6).click() | ||
data_frame.expect_row_focus_state(True, row=2) | ||
data_frame.expect_row_focus_state(False, row=1) | ||
data_frame.expect_cell("N2A2", row=1, col=6) | ||
|
||
# Enable rows selection and editable. | ||
# Select (and verify) a row. Hit enter to edit the first cell in that row. | ||
# Hit escape key. Verify the same row is focused. | ||
# Scroll right and display an html column in the left part of the view. | ||
# Hit enter to edit the first visible non-html cell in that row. | ||
# Verify that cell is editing. | ||
data_frame.cell_locator(row=1, col=2).click() | ||
page.keyboard.press("Enter") | ||
data_frame.expect_row_focus_state(False, row=1) | ||
page.keyboard.press("Escape") | ||
data_frame.expect_row_focus_state(True, row=1) | ||
page.keyboard.press("Escape") | ||
data_frame.edit_cell("Temp value", row=1, col=16) | ||
page.keyboard.press("Escape") | ||
page.keyboard.press("Enter") | ||
data_frame.expect_class_state("editing", row=1, col=0) | ||
|
||
# Click outside the table/Press Escape to exit row focus. | ||
# Tab to the column name, hit enter. Verify the table becomes sorted. | ||
# Tab to an HTML column name, hit enter. Verify the sort does not update. | ||
page.keyboard.press("Escape") | ||
page.keyboard.press("Escape") | ||
page.keyboard.press("Tab") | ||
page.keyboard.press("Tab") # tab to sample number | ||
page.keyboard.press("Enter") | ||
data_frame.expect_cell("152", row=0, col=1) | ||
page.keyboard.press("Tab") | ||
page.keyboard.press("Enter") | ||
data_frame.expect_cell("Adelie Penguin (Pygoscelis adeliae)", row=0, col=2) |