From f793c64e0e42522ac50f0caa5370b41ef1166c7b Mon Sep 17 00:00:00 2001 From: Vedha Viyash <49812166+vedhav@users.noreply.github.com> Date: Fri, 19 Apr 2024 18:40:58 +0530 Subject: [PATCH] 712 - `{shinytest2}` for `tm_g_distribution` (#726) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Part of #712 --------- Signed-off-by: André Veríssimo <211358+averissimo@users.noreply.github.com> Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com> Co-authored-by: Marcin <133694481+m7pr@users.noreply.github.com> --- .../test-shinytest2-tm_g_distribution.R | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 tests/testthat/test-shinytest2-tm_g_distribution.R diff --git a/tests/testthat/test-shinytest2-tm_g_distribution.R b/tests/testthat/test-shinytest2-tm_g_distribution.R new file mode 100644 index 000000000..49f447065 --- /dev/null +++ b/tests/testthat/test-shinytest2-tm_g_distribution.R @@ -0,0 +1,129 @@ +app_driver_tm_g_distribution <- function() { + data <- teal.data::teal_data() + data <- within(data, { + ADSL <- rADSL + }) + teal.data::datanames(data) <- c("ADSL") + teal.data::join_keys(data) <- teal.data::default_cdisc_join_keys[teal.data::datanames(data)] + + vars1 <- teal.transform::choices_selected( + teal.transform::variable_choices(data[["ADSL"]], c("ARM", "COUNTRY", "SEX")), + selected = NULL + ) + + init_teal_app_driver( + data = data, + modules = tm_g_distribution( + dist_var = teal.transform::data_extract_spec( + dataname = "ADSL", + select = teal.transform::select_spec( + choices = teal.transform::variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")), + selected = "BMRKR1", + multiple = FALSE, + fixed = FALSE + ) + ), + strata_var = teal.transform::data_extract_spec( + dataname = "ADSL", + filter = teal.transform::filter_spec( + vars = vars1, + multiple = TRUE + ) + ), + group_var = teal.transform::data_extract_spec( + dataname = "ADSL", + filter = teal.transform::filter_spec( + vars = vars1, + multiple = TRUE + ) + ), + ggplot2_args = teal.widgets::ggplot2_args( + labs = list(subtitle = "Plot generated by Distribution Module") + ), + ggtheme = "classic", + freq = TRUE, + bins = 36, + ) + ) +} + +testthat::test_that("e2e - tm_g_distribution: module is initialised with the specified defaults", { + skip_if_too_deep(5) + + app_driver <- app_driver_tm_g_distribution() + + app_driver$expect_no_shiny_error() + + # Encodings in the Histogram tab + testthat::expect_equal(app_driver$get_active_module_input("dist_i-dataset_ADSL_singleextract-select"), "BMRKR1") + testthat::expect_null(app_driver$get_active_module_input("group_i-dataset_ADSL_singleextract-filter1-col")) + testthat::expect_null(app_driver$get_active_module_input("group_i-dataset_ADSL_singleextract-filter1-vals")) + testthat::expect_null(app_driver$get_active_module_input("strata_i-dataset_ADSL_singleextract-filter1-col")) + testthat::expect_equal(app_driver$get_active_module_input("bins"), 36) + testthat::expect_equal(app_driver$get_active_module_input("main_type"), "Frequency") + testthat::expect_equal(app_driver$get_active_module_input("ggtheme"), "classic") + testthat::expect_equal(app_driver$get_active_module_input("tabs"), "Histogram") + + # Encodings in the QQplot tab + app_driver$set_active_module_input("tabs", "QQplot") + testthat::expect_true(app_driver$get_active_module_input("qq_line")) + + app_driver$stop() +}) + +testthat::test_that("e2e - tm_g_distribution: histogram encoding inputs produce output without validation errors", { + skip_if_too_deep(5) + + app_driver <- app_driver_tm_g_distribution() + + app_driver$set_active_module_input("main_type", "Density") + app_driver$expect_validation_error() # test needs to be updated to remove validation error + app_driver$set_active_module_input("dist_tests", "Shapiro-Wilk") + + # Encodings in the Histogram tab + app_driver$set_active_module_input("group_i-dataset_ADSL_singleextract-filter1-col", "ARM") + app_driver$expect_no_validation_error() + + app_driver$set_active_module_input( + "group_i-dataset_ADSL_singleextract-filter1-vals", + c("A: Drug X", "C: Combination") + ) + app_driver$expect_no_validation_error() + + app_driver$set_active_module_input("scales_type", "Free") + app_driver$expect_no_validation_error() + + app_driver$set_active_module_input("strata_i-dataset_ADSL_singleextract-filter1-col", "SEX") + app_driver$expect_no_validation_error() + + app_driver$set_active_module_input("strata_i-dataset_ADSL_singleextract-filter1-vals", c("F")) + app_driver$expect_no_validation_error() + + app_driver$set_active_module_input("bins", 50) + app_driver$expect_no_validation_error() + + app_driver$set_active_module_input("add_dens", FALSE) + app_driver$expect_no_validation_error() + + app_driver$stop() +}) + +testthat::test_that("e2e - tm_g_distribution: qqplot encoding inputs produce output without validation errors", { + skip_if_too_deep(5) + + app_driver <- app_driver_tm_g_distribution() + + # Encodings in the QQplot tab + app_driver$set_active_module_input("main_type", "Density") + app_driver$expect_validation_error() # test needs to be updated to remove validation error + app_driver$set_active_module_input("dist_tests", "Shapiro-Wilk") + app_driver$expect_no_validation_error() + + app_driver$set_active_module_input("tabs", "QQplot") + app_driver$set_active_module_input("t_dist", "normal") + app_driver$click(NS(app_driver$active_module_ns(), "params_reset")) + + app_driver$expect_no_validation_error() + + app_driver$stop() +})