Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

712 - {shinytest2} for tm_g_distribution #726

Merged
merged 16 commits into from
Apr 19, 2024
Merged
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
129 changes: 129 additions & 0 deletions tests/testthat/test-shinytest2-tm_g_distribution.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
app_driver_tm_g_distribution <- function() {
data <- teal.data::teal_data()
data <- within(data, {
ADSL <- rADSL
})
teal.data::datanames(data) <- c("ADSL")
teal.data::join_keys(data) <- teal.data::default_cdisc_join_keys[teal.data::datanames(data)]

vars1 <- teal.transform::choices_selected(
teal.transform::variable_choices(data[["ADSL"]], c("ARM", "COUNTRY", "SEX")),
selected = NULL
)

init_teal_app_driver(
data = data,
modules = tm_g_distribution(
dist_var = teal.transform::data_extract_spec(
dataname = "ADSL",
select = teal.transform::select_spec(
choices = teal.transform::variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")),
selected = "BMRKR1",
multiple = FALSE,
fixed = FALSE
)
),
strata_var = teal.transform::data_extract_spec(
dataname = "ADSL",
filter = teal.transform::filter_spec(
vars = vars1,
multiple = TRUE
)
),
group_var = teal.transform::data_extract_spec(
dataname = "ADSL",
filter = teal.transform::filter_spec(
vars = vars1,
multiple = TRUE
)
),
ggplot2_args = teal.widgets::ggplot2_args(
labs = list(subtitle = "Plot generated by Distribution Module")
),
ggtheme = "classic",
freq = TRUE,
bins = 36,
)
)
}

testthat::test_that("e2e - tm_g_distribution: module is initialised with the specified defaults", {
skip_if_too_deep(5)

app_driver <- app_driver_tm_g_distribution()

app_driver$expect_no_shiny_error()

# Encodings in the Histogram tab
testthat::expect_equal(app_driver$get_active_module_input("dist_i-dataset_ADSL_singleextract-select"), "BMRKR1")
testthat::expect_null(app_driver$get_active_module_input("group_i-dataset_ADSL_singleextract-filter1-col"))
testthat::expect_null(app_driver$get_active_module_input("group_i-dataset_ADSL_singleextract-filter1-vals"))
testthat::expect_null(app_driver$get_active_module_input("strata_i-dataset_ADSL_singleextract-filter1-col"))
testthat::expect_equal(app_driver$get_active_module_input("bins"), 36)
testthat::expect_equal(app_driver$get_active_module_input("main_type"), "Frequency")
testthat::expect_equal(app_driver$get_active_module_input("ggtheme"), "classic")
testthat::expect_equal(app_driver$get_active_module_input("tabs"), "Histogram")

# Encodings in the QQplot tab
app_driver$set_active_module_input("tabs", "QQplot")
testthat::expect_true(app_driver$get_active_module_input("qq_line"))

app_driver$stop()
})

testthat::test_that("e2e - tm_g_distribution: histogram encoding inputs produce output without validation errors", {
skip_if_too_deep(5)

app_driver <- app_driver_tm_g_distribution()

app_driver$set_active_module_input("main_type", "Density")
app_driver$expect_validation_error() # test needs to be updated to remove validation error
app_driver$set_active_module_input("dist_tests", "Shapiro-Wilk")

# Encodings in the Histogram tab
app_driver$set_active_module_input("group_i-dataset_ADSL_singleextract-filter1-col", "ARM")
app_driver$expect_no_validation_error()

app_driver$set_active_module_input(
"group_i-dataset_ADSL_singleextract-filter1-vals",
c("A: Drug X", "C: Combination")
)
app_driver$expect_no_validation_error()

app_driver$set_active_module_input("scales_type", "Free")
app_driver$expect_no_validation_error()

app_driver$set_active_module_input("strata_i-dataset_ADSL_singleextract-filter1-col", "SEX")
app_driver$expect_no_validation_error()

app_driver$set_active_module_input("strata_i-dataset_ADSL_singleextract-filter1-vals", c("F"))
app_driver$expect_no_validation_error()

app_driver$set_active_module_input("bins", 50)
app_driver$expect_no_validation_error()

app_driver$set_active_module_input("add_dens", FALSE)
app_driver$expect_no_validation_error()

app_driver$stop()
})

testthat::test_that("e2e - tm_g_distribution: qqplot encoding inputs produce output without validation errors", {
skip_if_too_deep(5)

app_driver <- app_driver_tm_g_distribution()

# Encodings in the QQplot tab
app_driver$set_active_module_input("main_type", "Density")
app_driver$expect_validation_error() # test needs to be updated to remove validation error
app_driver$set_active_module_input("dist_tests", "Shapiro-Wilk")
app_driver$expect_no_validation_error()

app_driver$set_active_module_input("tabs", "QQplot")
app_driver$set_active_module_input("t_dist", "normal")
app_driver$click(NS(app_driver$active_module_ns(), "params_reset"))

app_driver$expect_no_validation_error()
averissimo marked this conversation as resolved.
Show resolved Hide resolved

app_driver$stop()
})
Loading