test_that("webawesomePage attaches the package dependency once", { page <- shiny.webawesome::webawesomePage( shiny.webawesome:::.wa_component("wa-card", "Hello"), shiny.webawesome:::.wa_component("wa-checkbox") ) deps <- htmltools::findDependencies(page) dep_names <- vapply(deps, `[[`, character(1), "name") expect_equal(sum(dep_names == "shiny.webawesome"), 1L) }) test_that("webawesomePage attaches the Awesome theme stylesheet", { page <- shiny.webawesome::webawesomePage( class = "wa-theme-awesome wa-palette-bright wa-brand-blue", shiny.webawesome:::.wa_component("wa-card", "Hello") ) deps <- htmltools::findDependencies(page) dep_names <- vapply(deps, `[[`, character(1), "name") dep_stylesheets <- vapply( deps, `[[`, character(1), "stylesheet" ) expect_true("shiny.webawesome" %in% dep_names) expect_true("shiny.webawesome-theme-awesome" %in% dep_names) expect_true("www/wa/styles/themes/awesome.css" %in% dep_stylesheets) }) test_that("webawesomePage attaches the Shoelace theme stylesheet", { page <- shiny.webawesome::webawesomePage( class = "wa-theme-shoelace wa-palette-shoelace wa-brand-blue", shiny.webawesome:::.wa_component("wa-card", "Hello") ) deps <- htmltools::findDependencies(page) dep_names <- vapply(deps, `[[`, character(1), "name") dep_stylesheets <- vapply( deps, `[[`, character(1), "stylesheet" ) expect_true("shiny.webawesome" %in% dep_names) expect_true("shiny.webawesome-theme-shoelace" %in% dep_names) expect_true("www/wa/styles/themes/shoelace.css" %in% dep_stylesheets) }) test_that("webawesomePage rejects multiple recognized theme classes", { expect_error( shiny.webawesome::webawesomePage( class = "wa-theme-awesome wa-theme-shoelace", shiny.webawesome:::.wa_component("wa-card", "Hello") ), paste0( "`class` must not include more than one Web Awesome theme class. ", 'Found: "wa-theme-awesome", "wa-theme-shoelace".' ), fixed = TRUE ) }) test_that("webawesomePage returns an html page scaffold", { page <- shiny.webawesome::webawesomePage( title = "Runtime test", lang = "en", class = "wa-theme-default wa-palette-default wa-brand-blue", body_class = "app-shell", shiny.webawesome:::.wa_component("wa-card", "Hello") ) rendered <- htmltools::renderTags(page) expect_match( rendered$html, paste0( "]*lang=\"en\"[^>]*class=\"", "wa-theme-default wa-palette-default wa-brand-blue\"" ), perl = TRUE ) expect_match(rendered$head, "Runtime test", perl = TRUE) expect_match(rendered$html, "]*class=\"app-shell\"", perl = TRUE) }) test_that( "internal component helper attaches the dependency in fluidPage usage", { ui <- shiny::fluidPage( shiny.webawesome:::.wa_component("wa-card", "Hello") ) deps <- htmltools::findDependencies(ui) dep_names <- vapply(deps, `[[`, character(1), "name") expect_equal(sum(dep_names == "shiny.webawesome"), 1L) } ) test_that("package dependency points at the shipped bootstrap assets", { binding_dir <- system.file("bindings", package = "shiny.webawesome") dep <- shiny.webawesome:::.wa_dependency() script_src <- vapply(dep$script, `[[`, character(1), "src") expect_equal(dep$name, "shiny.webawesome") expect_equal(dep$src$file, ".") expect_equal(dep$stylesheet, "www/wa/styles/webawesome.css") expect_equal(script_src[[1]], "www/webawesome-init.js") expect_equal(dep$script[[1]]$type, "module") expect_true("bindings/wa_button.js" %in% script_src) expect_true("bindings/wa_checkbox.js" %in% script_src) expect_true("bindings/wa_color_picker.js" %in% script_src) expect_true("bindings/wa_input.js" %in% script_src) expect_true("bindings/wa_number_input.js" %in% script_src) expect_true("bindings/wa_dropdown.js" %in% script_src) expect_true("bindings/wa_radio_group.js" %in% script_src) expect_true("bindings/wa_rating.js" %in% script_src) expect_true("bindings/wa_select.js" %in% script_src) expect_true("bindings/wa_slider.js" %in% script_src) expect_true("bindings/wa_switch.js" %in% script_src) expect_true("bindings/wa_textarea.js" %in% script_src) expect_true("bindings/wa_tree.js" %in% script_src) expect_match( as.character(dep$head), "window\\.shinyWebawesomeWarnings", perl = TRUE ) }) test_that("package dependency renders warning bootstrap as a script tag", { dep_html <- htmltools::renderDependencies( htmltools::resolveDependencies(list(shiny.webawesome:::.wa_dependency())), srcType = "file" ) expect_match( dep_html, "