tests/testthat/test-shinytest2-tm_g_association_picks.R

app_driver_tm_g_association <- function() {
  data <- within(teal.data::teal_data(), {
    require(nestcolor)
    require(ggplot2)
    CO2 <- CO2 # nolint: object_name.
    .factors <- names(Filter(isTRUE, vapply(CO2, is.factor, logical(1L))))
    CO2[.factors] <- lapply(CO2[.factors], as.character) # nolint: object_name.
  })

  init_teal_app_driver(
    teal::init(
      data = data,
      modules = tm_g_association(
        label = "Association",
        ref = teal.picks::picks(
          teal.picks::datasets("CO2", "CO2"),
          teal.picks::variables(c("Plant", "Type", "Treatment"), "Plant")
        ),
        vars = teal.picks::picks(
          teal.picks::datasets("CO2", "CO2"),
          teal.picks::variables(c("Plant", "Type", "Treatment"), "Treatment", multiple = TRUE)
        ),
        show_association = TRUE,
        plot_height = c(600, 400, 5000),
        plot_width = NULL,
        distribution_theme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"),
        association_theme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"),
        pre_output = NULL,
        post_output = NULL,
        ggplot2_args = teal.widgets::ggplot2_args(
          labs = list(subtitle = "Plot generated by Association Module")
        )
      )
    )
  )
}

testthat::test_that("e2e - tm_g_association: Data parameter and module label is passed properly.", {
  skip_if_too_deep(5)
  app_driver <- app_driver_tm_g_association()
  app_driver$expect_no_shiny_error()

  testthat::expect_equal(app_driver$get_text(".teal-modules-tree .active"), "Association")

  encoding_dataset <- trimws(app_driver$get_text(
    app_driver$namespaces(TRUE)$module("ref-inputs-summary_badge")
  ))
  testthat::expect_match(encoding_dataset, "CO2[[:space:]]+Plant", all = FALSE)

  app_driver$stop()
})

testthat::test_that("e2e - tm_g_association:
  picks elements are initialized with the default values specified by ref and vars arguments.", {
  skip_if_too_deep(5)
  app_driver <- app_driver_tm_g_association()

  testthat::expect_identical(app_driver$get_active_module_input("ref-variables-selected"), "Plant")
  set_picks_slot_selected(app_driver, "ref", "Type")
  app_driver$expect_no_validation_error()

  testthat::expect_identical(app_driver$get_active_module_input("vars-variables-selected"), "Treatment")
  set_picks_slot_selected(app_driver, "vars", "Plant")
  app_driver$expect_no_validation_error()

  app_driver$stop()
})

testthat::test_that("e2e - tm_g_association: Module plot is visible.", {
  skip_if_too_deep(5)
  app_driver <- app_driver_tm_g_association()

  testthat::expect_true(app_driver$is_visible(app_driver$namespaces(TRUE)$module("myplot-plot_main > img")))

  app_driver$stop()
})

testthat::test_that("e2e - tm_g_association: Check and set default values for radio buttons.", {
  skip_if_too_deep(5)
  app_driver <- app_driver_tm_g_association()

  testthat::expect_true(app_driver$get_active_module_input("association"))
  testthat::expect_false(app_driver$get_active_module_input("show_dist"))
  testthat::expect_false(app_driver$get_active_module_input("log_transformation"))

  app_driver$set_active_module_input("association", FALSE)
  app_driver$set_active_module_input("show_dist", TRUE)
  app_driver$set_active_module_input("log_transformation", TRUE)
  app_driver$expect_no_validation_error()
  app_driver$expect_no_shiny_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.