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_ipp shinytests #1141

Merged
merged 5 commits into from
Apr 29, 2024
Merged
Changes from 2 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
297 changes: 297 additions & 0 deletions tests/testthat/test-shinytest2-tm_g_ipp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,297 @@
app_driver_tm_g_ipp <- function() {
data <- teal.data::teal_data() %>%
within({
library(dplyr)
library(tern)
ADSL <- teal.data::rADSL %>%
slice(1:20) %>%
df_explicit_na()
ADLB <- teal.data::rADLB %>%
filter(USUBJID %in% ADSL$USUBJID) %>%
df_explicit_na() %>%
filter(AVISIT != "SCREENING")
})

datanames <- c("ADSL", "ADLB")
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_g_ipp(
label = "Individual Patient Plot",
dataname = "ADLB",
arm_var = teal.transform::choices_selected(
teal.transform::value_choices(data[["ADLB"]], "ARMCD"),
"ARM A"
),
paramcd = teal.transform::choices_selected(
teal.transform::value_choices(data[["ADLB"]], "PARAMCD"),
"ALT"
),
aval_var = teal.transform::choices_selected(
teal.transform::variable_choices(data[["ADLB"]], c("AVAL", "CHG")),
"AVAL"
),
avalu_var = teal.transform::choices_selected(
teal.transform::variable_choices(data[["ADLB"]], c("AVALU")),
"AVALU",
fixed = TRUE
),
id_var = teal.transform::choices_selected(
teal.transform::variable_choices(data[["ADLB"]], c("USUBJID")),
"USUBJID",
fixed = TRUE
),
visit_var = teal.transform::choices_selected(
teal.transform::variable_choices(data[["ADLB"]], c("AVISIT", "ATOXGR")),
"AVISIT"
),
baseline_var = teal.transform::choices_selected(
teal.transform::variable_choices(data[["ADLB"]], c("BASE")),
"BASE",
fixed = TRUE
),
add_baseline_hline = FALSE,
separate_by_obs = FALSE
)
)
}

testthat::test_that("e2e - tm_g_ipp: Module initializes in teal without errors and produces plot output.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ipp()
app_driver$expect_no_shiny_error()
app_driver$expect_no_validation_error()
testthat::expect_match(
app_driver$get_active_module_pws_output("myplot"),
"data:image/png;base64,"
)
app_driver$stop()
})

testthat::test_that(
"e2e - tm_g_ipp: Starts with specified
label, parentname, arm_var, paramcd, id_var, visit_var, aval_var, avalu_var, baseline_var
add_baseline_hline, separate_by_obs, suppress_legend, add_avalu.",
{
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ipp()
testthat::expect_equal(
app_driver$get_text("#teal-main_ui-root-active_tab > li.active > a"),
"Individual Patient Plot"
)
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("arm_var-dataset_ADSL_singleextract-filter1-vals"),
"ARM A"
)
testthat::expect_equal(
app_driver$get_active_module_input("paramcd-dataset_ADLB_singleextract-filter1-col"),
"PARAMCD"
)
testthat::expect_equal(
app_driver$get_active_module_input("paramcd-dataset_ADLB_singleextract-filter1-vals"),
"ALT"
)
testthat::expect_equal(
app_driver$get_active_module_input("visit_var-dataset_ADLB_singleextract-select"),
"AVISIT"
)
testthat::expect_equal(
app_driver$get_active_module_input("aval_var-dataset_ADLB_singleextract-select"),
"AVAL"
)
testthat::expect_equal(
app_driver$get_active_module_input("id_var-dataset_ADLB_singleextract-select"),
"USUBJID"
)
testthat::expect_equal(
app_driver$get_active_module_input("avalu_var-dataset_ADLB_singleextract-select"),
"AVALU"
)
testthat::expect_equal(
app_driver$get_active_module_input("baseline_var-dataset_ADLB_singleextract-select"),
"BASE"
)
testthat::expect_false(app_driver$get_active_module_input("add_baseline_hline"))
testthat::expect_false(app_driver$get_active_module_input("separate_by_obs"))
testthat::expect_false(app_driver$get_active_module_input("suppress_legend"))
testthat::expect_true(app_driver$get_active_module_input("add_avalu"))
app_driver$stop()
}
)

testthat::test_that("e2e - tm_g_ipp: Selecting arm_var changes plot and doesn't throw validation errors.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ipp()
plot_before <- app_driver$get_active_module_pws_output("myplot")
app_driver$set_active_module_input("arm_var-dataset_ADSL_singleextract-filter1-vals", "ARM B")
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_ipp: Deselecting arm_var column throws validation error.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ipp()
app_driver$set_active_module_input("arm_var-dataset_ADSL_singleextract-filter1-vals", NULL)
testthat::expect_identical(app_driver$get_active_module_pws_output("myplot"), character(0))
testthat::expect_identical(
app_driver$active_module_element_text("arm_var-dataset_ADSL_singleextract-filter1-vals_input > div > span"),
"Please select Arm filter."
)
app_driver$expect_validation_error()
app_driver$stop()
})

testthat::test_that("e2e - tm_g_ipp: Selecting paramcd changes plot and doesn't throw validation errors.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ipp()
plot_before <- app_driver$get_active_module_pws_output("myplot")
app_driver$set_active_module_input("paramcd-dataset_ADLB_singleextract-filter1-vals", "CRP")
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_ipp: Deselecting paramcd throws validation error.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ipp()
app_driver$set_active_module_input("paramcd-dataset_ADLB_singleextract-filter1-vals", NULL)
testthat::expect_identical(app_driver$get_active_module_pws_output("myplot"), character(0))
testthat::expect_identical(
app_driver$active_module_element_text("paramcd-dataset_ADLB_singleextract-filter1-vals_input > div > span"),
"Please select Parameter filter."
)
app_driver$expect_validation_error()
app_driver$stop()
})

testthat::test_that("e2e - tm_g_ipp: Selecting paramcd changes plot and doesn't throw validation errors.", {
vedhav marked this conversation as resolved.
Show resolved Hide resolved
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ipp()
plot_before <- app_driver$get_active_module_pws_output("myplot")
app_driver$set_active_module_input("visit_var-dataset_ADLB_singleextract-select", "ATOXGR")
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_ipp: Deselecting visit_var throws validation error.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ipp()
app_driver$set_active_module_input("visit_var-dataset_ADLB_singleextract-select", NULL)
testthat::expect_identical(app_driver$get_active_module_pws_output("myplot"), character(0))
testthat::expect_identical(
app_driver$active_module_element_text("visit_var-dataset_ADLB_singleextract-select_input > div > span"),
"A Timepoint Variable must be selected"
)
app_driver$expect_validation_error()
app_driver$stop()
})

testthat::test_that("e2e - tm_g_ipp: Selecting paramcd changes plot and doesn't throw validation errors.", {
vedhav marked this conversation as resolved.
Show resolved Hide resolved
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ipp()
plot_before <- app_driver$get_active_module_pws_output("myplot")
app_driver$set_active_module_input("aval_var-dataset_ADLB_singleextract-select", "CHG")
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_ipp: Deselecting aval_var throws validation error.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ipp()
app_driver$set_active_module_input("aval_var-dataset_ADLB_singleextract-select", NULL)
testthat::expect_identical(app_driver$get_active_module_pws_output("myplot"), character(0))
testthat::expect_identical(
app_driver$active_module_element_text("aval_var-dataset_ADLB_singleextract-select_input > div > span"),
"A Parameter values over Time must be selected"
)
app_driver$expect_validation_error()
app_driver$stop()
})

testthat::test_that("e2e - tm_g_ipp: Changing add_baseline_hline changes plot and doesn't throw validation errors.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ipp()
plot_before <- app_driver$get_active_module_pws_output("myplot")
app_driver$set_active_module_input("add_baseline_hline", TRUE)
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_ipp: Changing separate_by_obs changes plot and doesn't throw validation errors.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ipp()
plot_before <- app_driver$get_active_module_pws_output("myplot")
app_driver$set_active_module_input("separate_by_obs", TRUE)
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_ipp: Changing suppress_legend changes plot and doesn't throw validation errors.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ipp()
plot_before <- app_driver$get_active_module_pws_output("myplot")
app_driver$set_active_module_input("suppress_legend", TRUE)
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_ipp: Changing add_avalu changes plot and doesn't throw validation errors.", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ipp()
plot_before <- app_driver$get_active_module_pws_output("myplot")
app_driver$set_active_module_input("add_avalu", FALSE)
testthat::expect_false(
identical(
plot_before,
app_driver$get_active_module_pws_output("myplot")
)
)
app_driver$expect_no_validation_error()
app_driver$stop()
})
Loading