Skip to content

Commit e1eeb76

Browse files
llrs-rocheaverissimogithub-actions[bot]
authored
Add shinytest2 tests for bslib (#653)
Co-authored-by: André Veríssimo <[email protected]> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 466fbe0 commit e1eeb76

File tree

7 files changed

+409
-12
lines changed

7 files changed

+409
-12
lines changed

DESCRIPTION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ Imports:
5656
teal.widgets (>= 0.4.3),
5757
utils
5858
Suggests:
59+
DT (>= 0.13),
5960
knitr (>= 1.42),
6061
MultiAssayExperiment,
6162
rmarkdown (>= 2.23),
63+
shinytest2 (>= 0.4.1),
6264
SummarizedExperiment,
6365
testthat (>= 3.2.2),
6466
withr (>= 3.0.2)
@@ -72,7 +74,7 @@ Config/Needs/verdepcheck: rstudio/shiny, rstudio/bslib, mllg/checkmate,
7274
daroczig/logger, plotly/plotly, r-lib/R6, daattali/shinycssloaders,
7375
daattali/shinyjs, dreamRs/shinyWidgets, insightsengineering/teal.data,
7476
insightsengineering/teal.logger, insightsengineering/teal.widgets,
75-
yihui/knitr, bioc::MultiAssayExperiment, bioc::SummarizedExperiment,
77+
rstudio/DT, yihui/knitr, bioc::MultiAssayExperiment, bioc::SummarizedExperiment,
7678
rstudio/rmarkdown, r-lib/testthat, r-lib/withr, bioc::matrixStats
7779
Config/Needs/website: insightsengineering/nesttemplate
7880
Encoding: UTF-8

R/FilteredData.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ FilteredData <- R6::R6Class( # nolint
532532
include_js_files(pattern = "togglePanelItems"),
533533
class = "teal-slice",
534534
bslib::accordion(
535-
id = ns("main_filter_accordian"),
535+
id = ns("main_filter_accordion"),
536536
bslib::accordion_panel(
537537
"Filter Data",
538538
tags$div(
@@ -578,8 +578,8 @@ FilteredData <- R6::R6Class( # nolint
578578
});
579579
",
580580
ns("additional_filter_helpers"),
581-
ns("main_filter_accordian"),
582-
ns("main_filter_accordian"),
581+
ns("main_filter_accordion"),
582+
ns("main_filter_accordion"),
583583
ns("additional_filter_helpers")
584584
)
585585
)
@@ -710,7 +710,7 @@ FilteredData <- R6::R6Class( # nolint
710710
tags$div(
711711
class = "teal-slice",
712712
bslib::accordion(
713-
id = ns("main_filter_accordian"),
713+
id = ns("main_filter_accordion"),
714714
bslib::accordion_panel(
715715
title = "Active Filter Summary",
716716
tags$div(

R/FilteredDataset.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ FilteredDataset <- R6::R6Class( # nolint
242242
include_css_files("filter-panel"),
243243
include_js_files(pattern = "icons"),
244244
bslib::accordion(
245-
id = session$ns("dataset_filter_accordian"),
245+
id = session$ns("dataset_filter_accordion"),
246246
class = "teal-slice-dataset-filter",
247247
bslib::accordion_panel(
248248
dataname,
@@ -298,10 +298,10 @@ FilteredDataset <- R6::R6Class( # nolint
298298
});
299299
",
300300
session$ns("filter_util_icons"),
301-
session$ns("dataset_filter_accordian"),
302-
session$ns("dataset_filter_accordian"),
301+
session$ns("dataset_filter_accordion"),
302+
session$ns("dataset_filter_accordion"),
303303
session$ns("active_filter_badge"),
304-
session$ns("dataset_filter_accordian")
304+
session$ns("dataset_filter_accordion")
305305
)
306306
)
307307
)
@@ -344,7 +344,7 @@ FilteredDataset <- R6::R6Class( # nolint
344344
$('#%s .accordion-button.collapsed').click();
345345
}",
346346
session$ns("add_panel"),
347-
session$ns("dataset_filter_accordian")
347+
session$ns("dataset_filter_accordion")
348348
)
349349
)
350350
),
@@ -387,8 +387,8 @@ FilteredDataset <- R6::R6Class( # nolint
387387

388388
# If the accordion input is `NULL` it is being collapsed.
389389
# It has the accordion panel label if it is expanded.
390-
observeEvent(input$dataset_filter_accordian, ignoreNULL = FALSE, {
391-
if (is.null(input$dataset_filter_accordian)) {
390+
observeEvent(input$dataset_filter_accordion, ignoreNULL = FALSE, {
391+
if (is.null(input$dataset_filter_accordion)) {
392392
# Hiding the `add_panel` dropdown and changing the minus icon to plus
393393
# TODO: simplify this implementation. This is done in multiple places
394394
shinyjs::runjs(
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
default_idle_timeout <- 20000 # Wait (ms) at most until idle
2+
default_idle_duration <- 200 # Time (ms) it is idle
3+
4+
# Check visibility (borrowed from teal.widgets/tests/testthat/helpers-utils.R)
5+
is_visible <- function(app_driver, element) {
6+
js_script <- sprintf("
7+
Array.from(document.querySelectorAll('%s')).map(el => {
8+
return el.checkVisibility() && (el.textContent.trim().length > 0 || el.children.length > 0);
9+
});
10+
", element)
11+
12+
any(unlist(app_driver$get_js(js_script)))
13+
}
14+
15+
# Write a js code to extract the classes
16+
get_attribute <- function(selector, attribute) {
17+
sprintf(
18+
"Array.from(document.querySelectorAll('%s')).map(el => el.getAttribute('%s'))",
19+
selector, attribute
20+
)
21+
}
22+
23+
is_existing <- function(app_driver, element) {
24+
js_script <- sprintf("document.querySelectorAll('%s').length > 0;", element)
25+
app_driver$get_js(js_script)
26+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#' Returns testing depth set by session option or by environmental variable.
2+
#'
3+
#' @details Looks for the session option `TESTING_DEPTH` first.
4+
#' If not set, takes the system environmental variable `TESTING_DEPTH`.
5+
#' If neither is set, then returns 3 by default.
6+
#' If the value of `TESTING_DEPTH` is not a numeric of length 1, then returns 3.
7+
#'
8+
#' @return `numeric(1)` the testing depth.
9+
#'
10+
get_testing_depth <- function() {
11+
default_depth <- 3
12+
depth <- getOption("TESTING_DEPTH", Sys.getenv("TESTING_DEPTH", default_depth))
13+
depth <- tryCatch(
14+
as.numeric(depth),
15+
error = function(error) default_depth,
16+
warning = function(warning) default_depth
17+
)
18+
if (length(depth) != 1) depth <- default_depth
19+
depth
20+
}
21+
22+
#' Skipping tests in the testthat pipeline under specific scope
23+
#' @description This function should be used per each `testthat::test_that` call.
24+
#' Each of the call should specify an appropriate depth value.
25+
#' The depth value will set the appropriate scope so more/less time consuming tests could be recognized.
26+
#' The environment variable `TESTING_DEPTH` is used for changing the scope of `testthat` pipeline.
27+
#' `TESTING_DEPTH` interpretation for each possible value:
28+
#' \itemize{
29+
#' \item{0}{no tests at all}
30+
#' \item{1}{fast - small scope - executed on every commit}
31+
#' \item{3}{medium - medium scope - daily integration pipeline}
32+
#' \item{5}{slow - all tests - daily package tests}
33+
#' }
34+
#' @param depth `numeric` the depth of the testing evaluation,
35+
#' has opposite interpretation to environment variable `TESTING_DEPTH`.
36+
#' So e.g. `0` means run it always and `5` means a heavy test which should be run rarely.
37+
#' If the `depth` argument is larger than `TESTING_DEPTH` then the test is skipped.
38+
#' @importFrom testthat skip
39+
#' @return `NULL` or invoke an error produced by `testthat::skip`
40+
#' @note By default `TESTING_DEPTH` is equal to 3 if there is no environment variable for it.
41+
#' By default `depth` argument lower or equal to 3 will not be skipped because by default `TESTING_DEPTH`
42+
#' is equal to 3. To skip <= 3 depth tests then the environment variable has to be lower than 3 respectively.
43+
skip_if_too_deep <- function(depth) { # nolintr
44+
checkmate::assert_numeric(depth, len = 1, lower = 0, upper = 5)
45+
testing_depth <- get_testing_depth() # by default 3 if there are no env variable
46+
if (testing_depth < depth) {
47+
testthat::skip(paste("testing depth", testing_depth, "is below current testing specification", depth))
48+
}
49+
}
50+
51+
default_idle_timeout <- 20000

0 commit comments

Comments
 (0)