Skip to content

Commit

Permalink
Merge branch 'main' into 1181-check_visibility@main
Browse files Browse the repository at this point in the history
  • Loading branch information
averissimo authored Mar 27, 2024
2 parents 6fa4653 + 3bdb696 commit 9ab985b
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 54 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: teal
Title: Exploratory Web Apps for Analyzing Clinical Trials Data
Version: 0.15.2.9016
Date: 2024-03-21
Version: 0.15.2.9017
Date: 2024-03-27
Authors@R: c(
person("Dawid", "Kaledkowski", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-9533-457X")),
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# teal 0.15.2.9016
# teal 0.15.2.9017

# teal 0.15.2

Expand Down
58 changes: 54 additions & 4 deletions R/TealAppDriver.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,29 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
#' Initialize a `TealAppDriver` object for testing a `teal` application.
#'
#' @param data,modules,filter,title,header,footer arguments passed to `init`
#' @param timeout (`numeric`) Default number of milliseconds for any timeout or
#' timeout_ parameter in the `TealAppDriver` class.
#' Defaults to 20s.
#'
#' See [`shinytest2::AppDriver`] `new` method for more details on how to change it
#' via options or environment variables.
#' @param load_timeout (`numeric`) How long to wait for the app to load, in ms.
#' This includes the time to start R. Defaults to 100s.
#'
#' See [`shinytest2::AppDriver`] `new` method for more details on how to change it
#' via options or environment variables
#' @param ... Additional arguments to be passed to `shinytest2::AppDriver$new`
#'
#'
#' @return Object of class `TealAppDriver`
initialize = function(data,
modules,
filter = teal_slices(),
title = build_app_title(),
header = tags$p(),
footer = tags$p(),
timeout = rlang::missing_arg(),
load_timeout = rlang::missing_arg(),
...) {
private$data <- data
private$modules <- modules
Expand All @@ -37,16 +51,29 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
header = header,
footer = footer
)

# Default timeout is hardcoded to 4s in shinytest2:::resolve_timeout
# It must be set as parameter to the AppDriver
suppressWarnings(
super$initialize(
shinyApp(app$ui, app$server),
app_dir = shinyApp(app$ui, app$server),
name = "teal",
variant = platform_variant(),
timeout = rlang::maybe_missing(timeout, 20 * 1000),
load_timeout = rlang::maybe_missing(load_timeout, 100 * 1000),
...
)
)

private$set_active_ns()
self$wait_for_idle()
},
#' @description
#' Append parent [`shinytest2::AppDriver`] `click` method with a call to `waif_for_idle()` method.
#' @param ... arguments passed to parent [`shinytest2::AppDriver`] `click()` method.
click = function(...) {
super$click(...)
self$wait_for_idle()
},
#' @description
#' Check if the app has shiny errors. This checks for global shiny errors.
Expand Down Expand Up @@ -112,7 +139,7 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
)
root <- sprintf("%s-%s", private$modules$label, get_unique_labels(tab))
}
self$wait_for_idle(timeout = private$idle_timeout)
self$wait_for_idle()
private$set_active_ns()
invisible(self)
},
Expand Down Expand Up @@ -429,6 +456,31 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
#' @return Nothing. Opens the underlying teal app in the browser.
open_url = function() {
browseURL(self$get_url())
},
#' @description
#' Waits until a specified input, output, or export value.
#' This function serves as a wrapper around the `wait_for_value` method,
#' providing a more flexible interface for waiting on different types of values within the active module namespace.
#' @param input,output,export A name of an input, output, or export value.
#' Only one of these parameters may be used.
#' @param ... Must be empty. Allows for parameter expansion.
#' Parameter with additional value to passed in `wait_for_value`.
wait_for_active_module_value = function(input = rlang::missing_arg(),
output = rlang::missing_arg(),
export = rlang::missing_arg(),
...) {
ns <- shiny::NS(self$active_module_ns())

if (!rlang::is_missing(input) && checkmate::test_string(input, min.chars = 1)) input <- ns(input)
if (!rlang::is_missing(output) && checkmate::test_string(output, min.chars = 1)) output <- ns(output)
if (!rlang::is_missing(export) && checkmate::test_string(export, min.chars = 1)) export <- ns(export)

self$wait_for_value(
input = input,
output = output,
export = export,
...
)
}
),
# private members ----
Expand All @@ -441,8 +493,6 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
module = character(0),
filter_panel = character(0)
),
idle_timeout = 20000, # 20 seconds
load_timeout = 100000, # 100 seconds
# private methods ----
set_active_ns = function() {
all_inputs <- self$get_values()$input
Expand Down
63 changes: 62 additions & 1 deletion man/TealAppDriver.Rd

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

2 changes: 0 additions & 2 deletions tests/testthat/helper-shinytest2.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
library(shinytest2)
library(rvest)

default_idle_timeout <- 20000

simple_teal_data <- function() {
data <- within(teal_data(), {
iris <- iris
Expand Down
10 changes: 0 additions & 10 deletions tests/testthat/test-shinytest2-filter_panel.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ testthat::test_that("e2e: module content is updated when a data is filtered in f
)
)

app$wait_for_idle(timeout = default_idle_timeout)

old_output <- app$get_active_module_output("text")

app$set_active_filter_selection("iris", "Species", c("setosa", "versicolor"))
Expand Down Expand Up @@ -47,20 +45,16 @@ testthat::test_that("e2e: filtering a module-specific filter is refected in othe
)
)

app$wait_for_idle(timeout = default_idle_timeout)

expect_equal(
app$get_active_data_filters("iris")$Species,
c("setosa", "versicolor", "virginica")
)

app$navigate_teal_tab("Module_2")
app$wait_for_idle(timeout = default_idle_timeout)

app$set_active_filter_selection("iris", "Species", c("setosa"))

app$navigate_teal_tab("Module_1")
app$wait_for_idle(timeout = default_idle_timeout)

expect_equal(
app$get_active_data_filters("iris")$Species,
Expand Down Expand Up @@ -90,20 +84,16 @@ testthat::test_that("e2e: filtering a module-specific filter is not refected in
)
)

app$wait_for_idle(timeout = default_idle_timeout)

expect_equal(
app$get_active_data_filters("mtcars")$cyl,
c("4", "6")
)

app$navigate_teal_tab("Module_2")
app$wait_for_idle(timeout = default_idle_timeout)

app$set_active_filter_selection("mtcars", "cyl", c("4"))

app$navigate_teal_tab("Module_1")
app$wait_for_idle(timeout = default_idle_timeout)

expect_equal(
app$get_active_data_filters("mtcars")$cyl,
Expand Down
4 changes: 0 additions & 4 deletions tests/testthat/test-shinytest2-init.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ testthat::test_that("e2e: teal app initializes with no errors", {
data = simple_teal_data(),
modules = example_module(label = "Example Module")
)
app$wait_for_idle(timeout = default_idle_timeout)
app$expect_no_shiny_error()
app$stop()
})
Expand All @@ -15,7 +14,6 @@ testthat::test_that("e2e: teal app initializes with sessionInfo modal", {
data = simple_teal_data(),
modules = example_module(label = "Example Module")
)
app$wait_for_idle(timeout = default_idle_timeout)

# Check if button exists.
button_selector <- "#teal-sessionInfo-button"
Expand All @@ -25,7 +23,6 @@ testthat::test_that("e2e: teal app initializes with sessionInfo modal", {
)

app$click(selector = button_selector)
app$wait_for_idle(timeout = default_idle_timeout)

# Check header and title content.
testthat::expect_equal(
Expand Down Expand Up @@ -82,7 +79,6 @@ testthat::test_that("e2e: init creates UI containing specified title, favicon, h
header = app_header,
footer = app_footer
)
app$wait_for_idle(timeout = default_idle_timeout)

testthat::expect_equal(
app$get_text("head > title")[1],
Expand Down
7 changes: 0 additions & 7 deletions tests/testthat/test-shinytest2-landing_popup.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ testthat::test_that("e2e: teal app with landing_popup_module initializes with no
)
)

app$wait_for_idle(timeout = default_idle_timeout)
testthat::expect_equal(
app$get_text("#landingpopup b"),
"A welcome message!"
Expand All @@ -28,7 +27,6 @@ testthat::test_that("e2e: app with default landing_popup_module creates modal co
example_module()
)
)
app$wait_for_idle(timeout = default_idle_timeout)

testthat::expect_equal(
app$get_text("#shiny-modal-wrapper button"),
Expand All @@ -47,11 +45,9 @@ testthat::test_that("e2e: when default landing_popup_module is closed, it shows
example_module()
)
)
app$wait_for_idle(timeout = default_idle_timeout)

# Button is clicked.
app$click(selector = "#shiny-modal-wrapper button[data-dismiss='modal']")
app$wait_for_idle(timeout = default_idle_timeout)

# There is no more modal displayed.
testthat::expect_null(app$get_html("#shiny-modal-wrapper"))
Expand Down Expand Up @@ -104,8 +100,6 @@ testthat::test_that(
)
)

app$wait_for_idle(timeout = default_idle_timeout)

testthat::expect_equal(
app$get_text(".modal-title"),
modal_title
Expand Down Expand Up @@ -157,7 +151,6 @@ testthat::test_that("e2e: when customized button in landing_popup_module is clic
example_module()
)
)
app$wait_for_idle(timeout = default_idle_timeout)

testthat::expect_equal(
app$get_attr("#read", "onclick"),
Expand Down
Loading

0 comments on commit 9ab985b

Please sign in to comment.