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 7 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
101 changes: 101 additions & 0 deletions tests/testthat/test-shinytest2-tm_g_distribution.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
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 = teal::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")
)
)
)
)
}

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"), 30)
testthat::expect_equal(app_driver$get_active_module_input("main_type"), "Density")
testthat::expect_true(app_driver$get_active_module_input("add_dens"))
testthat::expect_null(app_driver$get_active_module_input("t_dist"))
testthat::expect_identical(app_driver$get_active_module_input("dist_param1"), NA)
testthat::expect_identical(app_driver$get_active_module_input("dist_param2"), NA)
testthat::expect_null(app_driver$get_active_module_input("dist_tests"))
testthat::expect_equal(app_driver$get_active_module_input("roundn"), 2)
testthat::expect_equal(app_driver$get_active_module_input("ggtheme"), "gray")
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: encoding inputs produce output without validation errors", {
skip_if_too_deep(5)

app_driver <- app_driver_tm_g_distribution()

# Encodings in the Histogram tab
app_driver$set_active_module_input("group_i-dataset_ADSL_singleextract-filter1-col", "ARM")
app_driver$set_active_module_input("group_i-dataset_ADSL_singleextract-filter1-vals", c("A: Drug X", "C: Combination"))

Check warning on line 86 in tests/testthat/test-shinytest2-tm_g_distribution.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=tests/testthat/test-shinytest2-tm_g_distribution.R,line=86,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 121 characters.
app_driver$set_active_module_input("scales_type", "Free")
app_driver$set_active_module_input("strata_i-dataset_ADSL_singleextract-filter1-col", "COUNTRY")
app_driver$set_active_module_input("strata_i-dataset_ADSL_singleextract-filter1-vals", c("USA", "CAN", "BRA"))
app_driver$set_active_module_input("bins", 50)
app_driver$set_active_module_input("add_dens", FALSE)

# Encodings in the QQplot tab
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