tests/testthat/test-shinytest2-tm_g_distribution_picks.R

app_driver_tm_g_distribution <- function() {
  data <- teal.data::teal_data()
  data <- within(data, ADSL <- teal.data::rADSL)
  teal.data::join_keys(data) <- teal.data::default_cdisc_join_keys[names(data)]

  vars1 <- teal.transform::choices_selected(
    teal.transform::variable_choices(data[["ADSL"]], c("ARM", "COUNTRY", "SEX")),
    selected = NULL
  )

  init_teal_app_driver(
    teal::init(
      data = data,
      modules = tm_g_distribution(
        dist_var = teal.picks::picks(
          teal.picks::datasets("ADSL", "ADSL"),
          teal.picks::variables(c("AGE", "BMRKR1"), "BMRKR1")
        ),
        strata_var = teal.picks::picks(
          teal.picks::datasets("ADSL", "ADSL"),
          teal.picks::variables(c("ARM", "COUNTRY", "SEX"), NULL),
          values()
        ),
        group_var = teal.picks::picks(
          teal.picks::datasets("ADSL", "ADSL"),
          teal.picks::variables(c("ARM", "COUNTRY", "SEX"), NULL),
          values()
        ),
        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_var-variables-selected"), "BMRKR1")
  testthat::expect_equal(app_driver$get_active_module_input("group_var-variables-selected"), "")
  testthat::expect_null(app_driver$get_active_module_input("group_var-values-selected"))
  testthat::expect_equal(app_driver$get_active_module_input("strata_var-variables-selected"), "")
  testthat::expect_null(app_driver$get_active_module_input("strata_var-values-selected"))
  testthat::expect_equal(app_driver$get_active_module_input("histogram_plot-bins"), 36)
  testthat::expect_equal(app_driver$get_active_module_input("histogram_plot-statistic"), "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_plot-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("histogram_plot-statistic", "Density")
  .change_selectpicker(app_driver, app_driver$namespaces()$module("test_table-dist_test"), "Shapiro-Wilk")

  # Encodings in the Histogram tab
  set_picks_slot_selected(app_driver, "group_var", "ARM")
  app_driver$expect_no_validation_error()

  app_driver$expect_no_validation_error()

  set_picks_slot_selected(app_driver, "group_var", c("A: Drug X", "C: Combination"), "values")
  app_driver$expect_no_validation_error()

  app_driver$set_active_module_input("scales_type", "Free")
  app_driver$expect_no_validation_error()

  set_picks_slot_selected(app_driver, "strata_var", "SEX")
  app_driver$expect_no_validation_error()

  set_picks_slot_selected(app_driver, "strata_var", c("F"), "values")
  app_driver$expect_no_validation_error()

  app_driver$set_active_module_input("histogram_plot-bins", 50)
  app_driver$expect_no_validation_error()

  app_driver$set_active_module_input("histogram_plot-add_density", FALSE)
  app_driver$expect_no_validation_error()

  app_driver$stop()
})

testthat::test_that("e2e - tm_g_distribution: QQ plot encoding inputs produce output without validation errors.", {
  skip_if_too_deep(5)

  app_driver <- app_driver_tm_g_distribution()

  # Encodings in the QQplot tab
  .change_selectpicker(app_driver, app_driver$namespaces()$module("test_table-dist_test"), "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(app_driver$namespaces()$module("params_reset"))

  app_driver$expect_no_validation_error()

  app_driver$stop()
})

Try the teal.modules.general package in your browser

Any scripts or data that you put into this service are public.

teal.modules.general documentation built on Aug. 2, 2026, 1:06 a.m.