Skip to content

Commit

Permalink
test: use functions from helper.R
Browse files Browse the repository at this point in the history
  • Loading branch information
HenningLorenzen-ext-bayer committed Jul 19, 2024
1 parent b4e1012 commit cc095ae
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions tests/testthat/test-build-article.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ test_that("BS5 article gets correctly activated navbar", {

html <- xml2::read_html(article_path)
navbar <- xml2::xml_find_first(html, ".//div[contains(@class, 'navbar')]")

expect_equal(
xpath_text(navbar,".//li[contains(@class, 'active')]//button"),
"Articles"
Expand All @@ -104,7 +104,7 @@ test_that("output is reproducible by default, i.e. 'seed' is respected", {
r_code_block("runif(5L)")
))
suppressMessages(path <- build_article("test", pkg))

html <- xml2::read_html(path)
output <- xpath_text(html, "//main//pre")[[2]]
expect_snapshot(cat(output))
Expand Down Expand Up @@ -133,7 +133,7 @@ test_that("can control math mode", {
suppressMessages(path <- build_article("math", pkg))
html <- xml2::read_html(path)
expect_equal(xpath_length(html, ".//span[contains(@class, 'math')]"), 1)

pkg$meta$template$`math-rendering` <- "katex"
suppressMessages(init_site(pkg))
suppressMessages(path <- build_article("math", pkg))
Expand Down Expand Up @@ -276,11 +276,23 @@ test_that("warns about missing images", {
expect_snapshot(build_article("kitten", pkg))
})

test_that("spaces in base paths do work", {
d <- withr::local_tempdir("basename with spaces")
fs::dir_copy(test_path("assets/articles-images"), d, overwrite = TRUE)
test_that("spaces in sorce paths do work", {
# create simulated package
pkg0 <- local_pkgdown_site()
pkg0 <- pkg_add_file(pkg0, "vignettes/kitten.Rmd", "![Kitten](kitten.jpg)")
pkg0 <- pkg_add_kitten(pkg0, "vignettes")

# copy simulated pkg to path that contains spaces
d <-
fs::dir_copy(
path = pkg0$src_path,
new_path = fs::file_temp(pattern = "beware of spaces-")
)

expect_no_error(build_article(name = "kitten", pkg = d))
# check that pkgdown site builds anyways
expect_no_error(suppressMessages({
build_article(name = "kitten", pkg = as_pkgdown(pkg = d))
}))
})

test_that("warns about missing alt-text", {
Expand Down

0 comments on commit cc095ae

Please sign in to comment.