| 1 |
test_that("HTML template contains special comment when in shiny prerendered", { |
| 2 |
skip_if_not_pandoc() |
| 3 |
special_comment <- "<!-- HEAD_CONTENT -->" |
| 4 |
content <- c("---", "title: shiny", "runtime: shiny_prerendered", "---", "", "```{r}", "1+1", "```") |
| 5 |
tmp_rmd <- local_rmd_file(content) |
| 6 |
html <- .render_and_read(tmp_rmd, output_format = "html_document") |
| 7 |
expect_match(one_string(html), special_comment, fixed = TRUE, |
| 8 |
label = "hmlt_document template") |
| 9 |
html <- .render_and_read(tmp_rmd, output_format = "ioslides_presentation") |
| 10 |
expect_match(one_string(html), special_comment, fixed = TRUE, |
| 11 |
label = "ioslides_presentation template") |
| 12 |
html <- .render_and_read(tmp_rmd, output_format = "slidy_presentation") |
| 13 |
expect_match(one_string(html), special_comment, fixed = TRUE, |
| 14 |
label = "slidy_presentation template") |
| 15 |
# no runtime shiny prerendered |
| 16 |
content <- content[-which(grepl("^runtime", content))] |
| 17 |
tmp_rmd <- local_rmd_file(content) |
| 18 |
html <- .render_and_read(tmp_rmd, output_format = "html_document") |
| 19 |
expect_false(any(grepl(special_comment, html))) |
| 20 |
}) |
| 21 |
|
| 22 |
test_that("Special HEAD comment is added if none in rendered HTML when in shiny prerendered", { |
| 23 |
skip_if_not_pandoc() |
| 24 |
# inserted in default template |
| 25 |
special_comment <- "^\\s*<!-- HEAD_CONTENT -->\\s*$" |
| 26 |
tmp_rmd <- local_rmd_file(c("---", "title: shiny", "runtime: shiny_prerendered", "---", "", "```{r}", "1+1", "```")) |
| 27 |
html <- shiny_prerendered_html(tmp_rmd, list(quiet = TRUE)) |
| 28 |
expect_length(grep(special_comment, xfun::split_lines(html)), 1L) |
| 29 |
# inserted in pandoc template |
| 30 |
tmp_rmd <- local_rmd_file(c("---", "title: shiny", "runtime: shiny_prerendered", "---", "", "```{r}", "1+1", "```")) |
| 31 |
opts <- list(template = NULL, mathjax = NULL) |
| 32 |
html <- shiny_prerendered_html(tmp_rmd, list(output_options = opts, quiet = TRUE)) |
| 33 |
expect_length(grep(special_comment, xfun::split_lines(html)), 1L) |
| 34 |
# placed in include headers |
| 35 |
tmp_rmd <- local_rmd_file(c("---", "title: shiny", "runtime: shiny_prerendered", "---", "", "content")) |
| 36 |
template <- withr::local_tempfile(fileext = ".html") |
| 37 |
xfun::write_utf8(c("<head>", "$header-includes$", "<scripts></scripts>", "</head>", |
| 38 |
"<body>", "$body$", "</body>"), |
| 39 |
template) |
| 40 |
opts <- list(template = template, mathjax = NULL) |
| 41 |
html <- shiny_prerendered_html(tmp_rmd, list(output_options = opts, quiet = TRUE)) |
| 42 |
expect_equal(grep(special_comment, xfun::split_lines(html)), 2) |
| 43 |
}) |
| 44 |
|
| 45 |
test_that("html can be annotated as being a full document with deps attached", { |
| 46 |
html <- HTML("dummy") |
| 47 |
deps <- list(htmltools::htmlDependency("a", "1.1", c(href = "/"))) |
| 48 |
ui <- shiny_prerendered_ui(html, deps) |
| 49 |
expect_s3_class(ui, "html_document") |
| 50 |
expect_equal(htmltools::htmlDependencies(ui), deps) |
| 51 |
}) |
| 52 |
|
| 53 |
# As we don't use directly `{{ headContent() }}`, this test should help detect |
| 54 |
# if htmltools has change this special token in the future. In our CI tests, but also |
| 55 |
# in reverse dependency test |
| 56 |
test_that("htmtools still use the special token rmarkdown uses in its template", { |
| 57 |
htmltools_headcontent <- as.character(htmltools::htmlTemplate(text_ = "{{ headContent() }}")) |
| 58 |
expect_match(htmltools_headcontent, "<!-- HEAD_CONTENT -->", fixed = TRUE) |
| 59 |
}) |