test_that("wa_carousel requires input_id", {
expect_error(
shiny.webawesome:::wa_carousel(),
'argument "input_id" is missing',
fixed = TRUE
)
})
test_that("wa_carousel defaults render the minimal semantic wrapper", {
expect_exact_html(
render_html(
shiny.webawesome:::wa_carousel(
input_id = "carousel",
htmltools::tag("wa-carousel-item", "Slide 1"),
htmltools::tag("wa-carousel-item", "Slide 2")
)
),
c(
'',
" Slide 1",
" Slide 2",
""
)
)
})
test_that("wa_carousel override render includes attrs and slots", {
expect_exact_html(
render_html(
shiny.webawesome:::wa_carousel(
input_id = "carousel",
htmltools::tag("wa-carousel-item", "Slide 1"),
autoplay = TRUE,
autoplay_interval = 4000,
current_slide = 2,
dir = "rtl",
lang = "en",
loop = TRUE,
mouse_dragging = TRUE,
navigation = TRUE,
orientation = "vertical",
pagination = TRUE,
slides = 3,
slides_per_move = 2,
slides_per_page = 1,
next_icon = "Next",
previous_icon = "Previous"
)
),
c(
paste0(
''
),
" Slide 1",
' Next',
' Previous',
""
)
)
})
test_that("wa_carousel boolean args validate and render correctly", {
boolean_args <- c(
autoplay = "autoplay",
loop = "loop",
mouse_dragging = "mouse-dragging",
navigation = "navigation",
pagination = "pagination"
)
default_html <- render_html(
shiny.webawesome:::wa_carousel(
input_id = "carousel",
htmltools::tag("wa-carousel-item", "Slide 1")
)
)
for (arg_name in names(boolean_args)) {
attr_name <- boolean_args[[arg_name]]
true_tag <- do.call(
shiny.webawesome:::wa_carousel,
c(
list(
input_id = "carousel",
htmltools::tag("wa-carousel-item", "Slide 1")
),
stats::setNames(list(TRUE), arg_name)
)
)
expect_exact_html(
render_html(true_tag),
c(
sprintf('', attr_name),
" Slide 1",
""
)
)
false_tag <- do.call(
shiny.webawesome:::wa_carousel,
c(
list(
input_id = "carousel",
htmltools::tag("wa-carousel-item", "Slide 1")
),
stats::setNames(list(FALSE), arg_name)
)
)
expect_equal(render_html(false_tag), default_html)
null_tag <- do.call(
shiny.webawesome:::wa_carousel,
c(
list(
input_id = "carousel",
htmltools::tag("wa-carousel-item", "Slide 1")
),
stats::setNames(list(NULL), arg_name)
)
)
expect_equal(render_html(null_tag), default_html)
expect_error(
do.call(
shiny.webawesome:::wa_carousel,
c(
list(
input_id = "carousel",
htmltools::tag("wa-carousel-item", "Slide 1")
),
stats::setNames(list("yes"), arg_name)
)
),
sprintf("`%s` must be TRUE, FALSE, or NULL.", arg_name),
fixed = TRUE
)
}
})
test_that("wa_carousel orientation enum validates exactly", {
expect_exact_html(
render_html(
shiny.webawesome:::wa_carousel(
input_id = "carousel",
htmltools::tag("wa-carousel-item", "Slide 1"),
orientation = "horizontal"
)
),
c(
'',
" Slide 1",
""
)
)
expect_error(
shiny.webawesome:::wa_carousel(
input_id = "carousel",
htmltools::tag("wa-carousel-item", "Slide 1"),
orientation = "diagonal"
),
"`orientation` must be one of ",
fixed = TRUE
)
})