Skip to content

Commit

Permalink
adding driver to shinytest2 file.
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikeyakirar committed Apr 15, 2024
1 parent 95e2dbb commit 90357fd
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 41 deletions.
39 changes: 0 additions & 39 deletions tests/testthat/helper-TealAppDriver.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,42 +27,3 @@ simple_cdisc_data <- function(datasets = c("ADSL", "ADRS", "ADTTE")) {
teal.data::join_keys(data) <- teal.data::default_cdisc_join_keys[datasets]
data
}

# local app drivers for module testing ----------------------------------------
# based on examples

app_driver_tm_missing_data <- function() {
data <- within(simple_teal_data(), {
require(nestcolor)

add_nas <- function(x) {
x[sample(seq_along(x), floor(length(x) * runif(1, .05, .17)))] <- NA
x
}

iris[] <- lapply(iris, add_nas)
mtcars[] <- lapply(mtcars, add_nas)
mtcars[["cyl"]] <- as.factor(mtcars[["cyl"]])
mtcars[["gear"]] <- as.factor(mtcars[["gear"]])
})

TealAppDriver$new(
data = data,
modules = tm_missing_data(
label = "Missing data",
plot_height = c(600, 400, 5000),
plot_width = NULL,
parent_dataname = "",
ggtheme = "gray",
ggplot2_args = list(
"Combinations Hist" = teal.widgets::ggplot2_args(
labs = list(subtitle = "Plot produced by Missing Data Module", caption = NULL)
),
"Combinations Main" = teal.widgets::ggplot2_args(labs = list(title = NULL))
),
pre_output = NULL,
post_output = NULL
),
timeout = 3000
)
}
84 changes: 82 additions & 2 deletions tests/testthat/test-shinytest2-tm_misssing_data.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,106 @@
app_driver_tm_missing_data <- function() {
data <- within(simple_teal_data(), {
require(nestcolor)

add_nas <- function(x) {
x[sample(seq_along(x), floor(length(x) * runif(1, .05, .17)))] <- NA
x
}

iris[] <- lapply(iris, add_nas)
mtcars[] <- lapply(mtcars, add_nas)
mtcars[["cyl"]] <- as.factor(mtcars[["cyl"]])
mtcars[["gear"]] <- as.factor(mtcars[["gear"]])
})

TealAppDriver$new(
data = data,
modules = tm_missing_data(
label = "Missing data",
plot_height = c(600, 400, 5000),
plot_width = NULL,
parent_dataname = "",
ggtheme = "gray",
ggplot2_args = list(
"Combinations Hist" = teal.widgets::ggplot2_args(
labs = list(subtitle = "Plot produced by Missing Data Module", caption = NULL)
),
"Combinations Main" = teal.widgets::ggplot2_args(labs = list(title = NULL))
),
pre_output = NULL,
post_output = NULL
),
timeout = 3000
)
}

test_that("e2e: tm_missing_data initializes without errors and shows encodings", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_missing_data()

app_driver$expect_no_shiny_error()
app_driver$stop()
})

test_that("e2e: Default settings and visibility of the summary graph", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_missing_data()
# default summary tab
testthat::expect_equal(app_driver$get_active_module_input("iris-summary_type"),
"Summary")

testthat::expect_setequal(app_driver$get_active_module_input("iris-variables_select"),
c("Petal.Length", "Sepal.Length", "Petal.Width", "Species", "Sepal.Width"))



app_driver$click(selector = app_driver$active_module_element("iris-filter_na"))
app_driver$expect_no_validation_error()

app_driver$click(selector = app_driver$active_module_element("iris-any_na"))
app_driver$expect_no_validation_error()

app_driver$set_module_input("iris-ggtheme", "classic", timeout_ = 10000)

app_driver$set_module_input(input_id = "iris-summary_type", "Summary")
testthat::expect_true(app_driver$is_visible(app_driver$active_module_element("iris-summary_plot")))

app_driver$stop()
})

test_that("e2e: Check default settings and visibility of the combinations graph and encodings", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_missing_data()

app_driver$expect_no_shiny_error()

# combination graph

app_driver$set_module_input(input_id = "iris-summary_type", "Combinations")
app_driver$expect_no_validation_error()
testthat::expect_true(app_driver$is_visible(app_driver$active_module_element("iris-combination_plot")))

app_driver$stop()
})

test_that("e2e: Validate functionality and UI response for 'By Variable Levels'", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_missing_data()
# BY variablelevels
app_driver$set_module_input(input_id = "iris-summary_type", "By Variable Levels")
app_driver$expect_no_validation_error()


testthat::expect_equal(app_driver$get_active_module_input("iris-group_by_var"),
"Species")
testthat::expect_setequal(app_driver$get_active_module_input("iris-group_by_vals"),
c("NA", "setosa", "versicolor", "virginica"))

app_driver$set_module_input(input_id = "iris-group_by_vals", c("versicolor", "virginica"))
app_driver$expect_no_validation_error()

testthat::expect_equal(app_driver$get_active_module_input("iris-count_type"),
"counts")
app_driver$set_module_input("iris-count_type", "proportions")
testthat::expect_true(app_driver$is_visible(app_driver$active_module_element("iris-levels_table")))

app_driver$stop()
})

0 comments on commit 90357fd

Please sign in to comment.