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

310-311: Sidebar tests with dynamic UI, tabfocus order, sidebar_toggle() #164

Merged
merged 14 commits into from
May 9, 2023

Conversation

gadenbuie
Copy link
Member

@gadenbuie gadenbuie commented May 3, 2023

Two test suites around the bslib sidebar implementation:

  1. 310-bslib-sidebar-dynamic tests the sidebar when added to the page dynamically. The sidebar dependencies are not present on page load but are included when the sidebars are added via insertUI(). We test general function and form of the sidebar, in particular around initialization state and the collapse toggle event handlers that would not work correctly if the sidebar dependencies did not include special post-page-load initialization methods.

  2. 311-bslib-sidebar-toggle-methods tests the tab focus order of nested sidebars and all of the related sidebar toggling methods, including server-side sidebar_toggle().

@gadenbuie gadenbuie marked this pull request as ready for review May 5, 2023 21:36
@gadenbuie gadenbuie requested review from cpsievert and schloerke May 5, 2023 21:36
Comment on lines 18 to 69
key_press_factory <- function(app) {
brwsr <- app$get_chromote_session()

function(which = "Tab", shift = FALSE) {
virtual_code <- switch(
which,
Tab = 9,
Enter = 13,
Escape = 27,
ArrowLeft = 37,
ArrowUp = 38,
ArrowRight = 39,
ArrowDown = 40,
Backspace = 8,
Delete = 46,
Home = 36,
End = 35,
PageUp = 33,
PageDown = 34,
Space = 32
)

modifiers <- 0
if (shift) modifiers <- modifiers + 8
# if (command) modifiers <- modifiers + 4
# if (control) modifiers <- modifiers + 2
# if (alt) modifiers <- modifiers + 1

events <-
brwsr$Input$dispatchKeyEvent(
"rawKeyDown",
windowsVirtualKeyCode = virtual_code,
code = which,
key = which,
modifiers = modifiers,
wait_ = FALSE
)$then(
brwsr$Input$dispatchKeyEvent(
"keyUp",
windowsVirtualKeyCode = virtual_code,
code = which,
key = which,
modifiers = modifiers,
wait_ = FALSE
)
)

brwsr$wait_for(events)

invisible(app)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should something like this be added to shinytest2?
Related: rstudio/shinytest2#33

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! I'd consider this a first rough draft for something that I'd love to see in shinytest2.

I found some helpful source data in the playwright repo: https://github.com/microsoft/playwright/blob/1f209204cd18bce7d1bfae50f5af105dec752df8/packages/playwright-core/src/server/usKeyboardLayout.ts

Two things that would be useful to take into account:

  1. For completeness it'd be helpful to be able to do keydown, keyup and key "press" events.
  2. AFAICT, the difference between rawKeyDown and keyDown is that with rawKeyDown no text is expected to be entered. Playwright takes that into account and in the user-facing api that's also described here

inst/apps/310-bslib-sidebar-dynamic/README.md Outdated Show resolved Hide resolved
@gadenbuie gadenbuie changed the title 310: Sidebar tests with dynamic UI 310-311: Sidebar tests with dynamic UI May 8, 2023
@gadenbuie gadenbuie changed the title 310-311: Sidebar tests with dynamic UI 310-311: Sidebar tests with dynamic UI, tabfocus order, sidebar_toggle() May 8, 2023
@cpsievert cpsievert mentioned this pull request May 8, 2023
@gadenbuie gadenbuie merged commit 6945307 into main May 9, 2023
@gadenbuie gadenbuie deleted the 310-bslib-sidebar-dynamic branch May 9, 2023 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants