-
Notifications
You must be signed in to change notification settings - Fork 7
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
Conversation
inst/apps/310-bslib-sidebar-dynamic/tests/testthat/test-shinytest2.R
Outdated
Show resolved
Hide resolved
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) | ||
} | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
- For completeness it'd be helpful to be able to do keydown, keyup and key "press" events.
- AFAICT, the difference between
rawKeyDown
andkeyDown
is that withrawKeyDown
no text is expected to be entered. Playwright takes that into account and in the user-facing api that's also described here
sidebar_toggle()
Two test suites around the bslib sidebar implementation:
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 viainsertUI()
. 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.311-bslib-sidebar-toggle-methods
tests the tab focus order of nested sidebars and all of the related sidebar toggling methods, including server-sidesidebar_toggle()
.