-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wave 6 -
tm_t_pp_medical_history
shinytests (#1166)
Part of #1108 --------- Co-authored-by: unknown <[email protected]>
- Loading branch information
1 parent
c158cd6
commit da7584a
Showing
1 changed file
with
178 additions
and
0 deletions.
There are no files selected for viewing
178 changes: 178 additions & 0 deletions
178
tests/testthat/test-shinytest2-tm_t_pp_medical_history.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
app_driver_tm_t_pp_medical_history <- function() { # nolint: object_length | ||
data <- teal.data::teal_data() | ||
data <- within(data, { | ||
ADSL <- tmc_ex_adsl | ||
ADMH <- tmc_ex_admh | ||
}) | ||
datanames <- c("ADSL", "ADMH") | ||
teal.data::datanames(data) <- datanames | ||
teal.data::join_keys(data) <- teal.data::default_cdisc_join_keys[datanames] | ||
init_teal_app_driver( | ||
data = data, | ||
modules = tm_t_pp_medical_history( | ||
label = "Medical History", | ||
dataname = "ADMH", | ||
parentname = "ADSL", | ||
patient_col = "USUBJID", | ||
mhterm = teal.transform::choices_selected( | ||
choices = teal.transform::variable_choices(data[["ADMH"]], c("MHTERM", "STUDYID")), | ||
selected = "MHTERM" | ||
), | ||
mhbodsys = teal.transform::choices_selected( | ||
choices = teal.transform::variable_choices(data[["ADMH"]], c("MHBODSYS", "EOSSTT")), | ||
selected = "MHBODSYS" | ||
), | ||
mhdistat = teal.transform::choices_selected( | ||
choices = teal.transform::variable_choices(data[["ADMH"]], c("MHDISTAT", "STUDYID")), | ||
selected = "MHDISTAT" | ||
), | ||
pre_output = NULL, | ||
post_output = NULL | ||
) | ||
) | ||
} | ||
|
||
testthat::test_that( | ||
"e2e - tm_t_pp_medical_history: Module initializes in teal without errors and produces table output.", | ||
{ | ||
skip_if_too_deep(5) | ||
app_driver <- app_driver_tm_t_pp_medical_history() | ||
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_pp_medical_history: Starts with specified label, patient_id, mhterm, mhbodsys, mhdistat.", | ||
{ | ||
skip_if_too_deep(5) | ||
app_driver <- app_driver_tm_t_pp_medical_history() | ||
|
||
testthat::expect_equal( | ||
app_driver$get_text("#teal-main_ui-root-active_tab > li.active > a"), | ||
"Medical History" | ||
) | ||
testthat::expect_equal( | ||
app_driver$get_active_module_input("patient_id"), | ||
"AB12345-CHN-1-id-1" | ||
) | ||
testthat::expect_equal( | ||
app_driver$get_active_module_input("mhterm-dataset_ADMH_singleextract-select"), | ||
"MHTERM" | ||
) | ||
testthat::expect_equal( | ||
app_driver$get_active_module_input("mhbodsys-dataset_ADMH_singleextract-select"), | ||
"MHBODSYS" | ||
) | ||
testthat::expect_equal( | ||
app_driver$get_active_module_input("mhdistat-dataset_ADMH_singleextract-select"), | ||
"MHDISTAT" | ||
) | ||
app_driver$stop() | ||
} | ||
) | ||
|
||
testthat::test_that( | ||
"e2e - tm_t_pp_medical_history: Selecting patient_id changes the table and does not throw validation errors.", | ||
{ | ||
skip_if_too_deep(5) | ||
app_driver <- app_driver_tm_t_pp_medical_history() | ||
table_before <- app_driver$get_active_module_tws_output("table") | ||
app_driver$set_active_module_input("patient_id", "AB12345-USA-1-id-45") | ||
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_pp_medical_history: Deselection of patient_id throws validation error.", { | ||
skip_if_too_deep(5) | ||
app_driver <- app_driver_tm_t_pp_medical_history() | ||
app_driver$set_active_module_input("patient_id", 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("patient_id_input .shiny-validation-message"), | ||
"Please select a patient" | ||
) | ||
app_driver$stop() | ||
}) | ||
|
||
testthat::test_that( | ||
"e2e - tm_t_pp_medical_history: Selecting mhterm-variable changes the table and does not throw validation errors.", | ||
{ | ||
skip_if_too_deep(5) | ||
app_driver <- app_driver_tm_t_pp_medical_history() | ||
table_before <- app_driver$get_active_module_tws_output("table") | ||
app_driver$set_active_module_input("mhterm-dataset_ADMH_singleextract-select", "STUDYID") | ||
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_pp_medical_history: Deselection of mhterm-variable throws validation error.", { | ||
app_driver <- app_driver_tm_t_pp_medical_history() | ||
app_driver$set_active_module_input("mhterm-dataset_ADMH_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("mhterm-dataset_ADMH_singleextract-select_input .shiny-validation-message"), | ||
"Please select MHTERM variable." | ||
) | ||
app_driver$stop() | ||
}) | ||
|
||
testthat::test_that( | ||
"e2e - tm_t_pp_medical_history: Selecting mhbodsys-variable changes the table and does not throw validation errors.", | ||
{ | ||
skip_if_too_deep(5) | ||
app_driver <- app_driver_tm_t_pp_medical_history() | ||
table_before <- app_driver$get_active_module_tws_output("table") | ||
app_driver$set_active_module_input("mhbodsys-dataset_ADMH_singleextract-select", "EOSSTT") | ||
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_pp_medical_history: Deselection of mhbodsys-variable throws validation error.", { | ||
app_driver <- app_driver_tm_t_pp_medical_history() | ||
app_driver$set_active_module_input("mhbodsys-dataset_ADMH_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("mhbodsys-dataset_ADMH_singleextract-select_input .shiny-validation-message"), | ||
"Please select MHBODSYS variable." | ||
) | ||
app_driver$stop() | ||
}) | ||
|
||
testthat::test_that( | ||
"e2e - tm_t_pp_medical_history: Selecting mhbodsys-variable changes the table and does not throw validation errors.", | ||
{ | ||
skip_if_too_deep(5) | ||
app_driver <- app_driver_tm_t_pp_medical_history() | ||
table_before <- app_driver$get_active_module_tws_output("table") | ||
app_driver$set_active_module_input("mhdistat-dataset_ADMH_singleextract-select", "STUDYID") | ||
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_pp_medical_history: Deselection of mhdistat-variable throws validation error.", { | ||
app_driver <- app_driver_tm_t_pp_medical_history() | ||
app_driver$set_active_module_input("mhdistat-dataset_ADMH_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("mhdistat-dataset_ADMH_singleextract-select_input .shiny-validation-message"), | ||
"Please select MHDISTAT variable." | ||
) | ||
app_driver$stop() | ||
}) |