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 1 - tm_g_ci shinytests #1125

Merged
merged 15 commits into from
Apr 25, 2024
Merged
10 changes: 10 additions & 0 deletions tests/testthat/helper-TealAppDriver.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ init_teal_app_driver <- function(...) {
.package = "teal"
)
}



# returns base 64 encoded image
active_module_pws_output <- function(app_driver) {
app_driver$get_attr(
app_driver$active_module_element("myplot-plot_main > img"),
"src"
)
}
m7pr marked this conversation as resolved.
Show resolved Hide resolved
231 changes: 231 additions & 0 deletions tests/testthat/test-shinytest2-tm_g_ci.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
app_driver_tm_g_ci <- function() {
data <- teal.data::teal_data()
data <- within(data, {
ADSL <- rADSL
ADLB <- rADLB
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
})
teal.data::datanames(data) <- c("ADSL", "ADLB")
teal.data::join_keys(data) <- teal.data::default_cdisc_join_keys[c("ADSL", "ADLB")]


gogonzo marked this conversation as resolved.
Show resolved Hide resolved
init_teal_app_driver(
data = data,
modules = tm_g_ci(
label = "Confidence Interval Plot",
x_var = teal.transform::data_extract_spec(
dataname = "ADSL",
select = teal.transform::select_spec(
choices = c("ARMCD", "BMRKR2"),
selected = c("ARMCD"),
multiple = FALSE,
fixed = FALSE
)
),
y_var = teal.transform::data_extract_spec(
dataname = "ADLB",
filter = list(
teal.transform::filter_spec(
vars = "PARAMCD",
choices = levels(ADLB$PARAMCD),
selected = levels(ADLB$PARAMCD)[1],
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
multiple = FALSE,
label = "Select lab:"
),
teal.transform::filter_spec(
vars = "AVISIT",
choices = levels(ADLB$AVISIT),
selected = levels(ADLB$AVISIT)[1],
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
multiple = FALSE,
label = "Select visit:"
)
),
select = teal.transform::select_spec(
label = "Analyzed Value",
choices = c("AVAL", "CHG"),
selected = "AVAL",
multiple = FALSE,
fixed = FALSE
)
),
color = teal.transform::data_extract_spec(
dataname = "ADSL",
select = teal.transform::select_spec(
label = "Color by variable",
choices = c("SEX", "STRATA1", "STRATA2"),
selected = c("STRATA1"),
multiple = FALSE,
fixed = FALSE
)
)
)
)
}

testthat::test_that("e2e - tm_g_ci: example ci module initializes in teal without errors and produces plot output", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ci()
app_driver$expect_no_shiny_error()
app_driver$expect_no_validation_error()
testthat::expect_match(active_module_pws_output(app_driver), "data:image/png;base64,")
})

testthat::test_that("e2e - tm_g_ci: Module initializes with specified label, x_var, y_var, ADLB filters and color", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ci()

testthat::expect_equal(
app_driver$get_text("#teal-main_ui-root-active_tab > li.active > a"),
"Confidence Interval Plot"
)

testthat::expect_equal(
app_driver$get_active_module_input("x_var-dataset_ADSL_singleextract-select"),
"ARMCD"
)

testthat::expect_equal(
app_driver$get_active_module_input("y_var-dataset_ADLB_singleextract-select"),
"AVAL"
)

testthat::expect_equal(
app_driver$get_active_module_input("y_var-dataset_ADLB_singleextract-filter1-col"),
"PARAMCD"
)
testthat::expect_equal(
app_driver$get_active_module_input("y_var-dataset_ADLB_singleextract-filter1-vals"),
"ALT"
)

testthat::expect_equal(
app_driver$get_active_module_input("y_var-dataset_ADLB_singleextract-filter2-col"),
"AVISIT"
)
testthat::expect_equal(
app_driver$get_active_module_input("y_var-dataset_ADLB_singleextract-filter2-vals"),
"SCREENING"
)

testthat::expect_equal(
app_driver$get_active_module_input("color-dataset_ADSL_singleextract-select"),
"STRATA1"
)
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
})

testthat::test_that("e2e - tm_g_ci: Selecting x_var column changes plot and doesn't throw validation errors", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ci()
plot_before <- active_module_pws_output(app_driver)
app_driver$set_active_module_input("x_var-dataset_ADSL_singleextract-select", "BMRKR2")
testthat::expect_false(
identical(
plot_before,
active_module_pws_output(app_driver)
)
)
app_driver$expect_no_validation_error()
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
})

testthat::test_that("e2e - tm_g_ci: Deselecting x_var column throws validation error", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ci()
app_driver$set_active_module_input("x_var-dataset_ADSL_singleextract-select", character(0))
testthat::expect_identical(active_module_pws_output(app_driver), character(0))
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
app_driver$expect_validation_error()
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
})

testthat::test_that("e2e - tm_g_ci: Selecting y_var column changes plot and doesn't throw validation errors", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ci()
plot_before <- active_module_pws_output(app_driver)
app_driver$set_active_module_input("y_var-dataset_ADLB_singleextract-select", "CHG")
testthat::expect_false(
identical(
plot_before,
active_module_pws_output(app_driver)
)
)
app_driver$expect_no_validation_error()
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
})

testthat::test_that("e2e - tm_g_ci: Deselecting y_var column throws validation error", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ci()
app_driver$set_active_module_input("y_var-dataset_ADLB_singleextract-select", character(0))
testthat::expect_identical(active_module_pws_output(app_driver), character(0))
app_driver$expect_validation_error()
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
})

testthat::test_that("e2e - tm_g_ci: Selecting PARAMCD filter value changes plot and doesn't throw validation errors", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ci()
plot_before <- active_module_pws_output(app_driver)
app_driver$set_active_module_input("y_var-dataset_ADLB_singleextract-filter1-vals", "CRP")
testthat::expect_false(
identical(
plot_before,
active_module_pws_output(app_driver)
)
)
app_driver$expect_no_validation_error()
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
})

testthat::test_that("e2e - tm_g_ci: Deselecting PARAMCD filter value throws validation error", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ci()
app_driver$set_active_module_input("y_var-dataset_ADLB_singleextract-filter1-vals", character(0))
testthat::expect_identical(active_module_pws_output(app_driver), character(0))
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
app_driver$expect_validation_error()
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
})

testthat::test_that("e2e - tm_g_ci: Selecting AVISIT filter value doesn't throw validation errors", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ci()
plot_before <- active_module_pws_output(app_driver)
app_driver$set_active_module_input("y_var-dataset_ADLB_singleextract-filter2-vals", "VISIT1")
testthat::expect_false(identical(plot_before, active_module_pws_output(app_driver)))
app_driver$expect_no_validation_error()
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
})

testthat::test_that("e2e - tm_g_ci: Deselecting AVISIT filter value throws validation error", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ci()
app_driver$set_active_module_input("y_var-dataset_ADLB_singleextract-filter2-vals", character(0))
testthat::expect_identical(active_module_pws_output(app_driver), character(0))
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
app_driver$expect_validation_error()
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
})

testthat::test_that("e2e - tm_g_ci: Selecting color column changes plot output and doesn't throw validation errors", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ci()
plot_before <- active_module_pws_output(app_driver)
app_driver$set_active_module_input("color-dataset_ADSL_singleextract-select", "SEX")
app_driver$expect_no_validation_error()
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
})

testthat::test_that("e2e - tm_g_ci: Deselecting color column throws validation error", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ci()
app_driver$set_active_module_input("color-dataset_ADSL_singleextract-select", character(0))
testthat::expect_identical(active_module_pws_output(app_driver), character(0))
app_driver$expect_validation_error()
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
})

testthat::test_that("e2e - tm_g_ci: Selecting confidence interval value changes plot and doesn't throw any errors", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ci()
plot_before <- active_module_pws_output(app_driver)
app_driver$set_active_module_input("conf_level", 0.90)
testthat::expect_false(identical(plot_before, active_module_pws_output(app_driver)))
app_driver$expect_no_validation_error()
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
})


testthat::test_that("e2e - tm_g_ci: Selecting statistic to use changes a plot and doesn't throw any errors", {
skip_if_too_deep(5)
app_driver <- app_driver_tm_g_ci()
plot_before <- active_module_pws_output(app_driver)
app_driver$set_active_module_input("stat", "median")
testthat::expect_false(identical(plot_before, active_module_pws_output(app_driver)))
app_driver$expect_no_validation_error()
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
})
Loading