Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions R/TealAppDriver.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
#' @description
#' Initialize a `TealAppDriver` object for testing a `teal` application.
#'
#' @param app (`teal_app`)
#' @param app (`teal_app` or `list`) Accept the object created by the `init()` function or
#' a list of `ui` and `server` elements that contains teal as a shiny module.
#' @param options (`list`) passed to `shinyApp(options)`. See [shiny::shinyApp()].
#' @param timeout (`numeric`) Default number of milliseconds for any timeout or
#' timeout_ parameter in the `TealAppDriver` class.
Expand All @@ -47,7 +48,16 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
timeout = rlang::missing_arg(),
load_timeout = rlang::missing_arg(),
...) {
checkmate::assert_class(app, "teal_app")
checkmate::assert_class(app, c("teal_app", "list"))
if (inherits(app, "list")) {
checkmate::assert_names(
names(app),
must.include = c("ui", "server"),
subset.of = c("ui", "server")
)
checkmate::assert_function(app$server, args = c("input", "output", "session"))
checkmate::assert_class(app$ui, "shiny.tag")
}
# Default timeout is hardcoded to 4s in shinytest2:::resolve_timeout
# It must be set as parameter to the AppDriver
suppressWarnings(
Expand Down
3 changes: 2 additions & 1 deletion man/TealAppDriver.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 4 additions & 16 deletions tests/testthat/test-shinytest2-reporter.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ testthat::test_that("e2e: reporter tab is visible when reporter is specified (de

testthat::test_that("e2e: reporter tab is visible when the teal ui creation is delayed", {
skip_if_too_deep(5)
app <- shinytest2::AppDriver$new(
shiny::shinyApp(
app <- TealAppDriver$new(
list(
ui = bslib::page_fluid(
uiOutput("teal_as_shiny_module")
),
Expand All @@ -30,22 +30,10 @@ testthat::test_that("e2e: reporter tab is visible when the teal ui creation is d
})
srv_teal("teal", data = teal_data(iris = iris), modules = mods)
}
),
height = 1000,
width = 1000
)

# Runs the same check as `app$is_visible` to check if the selector is visible
testthat::expect_true(
unlist(
app$get_js(
sprintf(
"Array.from(document.querySelectorAll('%s')).map(el => el.checkVisibility({}))",
"#teal-reporter_menu_container"
)
)
)
)

testthat::expect_true(app$is_visible(selector = "#teal-reporter_menu_container"))
app$stop()
})

Expand Down
Loading