test_that("can construct menu with children", { menu <- menu_submenu( "Title", list( menu_heading("Heading"), menu_separator(), menu_link("Link", "https://example.com") ) ) expect_snapshot(cat(navbar_html(menu))) }) test_that("bad inputs give clear error", { submenu <- menu_submenu( "Title", list( menu_submenu("Heading", list(menu_heading("Hi"))) ) ) expect_snapshot(error = TRUE, { navbar_html(1) navbar_html(list(foo = 1)) navbar_html(submenu) }) }) test_that("can construct bullets", { expect_snapshot({ cat(navbar_html(menu_icon("fa-question", "https://example.com", "label"))) cat(navbar_html(menu_heading("Hi"))) cat(navbar_html(menu_link("Hi", "https://example.com"))) }) }) test_that("bullet class varies based on depth", { expect_equal( navbar_html(menu_separator(), menu_depth = 0), '' ) expect_equal( navbar_html(menu_separator(), menu_depth = 1), '
  • ' ) }) test_that("icons warn if no aria-label", { reset_message_verbosity("icon-aria-label") expect_snapshot({ . <- navbar_html(menu_icon("fa-question", "https://example.com", NULL)) }) }) test_that("icons extract base iconset class automatically", { expect_match( navbar_html(menu_icon("fa-question", "https://example.com", "label")), 'class="fa fa-question"', fixed = TRUE ) expect_match( navbar_html(menu_icon("fab fab-github", "https://example.com", "label")), 'class="fab fab-github"', fixed = TRUE ) }) test_that("can specify link target", { expect_match( navbar_html(menu_link("a", "b", target = "_blank")), 'target="_blank"', fixed = TRUE ) }) test_that("can construct theme menu", { pkg <- local_pkgdown_site(meta = list(template = list(bootstrap = 5, `light-switch` = TRUE))) lightswitch <- navbar_components(pkg)$lightswitch expect_snapshot(cat(navbar_html(lightswitch))) }) test_that("simple components don't change without warning", { expect_snapshot({ cat(navbar_html(menu_heading("a"))) cat(navbar_html(menu_link("a", "b"))) cat(navbar_html(menu_separator())) cat(navbar_html(menu_search())) }) }) # Building blocks ----------------------------------------------------------- test_that("navbar_html_text() combines icons and text", { expect_equal(navbar_html_text(list(text = "a")), 'a') expect_equal( navbar_html_text(list(icon = "fas-github", `aria-label` = "github")), '' ) expect_equal( navbar_html_text(list(text = "a", icon = "fas-github", `aria-label` = "github")), ' a' ) }) test_that("navbar_html_text() escapes text", { expect_equal(navbar_html_text(list(text = "<>")), '<>') }) test_that("named arguments become attributes", { expect_equal(html_tag("a"), '') expect_equal(html_tag("a", x = NULL), '') expect_equal(html_tag("a", x = NA), '') expect_equal(html_tag("a", x = 1), '') }) test_that("unnamed arguments become children", { expect_equal(html_tag("a", "b"), 'b') expect_equal(html_tag("a", "b", NULL), 'b') }) test_that("class components are pasted together", { expect_equal(html_tag("a", class = NULL), '') expect_equal(html_tag("a", class = "a"), '') expect_equal(html_tag("a", class = c("a", "b")), '') })