Skip to content

Commit

Permalink
Fix function scoping issue
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert committed Jul 26, 2023
1 parent be64141 commit 9c5006e
Showing 1 changed file with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ source(system.file("helpers", "keyboard.R", package = "shinycoreci"))

expect_focus <- function(app, selector) {
js <- sprintf(
"document.activeElement == document.querySelector('%s')",
"document.activeElement === document.querySelector('%s')",
selector
)
expect_true(app$get_js(!!js))
Expand All @@ -40,6 +40,23 @@ withr::defer(app$stop())

key_press <- key_press_factory(app)

# Before focusing any tooltips, set up an event handler to keep track of
# the last tooltip shown
app$run_js(
'$(document).on("shown.bs.tooltip", function(e) { window.lastShown = e.target; });'
)

# lastShown should contain the trigger element, which we can use to find the
# actual tooltip (we just make sure it's visible).
expect_visible_tip <- function(app, selector) {
app$wait_for_js(
sprintf("window.lastShown === document.querySelector('%s')", selector)
)
app$wait_for_js(
"var tipId = window.lastShown.getAttribute('aria-describedby');
$(`#${tipId}:visible`).length > 0;"
)
}

# Tests for the 1st tab (Tooltip cases)
test_that("Can tab focus various cases/options", {
Expand All @@ -48,24 +65,6 @@ test_that("Can tab focus various cases/options", {
key_press("Tab")
expect_focus(app, ".nav-link.active")

# Before focusing any tooltips, set up an event handler to keep track of
# the last tooltip shown
app$run_js(
'$(document).on("shown.bs.tooltip", function(e) { window.lastShown = e.target; });'
)

# lastShown should contain the trigger element, which we can use to find the
# actual tooltip (we just make sure it's visible).
expect_visible_tip <- function(app, selector) {
app$wait_for_js(
sprintf("window.lastShown === document.querySelector('%s')", selector)
)
app$wait_for_js(
"var tipId = window.lastShown.getAttribute('aria-describedby');
$(`#${tipId}:visible`).length > 0;"
)
}

# Placement ----------------------------------
key_press("Tab")
expect_focus(app, "#tip-auto")
Expand Down

0 comments on commit 9c5006e

Please sign in to comment.