Skip to content

Commit

Permalink
Wave 5 - tm_t_exposure shinytests (#1161)
Browse files Browse the repository at this point in the history
Part of #1108

---------

Signed-off-by: Vedha Viyash <[email protected]>
Signed-off-by: kartikeya kirar <[email protected]>
Co-authored-by: unknown <[email protected]>
  • Loading branch information
vedhav and kartikeyakirar authored May 9, 2024
1 parent d481686 commit 0d5ed4a
Showing 1 changed file with 225 additions and 0 deletions.
225 changes: 225 additions & 0 deletions tests/testthat/test-shinytest2-tm_t_exposure.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
app_driver_tm_t_exposure <- function() {
data <- teal.data::teal_data()
data <- within(data, {
library(dplyr)
ADSL <- teal.data::rADSL
ADEX <- teal.data::rADEX

set.seed(1, kind = "Mersenne-Twister")
labels <- col_labels(ADEX, fill = FALSE)
ADEX <- ADEX %>%
distinct(USUBJID, .keep_all = TRUE) %>%
mutate(
PARAMCD = "TDURD",
PARAM = "Overall duration (days)",
AVAL = sample(x = seq(1, 200), size = n(), replace = TRUE),
AVALU = "Days"
) %>%
bind_rows(ADEX)
col_labels(ADEX) <- labels
})

datanames <- c("ADSL", "ADEX")
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_exposure(
label = "Duration of Exposure Table",
dataname = "ADEX",
parentname = "ADSL",
paramcd = teal.transform::choices_selected(
choices = teal.transform::value_choices(data[["ADEX"]], "PARAMCD", "PARAM"),
selected = "TDURD"
),
col_by_var = teal.transform::choices_selected(
choices = teal.transform::variable_choices(data[["ADEX"]], subset = c("SEX", "ARM")),
selected = "SEX"
),
row_by_var = teal.transform::choices_selected(
choices = teal.transform::variable_choices(data[["ADEX"]], subset = c("RACE", "REGION1", "STRATA1", "SEX")),
selected = "RACE"
),
parcat = teal.transform::choices_selected(
choices = teal.transform::value_choices(data[["ADEX"]], "PARCAT2"),
selected = "Drug A"
),
add_total = FALSE,
paramcd_label = "PARAM",
id_var = teal.transform::choices_selected(
teal.transform::variable_choices(data[["ADEX"]], subset = "USUBJID"),
selected = "USUBJID", fixed = TRUE
),
aval_var = teal.transform::choices_selected(
teal.transform::variable_choices(data[["ADEX"]], subset = "AVAL"),
selected = "AVAL", fixed = TRUE
),
avalu_var = teal.transform::choices_selected(
teal.transform::variable_choices(data[["ADEX"]], subset = "AVALU"),
selected = "AVALU", fixed = TRUE
),
total_label = default_total_label(),
add_total_row = TRUE,
total_row_label = "Total number of patients and patient time*",
na_level = default_na_str(),
pre_output = NULL,
post_output = NULL,
basic_table_args = teal.widgets::basic_table_args()
),
filter = teal::teal_slices(teal_slice("ADSL", "SAFFL", selected = "Y")),
)
}

testthat::test_that("e2e - tm_t_exposure: Module initializes in teal without errors and produces table output.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_exposure()
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_exposure: Starts with specified label, paramcd, parcat,
col_by_var, row_by_var, add_total_row, add_total",
{
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_exposure()
testthat::expect_equal(
app_driver$get_text("#teal-main_ui-root-active_tab > li.active > a"),
"Duration of Exposure Table"
)
testthat::expect_equal(
app_driver$get_active_module_input("paramcd-dataset_ADEX_singleextract-filter1-vals"),
"TDURD"
)
testthat::expect_equal(
app_driver$get_active_module_input("parcat-dataset_ADEX_singleextract-filter1-vals"),
"Drug A"
)
testthat::expect_equal(
app_driver$get_active_module_input("col_by_var-dataset_ADSL_singleextract-select"),
"SEX"
)
testthat::expect_equal(
app_driver$get_active_module_input("row_by_var-dataset_ADEX_singleextract-select"),
"RACE"
)
testthat::expect_true(app_driver$get_active_module_input("add_total_row"))
testthat::expect_false(app_driver$get_active_module_input("add_total"))
app_driver$stop()
}
)

testthat::test_that(
"e2e - tm_t_exposure: Selecting paramcd-level changes the table and does not throw validation errors.",
{
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_exposure()
table_before <- app_driver$get_active_module_tws_output("table")
app_driver$set_active_module_input("paramcd-dataset_ADEX_singleextract-filter1-vals", "DOSE")
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_exposure: Deselection of paramcd-level throws validation error.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_exposure()
app_driver$set_active_module_input("paramcd-dataset_ADEX_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_ADEX_singleextract-filter1-vals_input .shiny-validation-message"
),
"Please select a parameter value."
)
app_driver$stop()
})

testthat::test_that(
"e2e - tm_t_exposure: Selecting parcat-level changes the table and does not throw validation errors.",
{
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_exposure()
table_before <- app_driver$get_active_module_tws_output("table")
app_driver$set_active_module_input("parcat-dataset_ADEX_singleextract-filter1-vals", "Drug B")
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_exposure: Deselection of parcat-level throws validation error.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_exposure()
app_driver$set_active_module_input("parcat-dataset_ADEX_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(
"parcat-dataset_ADEX_singleextract-filter1-vals_input .shiny-validation-message"
),
"Please select a parameter category value."
)
app_driver$stop()
})

testthat::test_that(
"e2e - tm_t_exposure: Selecting col_by_var-variable changes the table and does not throw validation errors.",
{
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_exposure()
table_before <- app_driver$get_active_module_tws_output("table")
app_driver$set_active_module_input("col_by_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_exposure: Deselection of col_by_var-variable changes the table and does not throw validation errors.",
{
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_exposure()
table_before <- app_driver$get_active_module_tws_output("table")
app_driver$set_active_module_input("col_by_var-dataset_ADSL_singleextract-select", character(0), wait_ = FALSE)
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_exposure: Selecting row_by_var_var-variable changes the table and does not throw validation errors.",
{
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_exposure()
table_before <- app_driver$get_active_module_tws_output("table")
app_driver$set_active_module_input("row_by_var-dataset_ADEX_singleextract-select", "REGION1")
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_exposure: Deselection of row_by_var-variable throws validation error.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_t_exposure()
app_driver$set_active_module_input("row_by_var-dataset_ADEX_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(
"row_by_var-dataset_ADEX_singleextract-select_input .shiny-validation-message"
),
"Please select a row by variable."
)
app_driver$stop()
})

0 comments on commit 0d5ed4a

Please sign in to comment.