# =========================================================================== # Tests for a11y_highContrastButton # =========================================================================== # --- Default parameters ----------------------------------------------------- test_that("a11y_highContrastButton works with defaults", { btn <- a11y_highContrastButton() expect_s3_class(btn, "shiny.tag") html <- as.character(btn) expect_true(grepl("a11y-high-contrast-toggle", html)) }) test_that("a11y_highContrastButton default inputId is toggle_contrast", { btn <- a11y_highContrastButton() html <- as.character(btn) expect_true(grepl("toggle_contrast", html)) }) test_that("a11y_highContrastButton default label is Contrast Mode", { btn <- a11y_highContrastButton() html <- as.character(btn) expect_true(grepl("Contrast Mode", html)) }) # --- aria-pressed ----------------------------------------------------------- test_that("a11y_highContrastButton sets aria-pressed to false", { btn <- a11y_highContrastButton() html <- as.character(btn) expect_true(grepl('aria-pressed=["\']false["\']', html)) }) # --- CSS class -------------------------------------------------------------- test_that("a11y_highContrastButton has a11y-high-contrast-toggle class", { btn <- a11y_highContrastButton() html <- as.character(btn) expect_true(grepl("a11y-high-contrast-toggle", html)) }) test_that("a11y_highContrastButton also has a11y-btn class (from a11y_actionButton)", { btn <- a11y_highContrastButton() html <- as.character(btn) expect_true(grepl("a11y-btn", html)) }) # --- Custom parameters ------------------------------------------------------ test_that("a11y_highContrastButton accepts custom inputId", { btn <- a11y_highContrastButton(inputId = "my_contrast") html <- as.character(btn) expect_true(grepl("my_contrast", html)) }) test_that("a11y_highContrastButton accepts custom label", { btn <- a11y_highContrastButton(label = "High Contrast") html <- as.character(btn) expect_true(grepl("High Contrast", html)) }) test_that("a11y_highContrastButton works with label = NULL and aria_label", { btn <- a11y_highContrastButton( label = NULL, icon = shiny::icon("adjust"), aria_label = "Toggle contrast" ) html <- as.character(btn) expect_true(grepl('aria-label=["\']Toggle contrast["\']', html)) }) # --- Dependency attachment -------------------------------------------------- test_that("a11y_highContrastButton attaches a11yShiny dependency", { btn <- a11y_highContrastButton() deps <- htmltools::htmlDependencies(btn) dep_names <- vapply(deps, function(d) d$name, character(1)) expect_true("a11yShiny" %in% dep_names) })