diff --git a/DESCRIPTION b/DESCRIPTION index 484ed9819..d8e0d4125 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: teal.modules.general Title: General Modules for 'teal' Applications -Version: 0.3.0.9010 -Date: 2024-04-18 +Version: 0.3.0.9012 +Date: 2024-04-19 Authors@R: c( person("Dawid", "Kaledkowski", , "dawid.kaledkowski@roche.com", role = c("aut", "cre")), person("Pawel", "Rucki", , "pawel.rucki@roche.com", role = "aut"), diff --git a/NEWS.md b/NEWS.md index 5e074467f..220427adc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# teal.modules.general 0.3.0.9010 +# teal.modules.general 0.3.0.9012 # teal.modules.general 0.3.0 diff --git a/tests/testthat/test-shinytest2-tm_g_scatterplotmatrix.R b/tests/testthat/test-shinytest2-tm_g_scatterplotmatrix.R new file mode 100644 index 000000000..1f1b6e7e9 --- /dev/null +++ b/tests/testthat/test-shinytest2-tm_g_scatterplotmatrix.R @@ -0,0 +1,113 @@ +app_driver_tm_g_scatterplotmatrix <- function() { # nolint: object_length_linter. + data <- simple_cdisc_data() + init_teal_app_driver( + data = data, + modules = tm_g_scatterplotmatrix( + label = "Scatterplot matrix", + variables = list( + teal.transform::data_extract_spec( + dataname = "ADSL", + select = teal.transform::select_spec( + label = "Select variables:", + choices = teal.transform::variable_choices(data[["ADSL"]]), + selected = c("AGE", "RACE", "SEX"), + multiple = TRUE, + ordered = TRUE, + fixed = FALSE + ) + ), + teal.transform::data_extract_spec( + dataname = "ADRS", + filter = teal.transform::filter_spec( + label = "Select endpoints:", + vars = c("PARAMCD", "AVISIT"), + choices = teal.transform::value_choices(data[["ADRS"]], c("PARAMCD", "AVISIT"), c("PARAM", "AVISIT")), + selected = "INVET - END OF INDUCTION", + multiple = TRUE + ), + select = teal.transform::select_spec( + label = "Select variables:", + choices = teal.transform::variable_choices(data[["ADRS"]]), + selected = c("AGE", "AVAL", "ADY"), + multiple = TRUE, + ordered = TRUE, + fixed = FALSE + ) + ) + ), + plot_height = c(600, 200, 2000), + plot_width = NULL, + pre_output = NULL, + post_output = NULL + ), + timeout = 3000 + ) +} + +test_that("e2e - tm_g_scatterplotmatrix: Initializes without errors", { + skip_if_too_deep(5) + app_driver <- app_driver_tm_g_scatterplotmatrix() + + app_driver$expect_no_shiny_error() + + testthat::expect_equal( + app_driver$get_text("#teal-main_ui-root-active_tab > li.active > a"), + "Scatterplot matrix" + ) + + encoding_dataset <- app_driver$get_text("#teal-main_ui-root-scatterplot_matrix .help-block") + testthat::expect_match(encoding_dataset, "Datasets.*ADSL.*ADRS", all = FALSE) + + app_driver$stop() +}) + +test_that("e2e - tm_g_scatterplotmatrix: Verify module displays data table", { + skip_if_too_deep(5) + app_driver <- app_driver_tm_g_scatterplotmatrix() + + # table + testthat::expect_true(app_driver$is_visible(selector = app_driver$active_module_element("myplot-plot_out_main"))) + + app_driver$stop() +}) + +test_that("e2e - tm_g_scatterplotmatrix: Verify default values and settings (data_extracts) for data selection", { + skip_if_too_deep(5) + app_driver <- app_driver_tm_g_scatterplotmatrix() + + # default variable selection + dataset <- app_driver$get_active_module_input("variables-dataset") + variables <- app_driver$get_active_module_input(sprintf( + "variables-dataset_%s_singleextract-select", + dataset + )) + testthat::expect_equal( + dataset, + "ADSL" + ) + testthat::expect_equal( + variables, + c("AGE", "SEX", "RACE") + ) + + # new variable selection + app_driver$set_active_module_input("variables-dataset", "ADRS") + app_driver$set_active_module_input("dataset_ADRS_singleextract-select", c("SEX", "RACE", "ETHNIC")) + app_driver$expect_no_validation_error() + + app_driver$stop() +}) + +test_that("e2e - tm_g_scatterplotmatrix: Change plot settings", { + skip_if_too_deep(5) + app_driver <- app_driver_tm_g_scatterplotmatrix() + + app_driver$set_active_module_input("alpha", 0.7) + app_driver$set_active_module_input("cex", 2) + + app_driver$expect_no_validation_error() + + app_driver$click(selector = app_driver$active_module_element("cor")) + app_driver$expect_no_validation_error() + app_driver$stop() +}) diff --git a/tests/testthat/test-shinytest2-tm_outliers.R b/tests/testthat/test-shinytest2-tm_outliers.R new file mode 100644 index 000000000..49065a963 --- /dev/null +++ b/tests/testthat/test-shinytest2-tm_outliers.R @@ -0,0 +1,313 @@ +app_driver_tm_outlier <- function() { + data <- teal.data::teal_data() + data <- within(data, { + CO2 <- CO2 # nolint: object_name + CO2[["primary_key"]] <- seq_len(nrow(CO2)) # nolint: object_name + }) + teal.data::datanames(data) <- "CO2" + teal.data::join_keys(data) <- teal.data::join_keys(join_key("CO2", "CO2", "primary_key")) + + vars <- teal.transform::choices_selected( + teal.transform::variable_choices( + data[["CO2"]], + c("Plant", "Type", "Treatment") + ) + ) + + init_teal_app_driver( + data = data, + modules = tm_outliers( + outlier_var = list( + teal.transform::data_extract_spec( + dataname = "CO2", + select = teal.transform::select_spec( + label = "Select variable:", + choices = teal.transform::variable_choices(data[["CO2"]], c("conc", "uptake")), + selected = "uptake", + multiple = FALSE, + fixed = FALSE + ) + ) + ), + categorical_var = list( + teal.transform::data_extract_spec( + dataname = "CO2", + filter = teal.transform::filter_spec( + vars = vars, + choices = teal.transform::value_choices(data[["CO2"]], vars$selected), + selected = teal.transform::value_choices(data[["CO2"]], vars$selected), + multiple = TRUE + ) + ) + ), + ggplot2_args = list( + teal.widgets::ggplot2_args( + labs = list(subtitle = "Plot generated by Outliers Module") + ) + ) + ) + ) +} + +testthat::test_that("e2e - tm_outliers: data parameter and module label is passed properly", { + skip_if_too_deep(5) + + app_driver <- app_driver_tm_outlier() + app_driver$expect_no_shiny_error() + + testthat::expect_equal( + app_driver$get_text("#teal-main_ui-root-active_tab > li.active > a"), + "Outliers Module" + ) + + encoding_dataset <- app_driver$get_text("#teal-main_ui-root-outliers_module .help-block") + testthat::expect_match(encoding_dataset, "Dataset:[\n ]*CO2", all = FALSE) + testthat::expect_match(encoding_dataset, "Outlier data points", all = FALSE) + + app_driver$stop() +}) + +testthat::test_that("e2e - tm_outliers: + data extract spec elements are initialized with the default values + specified by outlier_var and categorical_var argument", { + skip_if_too_deep(5) + + app_driver <- app_driver_tm_outlier() + app_driver$expect_no_shiny_error() + + testthat::expect_identical( + app_driver$get_active_module_input("outlier_var-dataset_CO2_singleextract-select"), + "uptake" + ) + app_driver$set_active_module_input("outlier_var-dataset_CO2_singleextract-select", "conc") + app_driver$expect_no_validation_error() + + testthat::expect_identical( + app_driver$get_active_module_input("categorical_var-dataset_CO2_singleextract-filter1-col"), + "Plant" + ) + + testthat::expect_identical( + app_driver$get_active_module_input("categorical_var-dataset_CO2_singleextract-filter1-vals"), + c( + "Qn1", "Qn2", "Qn3", "Qc1", "Qc2", "Qc3", "Mn1", "Mn2", "Mn3", + "Mc1", "Mc2", "Mc3" + ) + # THIS WILL HAVE DIFFERENT ORDER ONCE THIS IS FIXED + # https://github.com/insightsengineering/teal.modules.general/issues/735 + ) + app_driver$set_active_module_input("categorical_var-dataset_CO2_singleextract-filter1-col", c("Qn1", "Qn2", "Qn3")) + app_driver$expect_no_shiny_error() + + app_driver$set_active_module_input("categorical_var-dataset_CO2_singleextract-filter1-col", "Type") + app_driver$expect_no_shiny_error() + + app_driver$stop() +}) + +testthat::test_that("e2e - tm_outliers: default plot_type is set properly and has proper possible choices", { + skip_if_too_deep(5) + + app_driver <- app_driver_tm_outlier() + app_driver$expect_no_shiny_error() + + testthat::expect_identical(app_driver$get_active_module_input("boxplot_alts"), "Box plot") + + plot_choices <- app_driver$active_module_element_text("boxplot_alts") + testthat::expect_match(plot_choices, "Violin plot", fixed = TRUE) + + app_driver$set_active_module_input("boxplot_alts", "Violin plot") + app_driver$expect_no_shiny_error() + + app_driver$stop() +}) + +testthat::test_that("e2e - tm_outliers: module is divided into 3 tabs", { + skip_if_too_deep(5) + + app_driver <- app_driver_tm_outlier() + app_driver$expect_no_shiny_error() + + testthat::expect_identical(app_driver$get_active_module_input("tabs"), "Boxplot") + testthat::expect_match( + app_driver$active_module_element_text("tabs"), + "Boxplot.*Density Plot.*Cumulative Distribution Plot", + fixed = FALSE + ) + app_driver$stop() +}) + +testthat::test_that("e2e - tm_outliers: plot_type is hidden when Boxplot tab is not selected", { + skip_if_too_deep(5) + + app_driver <- app_driver_tm_outlier() + app_driver$expect_no_shiny_error() + + testthat::expect_true(app_driver$is_visible(app_driver$active_module_element("boxplot_alts"))) + + app_driver$set_active_module_input("tabs", "Density Plot") + testthat::expect_false(app_driver$is_visible(app_driver$active_module_element("boxplot_alts"))) + + app_driver$set_active_module_input("tabs", "Cumulative Distribution Plot") + testthat::expect_false(app_driver$is_visible(app_driver$active_module_element("boxplot_alts"))) + + app_driver$stop() +}) + +testthat::test_that("e2e - tm_outliers: default radio buttons are set properly", { + skip_if_too_deep(5) + + app_driver <- app_driver_tm_outlier() + app_driver$expect_no_shiny_error() + + testthat::expect_false(app_driver$get_active_module_input("split_outliers")) + testthat::expect_false(app_driver$get_active_module_input("order_by_outlier")) + + app_driver$set_active_module_input("split_outliers", TRUE) + app_driver$set_active_module_input("order_by_outlier", TRUE) + app_driver$expect_no_shiny_error() + + app_driver$stop() +}) + +testthat::test_that("e2e - tm_outliers: method parameters are set properly", { + skip_if_too_deep(5) + + app_driver <- app_driver_tm_outlier() + app_driver$expect_no_shiny_error() + + testthat::expect_identical(app_driver$get_active_module_input("method"), "IQR") + method_choices <- app_driver$active_module_element_text("method") + testthat::expect_match(method_choices, "Z-score", fixed = TRUE) + testthat::expect_match(method_choices, "Percentile", fixed = TRUE) + + app_driver$stop() +}) + + +testthat::test_that("e2e - tm_outliers: outlier definition text and range are displayed properly depending on method", { + skip_if_too_deep(5) + + app_driver <- app_driver_tm_outlier() + app_driver$expect_no_shiny_error() + + # Initially only the first slider should be visible. + testthat::expect_true(app_driver$is_visible(app_driver$active_module_element("iqr_slider"))) + testthat::expect_false(app_driver$is_visible(app_driver$active_module_element("zscore_slider"))) + testthat::expect_false(app_driver$is_visible(app_driver$active_module_element("percentile_slider"))) + + # IQR METHOD + testthat::expect_identical(app_driver$get_active_module_input("method"), "IQR") + testthat::expect_match( + app_driver$active_module_element_text("ui_outlier_help"), + "x