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

Quarto rendering tests #162

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 64 additions & 23 deletions tests/testthat/test-quarto_leanpub_prep.R
Original file line number Diff line number Diff line change
@@ -1,38 +1,79 @@
if (Sys.getenv("GH_PAT") != "") {

test_that("Get base URL - Quarto", {
# Authorize GitHub
auth_from_secret("github",
token = Sys.getenv("GH_PAT"),
in_test = FALSE
)
### Now run functions we will test
base_url <- get_pages_url(repo_name = "fhdsl/OTTR_Quarto",
git_pat = Sys.getenv("secrets.GH_PAT"))

test_that("Create Leanpub IFrames for Quarto", {
# TODO: Test that the URL can
testthat::expect_true(base_url == "https://hutchdatascience.org/OTTR_Quarto/")
})

test_that("Get chapters - Quarto", {
### Set up the OTTR repo
dir <- setup_ottr_template(dir = ".", type = "quarto")

# TODO: This should be functionalized and incorporated into the package
# curl -o make_screenshots.R https://raw.githubusercontent.com/jhudsl/ottr-reports/main/scripts/make_screenshots.R
# chapt_urls=$(Rscript --vanilla make_screenshots.R
# --git_pat sys.getEnv("GH_PAT")
# --repo fhdsl/OTTR_Quarto
# --output_dir resources/chapt_screen_images)

## TEST HERE:
# 1. Does each chapter have screenshot?
# 2. Is the file 'resources/chapt_screen_images/chapter_urls.tsv' made fresh?
# 2. Does chapter_urls.tsv file made have columns with information that are labeled "url", "chapt_title" and "img_path"

#ottrpal::bookdown_to_embed_leanpub(
# render = FALSE,
# chapt_img_key = 'resources/chapt_screen_images/chapter_urls.tsv',
# make_book_txt = TRUE,
# quiz_dir = NULL)

## TEST HERE:
# 1. Did each chapter get a md in the manuscript folder?
# 2. Does each md link to the appropriate sceenshot?
# 3. Did the screenshot file path that's in the md lead to the appropriate file path?
chapt_df <- get_chapters(html_page = file.path("OTTR_Quarto-main", "docs", "index.html"))

testthat::expect_named(chapt_df, c("url", "chapt_title"))

})

test_that("Make screenshots - Quarto", {
# We want to make screenshots from the course
chapt_df_file <- make_screenshots(git_pat = Sys.getenv("secrets.GH_PAT"),
repo = "fhdsl/OTTR_Quarto",
path = "OTTR_Quarto-main")

testthat::expect_equal(chapt_df_file, "resources/chapt_screen_images/chapter_urls.tsv")

chapt_df <- readr::read_tsv(file.path("OTTR_Quarto-main",
"resources",
"chapt_screen_images",
"chapter_urls.tsv"))

# Expect column names should still be the
testthat::expect_names(chapt_df, c("url", "chapt_title", "img_path"))

testthat::expect_number(nrow(chapt_df), 5)
})

test_that("Set Up Leanpub - fhdsl/OTTR_Quarto", {
dir <- setup_ottr_template(dir = ".", type = "quarto")

# We're going to delete this so we can test making it again
unlink(file.path(dir, "manuscript"), recursive = TRUE)

# Now run the iframe maker bit
website_to_embed_leanpub(
path = dir,
chapt_img_key = file.path('resources', 'chapt_screen_images', 'chapter_urls.tsv'),
make_book_txt = TRUE,
quiz_dir = NULL,
output_dir = "manuscript")

testthat::expect_true(
file.exists(file.path(dir,
"manuscript",
"resources",
"chapt_screen_images",
"introduction.png")))

# Lets check what the file looks like
intro <- readLines(file.path(dir, "manuscript", "1-Introduction.md"))

# Make sure the png is pointed to
testthat::expect_true(any(grepl("poster:resources/chapt_screen_images/introduction.png", intro)))

# Make sure we link to the page
testthat::expect_true(any(grepl("![](https://hutchdatascience.org/OTTR_Quarto/intro.html)", intro, fixed = TRUE)))

clean_up()
})

}
Loading