Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject CSS styling into RMD parametrization app #866

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
[params] added tests to params_html_head
Uriel Avalos committed Nov 11, 2016
commit 99e714d12cb34ab2179160d6f78cf2b0ec8b57ae
10 changes: 5 additions & 5 deletions R/params.R
Original file line number Diff line number Diff line change
@@ -187,7 +187,7 @@ params_namedList <- function() {
}


setup_html_head <- function(html_head_style = c(),
params_html_head <- function(html_head_style = c(),
html_head_script = c(),
html_head_style_link = c(),
html_head_script_link = c()) {
@@ -225,10 +225,10 @@ setup_html_head <- function(html_head_style = c(),
append(
list(default_style, default_script),
c(
custom_styles,
custom_scripts,
custom_style_links,
custom_script_links
custom_styles,
custom_script_links,
custom_scripts
)
)
))
@@ -463,7 +463,7 @@ knit_params_ask <- function(file = NULL,
class = "navbar navbar-default navbar-fixed-bottom")

ui <- shiny::bootstrapPage(
setup_html_head(
params_html_head(
html_head_style = html_head_style,
html_head_script = html_head_script,
html_head_style_link = html_head_style_link,
14 changes: 13 additions & 1 deletion man/knit_params_ask.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions tests/testthat/test-params.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
context("params_html_head")

anyHeadParams <- list(
html_head_style="style",
html_head_style_link = "link",
html_head_script = "script",
html_head_script_link = "scriptjs"
)

test_that("adds default style and script", {
result <- params_html_head()$children
expect_equal(length(result), 2)
expect_equal(result[[1]]$name, "style")
expect_equal(result[[2]]$name, "script")
})

test_that("adds custom style after default style", {
result <- do.call(params_html_head, anyHeadParams)$children
expect_equal(length(result), 6)
expect_equal(result[[4]], shiny::tags$style("style"))
})

test_that("adds custom style links after default but before inline custom styles", {
result <- do.call(params_html_head, anyHeadParams)$children
expect_equal(length(result), 6)
expect_equal(result[[3]], shiny::tags$link(href = "link"))
expect_equal(result[[4]], shiny::tags$style("style"))
})

test_that("adds custom script links after default but before inline custom scripts", {
result <- do.call(params_html_head, anyHeadParams)$children
expect_equal(length(result), 6)
expect_equal(result[[5]], shiny::tags$script(src = "scriptjs"))
expect_equal(result[[6]], shiny::tags$script(shiny::HTML("script")))
})

test_that("can pass string as style link", {
result <- params_html_head(html_head_style_link="link")$children
expect_equal(result[[3]], shiny::tags$link(href = "link"))
})

test_that("can pass vector of strings as style link", {
result <- params_html_head(html_head_style_link=c("link"))$children
expect_equal(result[[3]], shiny::tags$link(href = "link"))
})

test_that("can pass string as style", {
result <- params_html_head(html_head_style="style")$children
expect_equal(result[[3]], shiny::tags$style("style"))
})

test_that("can pass vector of strings as style", {
result <- params_html_head(html_head_style=c("style"))$children
expect_equal(result[[3]], shiny::tags$style("style"))
})

test_that("can pass string as script", {
result <- params_html_head(html_head_script="script")$children
expect_equal(result[[3]], shiny::tags$script(shiny::HTML("script")))
})

test_that("can pass vector of strings as script", {
result <- params_html_head(html_head_script=c("script"))$children
expect_equal(result[[3]], shiny::tags$script(shiny::HTML("script")))
})

test_that("can pass string as script link", {
result <- params_html_head(html_head_script_link="script")$children
expect_equal(result[[3]], shiny::tags$script(src = "script"))
})

test_that("can pass vector of strings as script link", {
result <- params_html_head(html_head_script_link=c("script"))$children
expect_equal(result[[3]], shiny::tags$script(src = "script"))
})