Skip to content

Commit

Permalink
update urls & add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ElenaMetori committed Nov 27, 2023
1 parent af0908b commit 5e09532
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 4 deletions.
10 changes: 6 additions & 4 deletions R/bs4_book.R
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,13 @@ tweak_navbar <- function(html, toc, active = "", rmd_index = NULL, repo = NULL)
}

if(grepl("dev.azure", repo$base)) {
repo_edit <- paste0(repo$base, "?path=/", rmd_index[[active]])
repo_edit <- paste0(repo$base, "?path=/", rmd_index[[active]], "&version=GB",
repo$branch)
repo_view <- repo_edit
} else if(grepl("bitbucket", repo$base)){
repo_edit <- paste0(repo$base, "/browse/", rmd_index[[active]])
repo_view <- repo_edit
repo_edit <- paste0(repo$base, "/src/", repo$branch, "/", repo$subdir, rmd_index[[active]],
"?mode=edit&at=", repo$branch)
repo_view <- paste0(repo$base, "/src/", repo$branch, "/", repo$subdir, rmd_index[[active]])
} else {
repo_edit <- paste0(repo$base, "/edit/", repo$branch, "/", repo$subdir, rmd_index[[active]])
repo_view <- paste0(repo$base, "/blob/", repo$branch, "/", repo$subdir, rmd_index[[active]])
Expand All @@ -441,7 +443,7 @@ tweak_navbar <- function(html, toc, active = "", rmd_index = NULL, repo = NULL)
"fab fa-github"
} else if (grepl("dev.azure", repo$base)) {
"fab fa-microsoft"
} else if (grepl("dev.azure", repo$base)) {
} else if (grepl("bitbucket", repo$base)) {
"fab fa-bitbucket"
} else {
"fab fa-gitlab"
Expand Down
66 changes: 66 additions & 0 deletions tests/testthat/test-bs4_book.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,36 @@ test_that("bs4_book() repo specification works - GitLab", {
)
})

test_that("bs4_book() repo specification works - Azure Devops", {
skip_if_bs4_book_deps_missing()
book <- local_bs4_book(
output_options = list(
repo = "https://dev.azure.com/elenasaletter/_git/test_book"
)
)
html <- xml2::read_html(file.path(book, "_book", "index.html"))

expect_equal(
xml2::xml_attr(xml2::xml_child(xml2::xml_find_first(html, "//a[@id='book-repo']")), "class"),
"fab fa-microsoft"
)
})

test_that("bs4_book() repo specification works - Bitbucket", {
skip_if_bs4_book_deps_missing()
book <- local_bs4_book(
output_options = list(
repo = "https://bitbucket.org/test-book/test_book/src/master/"
)
)
html <- xml2::read_html(file.path(book, "_book", "index.html"))

expect_equal(
xml2::xml_attr(xml2::xml_child(xml2::xml_find_first(html, "//a[@id='book-repo']")), "class"),
"fab fa-bitbucket"
)
})

test_that("bs4_book() repo specification works - custom icon", {
skip_if_bs4_book_deps_missing()
book <- local_bs4_book(
Expand Down Expand Up @@ -118,6 +148,42 @@ test_that("bs4_book() repo specification works - custom icon GitHub", {
)
})

test_that("bs4_book() repo specification works - custom icon - Azure Devops", {
skip_if_bs4_book_deps_missing()
book <- local_bs4_book(
output_options = list(
repo = list(
base = "https://dev.azure.com/elenasaletter/_git/test_book",
icon = "fas fa-air-freshener"
)
)
)
html <- xml2::read_html(file.path(book, "_book", "index.html"))

expect_equal(
xml2::xml_attr(xml2::xml_child(xml2::xml_find_first(html, "//a[@id='book-repo']")), "class"),
"fas fa-air-freshener"
)
})

test_that("bs4_book() repo specification works - custom icon - Bitbucket", {
skip_if_bs4_book_deps_missing()
book <- local_bs4_book(
output_options = list(
repo = list(
base = "https://bitbucket.org/test-book/test_book/src/master/",
icon = "fas fa-air-freshener"
)
)
)
html <- xml2::read_html(file.path(book, "_book", "index.html"))

expect_equal(
xml2::xml_attr(xml2::xml_child(xml2::xml_find_first(html, "//a[@id='book-repo']")), "class"),
"fas fa-air-freshener"
)
})

test_that("bs4_book() metadata tweaking works -- index", {
skip_if_bs4_book_deps_missing()
book <- local_bs4_book(description = "A very nice book.", url = 'https://example.com/')
Expand Down

0 comments on commit 5e09532

Please sign in to comment.