Skip to content

Commit

Permalink
Wave 4 - tm_t_ancova shinytests (#1154)
Browse files Browse the repository at this point in the history
Part of #1108

---------

Co-authored-by: unknown <[email protected]>
  • Loading branch information
vedhav and kartikeyakirar authored May 7, 2024
1 parent 5754243 commit dec314f
Showing 1 changed file with 266 additions and 0 deletions.
266 changes: 266 additions & 0 deletions tests/testthat/test-shinytest2-tm_t_ancova.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
app_driver_tm_t_ancova <- function() {
data <- teal.data::teal_data() %>%
within({
ADSL <- tmc_ex_adsl
ADQS <- tmc_ex_adqs
})

datanames <- c("ADSL", "ADQS")
teal.data::datanames(data) <- datanames
teal.data::join_keys(data) <- teal.data::default_cdisc_join_keys[datanames]

arm_ref_comp <- list(
ARM = list(
ref = "B: Placebo",
comp = c("A: Drug X", "C: Combination")
),
ACTARMCD = list(
ref = "ARM B",
comp = c("ARM A", "ARM C")
)
)

init_teal_app_driver(
data = data,
modules = tm_t_ancova(
label = "ANCOVA Table",
dataname = "ADQS",
parentname = "ADSL",
avisit = teal.transform::choices_selected(
choices = teal.transform::value_choices(data[["ADQS"]], "AVISIT"),
selected = "WEEK 1 DAY 8"
),
arm_var = teal.transform::choices_selected(
choices = teal.transform::variable_choices(data[["ADSL"]], c("ARM", "ACTARMCD", "ARMCD")),
selected = "ARMCD"
),
arm_ref_comp = arm_ref_comp,
aval_var = teal.transform::choices_selected(
choices = teal.transform::variable_choices(data[["ADQS"]], c("CHG", "AVAL")),
selected = "CHG"
),
cov_var = teal.transform::choices_selected(
choices = teal.transform::variable_choices(data[["ADQS"]], c("BASE", "STRATA1", "SEX")),
selected = "STRATA1"
),
paramcd = teal.transform::choices_selected(
choices = teal.transform::value_choices(data[["ADQS"]], "PARAMCD", "PARAM"),
selected = "FKSI-FWB"
),
interact_var = teal.transform::choices_selected(
choices = teal.transform::variable_choices(data[["ADQS"]], c("BASE", "STRATA1", "SEX")),
selected = "STRATA1"
),
conf_level = teal.transform::choices_selected(c(2, 0.95, 0.9, 0.8), 0.95, keep_order = TRUE),
include_interact = FALSE,
interact_y = FALSE,
pre_output = NULL,
post_output = NULL,
basic_table_args = teal.widgets::basic_table_args()
)
)
}

testthat::test_that("e2e - tm_t_ancova: Module initializes in teal without errors and produces table output.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_ancova()
app_driver$expect_no_shiny_error()
app_driver$expect_no_validation_error()
testthat::expect_true(
app_driver$is_visible(app_driver$active_module_element("table-table-with-settings"))
)
app_driver$stop()
})

testthat::test_that(
"e2e - tm_t_ancova: Starts with specified label, avisit, paramcd, aval_var, aval_var,
arm_var, buckets, combine_comp_arms, interact_var, cov_var, conf_level, include_interact.",
{
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_ancova()

testthat::expect_equal(
app_driver$get_text("#teal-main_ui-root-active_tab > li.active > a"),
"ANCOVA Table"
)
testthat::expect_equal(
app_driver$get_active_module_input("avisit-dataset_ADQS_singleextract-filter1-vals"),
"WEEK 1 DAY 8"
)
testthat::expect_equal(
app_driver$get_active_module_input("avisit-dataset_ADQS_singleextract-select"),
"AVISIT"
)
testthat::expect_equal(
app_driver$get_active_module_input("paramcd-dataset_ADQS_singleextract-filter1-vals"),
"FKSI-FWB"
)
testthat::expect_equal(
app_driver$get_active_module_input("aval_var-dataset_ADQS_singleextract-select"),
"CHG"
)
testthat::expect_equal(
app_driver$get_active_module_input("arm_var-dataset_ADSL_singleextract-select"),
"ARMCD"
)
testthat::expect_equal(
app_driver$get_active_module_input("buckets"),
list(
Ref = list("ARM A"),
Comp = list("ARM B", "ARM C")
)
)
testthat::expect_false(app_driver$get_active_module_input("combine_comp_arms"))
testthat::expect_equal(
app_driver$get_active_module_input("interact_var-dataset_ADQS_singleextract-select"),
"STRATA1"
)
testthat::expect_equal(
app_driver$get_active_module_input("cov_var-dataset_ADQS_singleextract-select"),
"STRATA1"
)
testthat::expect_equal(
app_driver$get_active_module_input("conf_level"),
"0.95"
)
testthat::expect_false(app_driver$get_active_module_input("include_interact"))
app_driver$stop()
}
)

testthat::test_that(
"e2e - tm_t_ancova: Selecting avisit-level changes the table and does not throw validation errors.",
{
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_ancova()
table_before <- app_driver$get_active_module_tws_output("table")
app_driver$set_active_module_input(
"avisit-dataset_ADQS_singleextract-filter1-vals",
c("WEEK 1 DAY 8", "WEEK 2 DAY 15")
)
testthat::expect_false(identical(table_before, app_driver$get_active_module_tws_output("table")))
app_driver$expect_no_validation_error()
app_driver$stop()
}
)

testthat::test_that("e2e - tm_t_ancova: Deselection of avisit-level throws validation error.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_ancova()
app_driver$set_active_module_input("avisit-dataset_ADQS_singleextract-filter1-vals", NULL)
testthat::expect_identical(app_driver$get_active_module_tws_output("table"), data.frame())
app_driver$expect_validation_error()
testthat::expect_equal(
app_driver$active_module_element_text(
"avisit-dataset_ADQS_singleextract-filter1-vals_input .shiny-validation-message"
),
"`Analysis Visit` field cannot be empty."
)
app_driver$stop()
})

testthat::test_that(
"e2e - tm_t_ancova: Selecting paramcd-level changes the table and does not throw validation errors.",
{
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_ancova()
table_before <- app_driver$get_active_module_tws_output("table")
app_driver$set_active_module_input("paramcd-dataset_ADQS_singleextract-filter1-vals", c("BFIALL", "FATIGI"))
testthat::expect_false(identical(table_before, app_driver$get_active_module_tws_output("table")))
app_driver$expect_no_validation_error()
app_driver$stop()
}
)

testthat::test_that("e2e - tm_t_ancova: Deselection of paramcd-level throws validation error.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_ancova()
app_driver$set_active_module_input("paramcd-dataset_ADQS_singleextract-filter1-vals", NULL)
testthat::expect_identical(app_driver$get_active_module_tws_output("table"), data.frame())
app_driver$expect_validation_error()
testthat::expect_equal(
app_driver$active_module_element_text(
"paramcd-dataset_ADQS_singleextract-filter1-vals_input .shiny-validation-message"
),
"`Select Endpoint` is not selected."
)
app_driver$stop()
})

testthat::test_that(
"e2e - tm_t_ancova: Selecting aval_var-variable changes the table and does not throw validation errors.",
{
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_ancova()
table_before <- app_driver$get_active_module_tws_output("table")
app_driver$set_active_module_input("aval_var-dataset_ADQS_singleextract-select", "AVAL")
testthat::expect_false(identical(table_before, app_driver$get_active_module_tws_output("table")))
app_driver$expect_no_validation_error()
app_driver$stop()
}
)

testthat::test_that("e2e - tm_t_ancova: Deselection of aval_var-variable throws validation error.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_ancova()
app_driver$set_active_module_input("aval_var-dataset_ADQS_singleextract-select", NULL)
testthat::expect_identical(app_driver$get_active_module_tws_output("table"), data.frame())
app_driver$expect_validation_error()
testthat::expect_equal(
app_driver$active_module_element_text("aval_var-dataset_ADQS_singleextract-select_input .shiny-validation-message"),
"Analysis variable cannot be empty."
)
app_driver$stop()
})

testthat::test_that(
"e2e - tm_t_ancova: Selecting arm_var-variable changes the table and does not throw validation errors.",
{
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_ancova()
table_before <- app_driver$get_active_module_tws_output("table")
app_driver$set_active_module_input("arm_var-dataset_ADSL_singleextract-select", "ARM")
testthat::expect_false(identical(table_before, app_driver$get_active_module_tws_output("table")))
app_driver$expect_no_validation_error()
app_driver$stop()
}
)

testthat::test_that("e2e - tm_t_ancova: Deselection of arm_var-variable throws validation error.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_ancova()
app_driver$set_active_module_input("arm_var-dataset_ADSL_singleextract-select", NULL)
testthat::expect_identical(app_driver$get_active_module_tws_output("table"), data.frame())
app_driver$expect_validation_error()
testthat::expect_equal(
app_driver$active_module_element_text("arm_var-dataset_ADSL_singleextract-select_input .shiny-validation-message"),
"Treatment variable must be selected"
)
app_driver$stop()
})

testthat::test_that(
"e2e - tm_t_ancova: Selecting cov_var-variable changes the table and does not throw validation errors.",
{
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_ancova()
table_before <- app_driver$get_active_module_tws_output("table")
app_driver$set_active_module_input("cov_var-dataset_ADQS_singleextract-select", "BASE")
testthat::expect_false(identical(table_before, app_driver$get_active_module_tws_output("table")))
app_driver$expect_no_validation_error()
app_driver$stop()
}
)

testthat::test_that(
"e2e - tm_t_ancova: Deselection of cov_var-variable changes table and doesn't throw validation error.",
{
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_ancova()
table_before <- app_driver$get_active_module_tws_output("table")
app_driver$set_active_module_input("cov_var-dataset_ADQS_singleextract-select", NULL)
testthat::expect_false(identical(table_before, app_driver$get_active_module_tws_output("table")))
app_driver$expect_no_validation_error()
app_driver$stop()
}
)

0 comments on commit dec314f

Please sign in to comment.