tests/testthat/test-shinytest2-tm_t_crosstable_picks.R

app_driver_tm_t_crosstable <- function() {
  data <- simple_cdisc_data()
  init_teal_app_driver(
    teal::init(
      data = data,
      modules = tm_t_crosstable(
        label = "Cross Table",
        x = teal.picks::picks(
          teal.picks::datasets("ADSL", "ADSL"),
          suppressWarnings(
            teal.picks::variables(
              function(x) !inherits(x, c("Date", "POSIXct", "POSIXlt")), "COUNTRY",
              multiple = TRUE
            ),
            classes = "picks_delayed"
          )
        ),
        y = teal.picks::picks(
          teal.picks::datasets("ADSL", "ADSL"),
          suppressWarnings(teal.picks::variables(is.factor, "SEX"), classes = "picks_delayed")
        ),
        show_percentage = TRUE,
        show_total = TRUE,
        pre_output = NULL,
        post_output = NULL,
        basic_table_args = teal.widgets::basic_table_args(
          subtitles = "Table generated by Crosstable Module"
        )
      )
    )
  )
}

test_that("e2e - tm_t_crosstable: Initializes without errors", {
  skip_if_too_deep(5)
  app_driver <- app_driver_tm_t_crosstable()

  app_driver$expect_no_shiny_error()

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

  encoding_dataset <- trimws(app_driver$get_text(".badge-dropdown-label"))
  testthat::expect_match(encoding_dataset, "^(ADSL)[[:space:]]")

  app_driver$stop()
})

test_that("e2e - tm_t_crosstable: Verify module displays data table", {
  skip_if_too_deep(5)
  app_driver <- app_driver_tm_t_crosstable()

  # table
  app_driver$expect_visible(selector = app_driver$namespaces(TRUE)$module("table-table-with-settings"))

  app_driver$stop()
})

test_that("e2e - tm_t_crosstable: Verify default values and settings (data_extracts) for data selection", {
  skip_if_too_deep(5)
  app_driver <- app_driver_tm_t_crosstable()

  # default variable selection
  testthat::expect_equal(
    app_driver$get_active_module_input("x-variables-selected"),
    "COUNTRY"
  )

  testthat::expect_equal(
    app_driver$get_active_module_input("y-variables-selected"),
    "SEX"
  )

  # new variable selection
  set_picks_slot_selected(app_driver, "x", c("SEX", "RACE", "COUNTRY"))
  set_picks_slot_selected(app_driver, "y", "ETHNIC")
  app_driver$expect_no_validation_error()

  app_driver$stop()
})

test_that("e2e - tm_t_crosstable: Change plot settings", {
  skip_if_too_deep(5)
  app_driver <- app_driver_tm_t_crosstable()

  app_driver$click(selector = app_driver$namespaces(TRUE)$module("show_percentage"))
  app_driver$expect_no_validation_error()

  app_driver$click(selector = app_driver$namespaces(TRUE)$module("show_total"))
  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.