tests/testthat/test-button_Input.R

test_that("default button has plain govuk-button class and renders label", {
  btn <- button_Input("btnId", "Continue")

  expect_identical(
    htmltools::tagGetAttribute(btn, "class"),
    "govuk-button action-button"
  )
  expect_identical(htmltools::tagGetAttribute(btn, "id"), "btnId")
  expect_identical(tag_text(btn, "govuk-button"), "Continue")
  expect_no_tag(btn, "govuk-button__start-icon")
})

test_that("start button has start modifier and start-icon svg", {
  btn <- button_Input("btnId", "Start now", type = "start")

  expect_identical(
    htmltools::tagGetAttribute(btn, "class"),
    "govuk-button govuk-button--start action-button"
  )
  # A start button carries the label plus the arrow svg, so assert both
  # children rather than reaching for the single-child tag_text().
  expect_identical(rendered_children(btn)[[1L]], "Start now")

  icon <- expect_has_tag(btn, "govuk-button__start-icon")
  expect_identical(icon$name, "svg")
  expect_identical(rendered_children(btn)[[2L]], icon)
})

test_that("start button wraps rich label before the icon", {
  btn <- button_Input("btnId", shiny::tags$strong("Start now"), type = "start")

  label <- rendered_children(btn)[[1L]]
  expect_identical(label$name, "span")
  expect_identical(rendered_children(label)[[1L]]$name, "strong")
  expect_identical(rendered_children(btn)[[2L]]$name, "svg")
})

test_that("secondary button has secondary modifier and no start-icon", {
  btn <- button_Input("btnId", "Cancel", type = "secondary")

  expect_identical(
    htmltools::tagGetAttribute(btn, "class"),
    "govuk-button govuk-button--secondary action-button"
  )
  expect_no_tag(btn, "govuk-button__start-icon")
})

test_that("warning button has warning modifier and no start-icon", {
  btn <- button_Input("btnId", "Delete", type = "warning")

  expect_identical(
    htmltools::tagGetAttribute(btn, "class"),
    "govuk-button govuk-button--warning action-button"
  )
  expect_no_tag(btn, "govuk-button__start-icon")
})

Try the shinyGovstyle package in your browser

Any scripts or data that you put into this service are public.

shinyGovstyle documentation built on Oct. 16, 2026, 1:07 a.m.