From 5e095329ef5dec113bcc0d0f98c31b6e12b64115 Mon Sep 17 00:00:00 2001 From: elena Date: Mon, 27 Nov 2023 12:34:37 +0100 Subject: [PATCH] update urls & add tests --- R/bs4_book.R | 10 +++--- tests/testthat/test-bs4_book.R | 66 ++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/R/bs4_book.R b/R/bs4_book.R index 5fd5c527a..e03673b47 100644 --- a/R/bs4_book.R +++ b/R/bs4_book.R @@ -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]]) @@ -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" diff --git a/tests/testthat/test-bs4_book.R b/tests/testthat/test-bs4_book.R index 294b22bde..0da3ff259 100644 --- a/tests/testthat/test-bs4_book.R +++ b/tests/testthat/test-bs4_book.R @@ -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( @@ -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/')