# =========================================================================== # Tests for a11y_textInputsGroup # =========================================================================== # --- Legend validation ------------------------------------------------------ test_that("a11y_textInputsGroup errors when legend is missing", { expect_error( a11y_textInputsGroup( groupId = "grp1", inputs = list(list(inputId = "f1", label = "Field")) ), "legend.*required" ) }) test_that("a11y_textInputsGroup errors when legend is NULL", { expect_error( a11y_textInputsGroup( groupId = "grp2", legend = NULL, inputs = list(list(inputId = "f1", label = "Field")) ), "legend.*required" ) }) test_that("a11y_textInputsGroup errors when legend is empty string", { expect_error( a11y_textInputsGroup( groupId = "grp3", legend = "", inputs = list(list(inputId = "f1", label = "Field")) ), "legend.*required" ) }) test_that("a11y_textInputsGroup errors when legend is whitespace only", { expect_error( a11y_textInputsGroup( groupId = "grp4", legend = " ", inputs = list(list(inputId = "f1", label = "Field")) ), "legend.*required" ) }) test_that("a11y_textInputsGroup error includes groupId", { expect_error( a11y_textInputsGroup( groupId = "myGroup", legend = "", inputs = list(list(inputId = "f1", label = "Field")) ), "myGroup" ) }) # --- Inputs validation ------------------------------------------------------ test_that("a11y_textInputsGroup errors when inputs is empty list", { expect_error( a11y_textInputsGroup( groupId = "grp5", legend = "Address", inputs = list() ), "non-empty list" ) }) test_that("a11y_textInputsGroup errors when inputs is missing", { expect_error( a11y_textInputsGroup( groupId = "grp6", legend = "Address" ), "non-empty list" ) }) test_that("a11y_textInputsGroup errors when input spec is not a list", { expect_error( a11y_textInputsGroup( groupId = "grp7", legend = "Address", inputs = list("not a list") ), "must be a list" ) }) test_that("a11y_textInputsGroup errors when inputId is missing from spec", { expect_error( a11y_textInputsGroup( groupId = "grp8", legend = "Address", inputs = list(list(label = "Street")) ), "non-empty.*inputId" ) }) # --- Per-input label requirements ------------------------------------------- test_that("a11y_textInputsGroup errors when input has no label, aria_label, or title", { expect_error( a11y_textInputsGroup( groupId = "grp9", legend = "Address", inputs = list(list(inputId = "field1")) ), "label.*aria_label.*title" ) }) test_that("a11y_textInputsGroup accepts input with visible label", { expect_no_error( a11y_textInputsGroup( groupId = "grp10", legend = "Address", inputs = list(list(inputId = "street", label = "Street")) ) ) }) test_that("a11y_textInputsGroup accepts input with aria_label", { expect_no_error( a11y_textInputsGroup( groupId = "grp11", legend = "Address", inputs = list(list(inputId = "street", aria_label = "Street address")) ) ) }) test_that("a11y_textInputsGroup accepts input with title", { expect_no_error( a11y_textInputsGroup( groupId = "grp12", legend = "Address", inputs = list(list(inputId = "street", title = "Enter street name")) ) ) }) # --- Fieldset / legend structure -------------------------------------------- test_that("a11y_textInputsGroup creates a fieldset tag", { grp <- a11y_textInputsGroup( groupId = "grp13", legend = "Address", inputs = list(list(inputId = "street", label = "Street")) ) # Find the fieldset - could be direct or inside a tagList html <- as.character(grp) expect_true(grepl("