# =========================================================================== # Tests for a11y_fluidRow # =========================================================================== # --- Basic structure -------------------------------------------------------- test_that("a11y_fluidRow creates a section tag with a11y-row class", { row <- a11y_fluidRow( a11y_column(6, htmltools::p("Left")), a11y_column(6, htmltools::p("Right")) ) expect_equal(row$name, "section") html <- as.character(row) expect_true(grepl("a11y-row", html)) }) # --- Column width validation ------------------------------------------------ test_that("a11y_fluidRow errors when column widths do not sum to 12", { expect_error( a11y_fluidRow( a11y_column(4, htmltools::p("A")), a11y_column(4, htmltools::p("B")) ), "sum.*8.*expected.*12" ) }) test_that("a11y_fluidRow accepts columns summing to 12", { expect_no_error( a11y_fluidRow( a11y_column(4, htmltools::p("A")), a11y_column(4, htmltools::p("B")), a11y_column(4, htmltools::p("C")) ) ) }) test_that("a11y_fluidRow accepts single column with width 12", { expect_no_error( a11y_fluidRow( a11y_column(12, htmltools::p("Full width")) ) ) }) # --- Non-a11y column detection ---------------------------------------------- test_that("a11y_fluidRow errors on non-a11y columns", { expect_error( a11y_fluidRow( htmltools::tags$div(class = "col-sm-6", htmltools::p("A")), a11y_column(6, htmltools::p("B")) ), "not implemented with a11y_column" ) }) # --- Offset validation ------------------------------------------------------ test_that("a11y_fluidRow accounts for offset in total width", { # width 4 + offset 2 + width 6 = 12 expect_no_error( a11y_fluidRow( a11y_column(4, offset = 2, htmltools::p("A")), a11y_column(6, htmltools::p("B")) ) ) }) test_that("a11y_fluidRow errors when width + offset do not sum to 12", { expect_error( a11y_fluidRow( a11y_column(4, offset = 2, htmltools::p("A")), a11y_column(4, htmltools::p("B")) ), "sum.*10.*expected.*12" ) }) # --- Nested row warning ----------------------------------------------------- test_that("a11y_fluidRow warns on nested a11y_fluidRow", { inner_row <- a11y_fluidRow( a11y_column(12, htmltools::p("Inner")) ) expect_warning( a11y_fluidRow( a11y_column(12, inner_row) ), "Nested a11y_fluidRow" ) }) # --- No columns warning ----------------------------------------------------- test_that("a11y_fluidRow warns when no a11y_column divs found", { expect_warning( a11y_fluidRow(htmltools::tags$p("just text")), "No direct a11y_column" ) }) # --- ID and aria_label passthrough ------------------------------------------ test_that("a11y_fluidRow passes id attribute", { row <- a11y_fluidRow( a11y_column(12, htmltools::p("Content")), id = "my-row" ) expect_equal(row$attribs$id, "my-row") }) test_that("a11y_fluidRow passes aria_label attribute", { row <- a11y_fluidRow( a11y_column(12, htmltools::p("Content")), aria_label = "Results section" ) html <- as.character(row) expect_true(grepl('aria-label=["\']Results section["\']', html)) })