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

Wave 2 - tm_g_forest_tte shinytest2 #1138

Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6b647c7
feat: initial support for tm_g_forest_tte e2e testing
averissimo Apr 25, 2024
eae4cfc
fix: add testing depth and missing dependency
averissimo Apr 25, 2024
ad3d46d
cleanup: remove old tests
averissimo Apr 25, 2024
82dde88
fix: adds teal.transform prefix
averissimo Apr 25, 2024
c94097e
fix: corrects test title
averissimo Apr 25, 2024
315df39
Merge branch 'shinytest2@main' into 1108_shinytest2_tm_g_forest_tte@s…
averissimo Apr 25, 2024
64e674b
Merge branch 'shinytest2@main' into 1108_shinytest2_tm_g_forest_tte@s…
averissimo Apr 25, 2024
90279f6
fix: remove unused expression
averissimo Apr 25, 2024
24f1b25
fix: typo
averissimo Apr 25, 2024
cfb0f1f
Apply suggestions from @gogonzo
averissimo Apr 26, 2024
4ef870b
chore: use new function name from PR review
averissimo Apr 26, 2024
b18ca33
Merge branch 'shinytest2@main' into 1108_shinytest2_tm_g_forest_tte@s…
averissimo Apr 26, 2024
b3b9492
chore: use new function name from PR review
averissimo Apr 26, 2024
d3a8b53
fix_ order of ns_des_input changed with PR comment
averissimo Apr 26, 2024
d8f678d
chore: remove definition as it has been merged upstream
averissimo Apr 26, 2024
752fdad
Merge branch 'shinytest2@main' into 1108_shinytest2_tm_g_forest_tte@s…
averissimo Apr 26, 2024
f1ce685
Merge branch 'shinytest2@main' into 1108_shinytest2_tm_g_forest_tte@s…
gogonzo Apr 30, 2024
e975c4d
Merge branch '1108_shinytest2_tm_g_forest_tte@shinytest2@main' of git…
gogonzo Apr 30, 2024
b6d6005
fix tests
gogonzo Apr 30, 2024
debd8fb
Merge remote-tracking branch 'origin/shinytest2@main' into 1108_shiny…
gogonzo Apr 30, 2024
364b358
fix error
gogonzo May 2, 2024
94122dd
Merge branch 'shinytest2@main' into 1108_shinytest2_tm_g_forest_tte@s…
gogonzo May 2, 2024
82e1ed9
fix
gogonzo May 2, 2024
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
252 changes: 252 additions & 0 deletions tests/testthat/test-shinytest2-tm_g_forest_tte.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
app_driver_tm_g_forest_tte <- function() { # nolint: object_length.
data <- within(teal.data::teal_data(), {
ADSL <- teal.modules.clinical::tmc_ex_adsl
ADSL$RACE <- with_label(droplevels(ADSL$RACE), "Race")
ADTTE <- teal.modules.clinical::tmc_ex_adtte
})

datanames <- c("ADSL", "ADTTE")
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")
),
ARMCD = list(
ref = "ARM B",
comp = c("ARM A", "ARM C")
)
)

init_teal_app_driver(
data = data,
modules = tm_g_forest_tte(
label = "Forest Survival (e2e)",
dataname = "ADTTE",
arm_var = teal.transform::choices_selected(
teal.transform::variable_choices(data[["ADSL"]], c("ARM", "ARMCD")),
"ARMCD"
),
arm_ref_comp = arm_ref_comp,
paramcd = teal.transform::choices_selected(
teal.transform::value_choices(data[["ADTTE"]], "PARAMCD", "PARAM"),
"OS"
),
subgroup_var = teal.transform::choices_selected(
teal.transform::variable_choices(data[["ADSL"]], names(data[["ADSL"]])),
c("BMRKR2", "SEX")
),
strata_var = teal.transform::choices_selected(
teal.transform::variable_choices(data[["ADSL"]], c("STRATA1", "STRATA2")),
"STRATA2"
),
fixed_symbol_size = FALSE,
plot_height = c(500L, 300L, 2000L),
plot_width = c(1000L, 700L, 2000L),
rel_width_forest = c(25L, 0L, 100L),
font_size = c(12L, 1L, 30L),
pre_output = NULL,
post_output = NULL,
ggplot2_args = teal.widgets::ggplot2_args()
)
)
}

# Initialization --------------------------------------------------------------

testthat::test_that("e2e - tm_g_forest_tte: Module initializes in teal without errors and produces output.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_forest_tte()
app_driver$expect_no_shiny_error()
app_driver$expect_no_validation_error()
testthat::expect_true(
app_driver$is_visible(app_driver$active_module_element("myplot-plot_out_main"))
)

app_driver$stop()
})

testthat::test_that(
paste0(
"e2e - tm_g_forest_tte: Starts with specified ",
"label, paramcd, arm_var, buckets, paramcd, subgroup_var, strata_var and plot settings"
),
{
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_forest_tte()

testthat::expect_identical(
trimws(app_driver$get_text("#teal-main_ui-root-active_tab > li.active")),
"Forest Survival (e2e)"
)

testthat::expect_identical(
app_driver$get_active_module_input(ns_des_input("arm_var", "ADSL", "select")),
"ARMCD"
)

testthat::expect_identical(
app_driver$get_active_module_input(ns_des_input("paramcd", "ADTTE", "filter1-vals")),
"OS"
)

testthat::expect_identical(
app_driver$get_active_module_input(ns_des_input("aval_var", "ADTTE", "select")),
"AVAL"
)

testthat::expect_identical(
app_driver$get_active_module_input(ns_des_input("cnsr_var", "ADTTE", "select")),
"CNSR"
)

testthat::expect_equal(
app_driver$get_active_module_input("buckets"),
list(Ref = list("ARM B"), Comp = list("ARM A", "ARM C"))
)

testthat::expect_setequal(
app_driver$get_active_module_input(ns_des_input("subgroup_var", "ADSL", "select")),
c("SEX", "BMRKR2")
)

testthat::expect_equal(
app_driver$get_active_module_input(ns_des_input("strata_var", "ADSL", "select")),
"STRATA2"
)

# Plot settings -----------------------------------------------------------
# only tests the options that are customizable

testthat::expect_equal(app_driver$get_active_module_input("conf_level"), "0.95")
testthat::expect_true(app_driver$get_active_module_input("fixed_symbol_size"))
testthat::expect_equal(app_driver$get_active_module_input("rel_width_forest"), 25)
testthat::expect_equal(app_driver$get_active_module_input("font_size"), 12)

app_driver$stop()
}
)

testthat::test_that(
"e2e - tm_g_forest_tte: Selection of 'paramcd' changes the element and does not throw validation errors",
{
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_forest_tte()
plot_before <- app_driver$get_active_module_pws_output("myplot")
app_driver$set_active_module_input(ns_des_input("paramcd", "ADTTE", "filter1-vals"), "CRSD")
testthat::expect_false(identical(plot_before, app_driver$get_active_module_pws_output("myplot")))
app_driver$expect_no_validation_error()
app_driver$stop()
}
)

testthat::test_that("e2e - tm_g_forest_tte: Deselection of paramcd filter throws validation error.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_forest_tte()
input_id <- ns_des_input("paramcd", "ADTTE", "filter1-vals")
app_driver$set_active_module_input(input_id, character(0L))
app_driver$expect_validation_error()
testthat::expect_match(
app_driver$active_module_element_text(
sprintf(
"%s_input .shiny-validation-message",
input_id
)
),
"Please select Endpoint filter."
)
app_driver$stop()
})

testthat::test_that(
"e2e - tm_g_forest_tte: Selection of 'arm_var' changes the element and does not throw validation errors",
{
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_forest_tte()
plot_before <- app_driver$get_active_module_pws_output("myplot")
app_driver$set_active_module_input(ns_des_input("arm_var", "ADSL", "select"), "ARM")
testthat::expect_false(identical(plot_before, app_driver$get_active_module_pws_output("myplot")))
app_driver$expect_no_validation_error()
app_driver$stop()
}
)

testthat::test_that("e2e - tm_g_forest_tte: Deselection of paramcd var throws validation error.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_forest_tte()
input_id <- ns_des_input("arm_var", "ADSL", "select")
app_driver$set_active_module_input(input_id, character(0L))
app_driver$expect_validation_error()
testthat::expect_match(
app_driver$active_module_element_text(
sprintf(
"%s_input .shiny-validation-message",
input_id
)
),
"Treatment variable must be selected"
)
app_driver$stop()
})

testthat::test_that(
"e2e - tm_g_forest_tte: Selecting aval_var does not throw validation errors and changes a plot.",
{
skip_if_too_deep(5)
# not possible in this app due to fixed input
}
)

testthat::test_that(
"e2e - tm_g_forest_tte: Deselecting aval_var throws validation error.",
{
skip_if_too_deep(5)
# not possible in this app due to fixed input
}
)

testthat::test_that(
"e2e - tm_g_forest_tte: Selecting cnsr_var does not throw validation errors and changes a plot.",
{
skip_if_too_deep(5)
# not possible in this app due to fixed input
}
)

testthat::test_that(
"e2e - tm_g_forest_tte: Deselecting cnsr_var throws validation error.",
{
skip_if_too_deep(5)
# not possible in this app due to fixed input
}
)

testthat::test_that(
"e2e - tm_g_forest_tte: Selecting time_unit variable does not throw validation errors and changes a plot.",
{
skip_if_too_deep(5)
# not possible in this app due to fixed input
}
)

testthat::test_that(
"e2e - tm_g_forest_tte: Selecting conf_level does not throw validation errors and changes a plot.",
{
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_forest_tte()
input_id <- "conf_level"
plot_before <- app_driver$get_active_module_pws_output("myplot")
app_driver$set_active_module_input(input_id, "0.99")
testthat::expect_false(identical(plot_before, app_driver$get_active_module_pws_output("myplot")))
app_driver$expect_validation_error()
testthat::expect_match(
app_driver$active_module_element_text(
sprintf("%s_input .shiny-validation-message", input_id)
),
"Please choose a confidence level"
)
app_driver$stop()
}
)
Loading