diff --git a/R/TealAppDriver.R b/R/TealAppDriver.R index 2506fe1102..67435383e2 100644 --- a/R/TealAppDriver.R +++ b/R/TealAppDriver.R @@ -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. @@ -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( diff --git a/man/TealAppDriver.Rd b/man/TealAppDriver.Rd index 2d8560ac96..0ccc900571 100644 --- a/man/TealAppDriver.Rd +++ b/man/TealAppDriver.Rd @@ -99,7 +99,8 @@ Initialize a \code{TealAppDriver} object for testing a \code{teal} application. \subsection{Arguments}{ \if{html}{\out{
}} \describe{ -\item{\code{app}}{(\code{teal_app})} +\item{\code{app}}{(\code{teal_app} or \code{list}) Accept the object created by the \code{init()} function or +a list of \code{ui} and \code{server} elements that contains teal as a shiny module.} \item{\code{options}}{(\code{list}) passed to \code{shinyApp(options)}. See \code{\link[shiny:shinyApp]{shiny::shinyApp()}}.} diff --git a/tests/testthat/test-shinytest2-reporter.R b/tests/testthat/test-shinytest2-reporter.R index 73e99b019c..d2e7f7ee8a 100644 --- a/tests/testthat/test-shinytest2-reporter.R +++ b/tests/testthat/test-shinytest2-reporter.R @@ -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") ), @@ -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() })