Skip to content

Commit

Permalink
tests: drop some visual testing
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgohel committed Oct 27, 2024
1 parent 71b7716 commit 040e39c
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 38 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: officedown
Type: Package
Title: Enhanced 'R Markdown' Format for 'Word' and 'PowerPoint'
Version: 0.3.3
Version: 0.4.0.001
Authors@R: c(
person("David", "Gohel", role = c("aut", "cre", "cph"),
email = "[email protected]"),
Expand Down
Binary file removed tests/testthat/_snaps/rdocx-plots/plot-basic.png
Binary file not shown.
Binary file removed tests/testthat/_snaps/rpptx/pptx-example.png
Binary file not shown.
6 changes: 3 additions & 3 deletions tests/testthat/utils.R → tests/testthat/helper-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ render_rmd <- function(rmd_file, output_file) {
tryCatch(
{
rmarkdown::render(rmd_file,
output_file = output_file,
envir = new.env(),
quiet = TRUE
output_file = output_file,
envir = new.env(),
quiet = TRUE
)
sucess <- TRUE
},
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-rdocx-lists.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ library(rmarkdown)
skip_if_not(rmarkdown::pandoc_available())
skip_if_not(pandoc_version() >= numeric_version("2"))

source("utils.R")

docx_file <- tempfile(fileext = ".docx")
render_rmd("rmd/lists.Rmd", output_file = docx_file)

Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-rdocx-par-settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ library(rmarkdown)
skip_if_not(rmarkdown::pandoc_available())
skip_if_not(pandoc_version() >= numeric_version("2"))

source("utils.R")

docx_file <- tempfile(fileext = ".docx")
render_rmd("rmd/par-settings.Rmd", output_file = docx_file)

Expand Down
17 changes: 2 additions & 15 deletions tests/testthat/test-rdocx-plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ library(rmarkdown)
skip_if_not(rmarkdown::pandoc_available())
skip_if_not(pandoc_version() >= numeric_version("2"))

source("utils.R")

docx_file <- tempfile(fileext = ".docx")
render_rmd("rmd/plot-basic.Rmd", output_file = docx_file)

test_that("reading captions", {

docx_file <- tempfile(fileext = ".docx")
render_rmd("rmd/plot-basic.Rmd", output_file = docx_file)

node_body <- get_docx_xml(docx_file)

expect_equal(
Expand All @@ -24,13 +21,3 @@ test_that("reading captions", {
"Figure SEQ fig \\* Arabic: What a barplot"
)
})

test_that("visual testing plots", {
testthat::skip_if_not_installed("doconv")
testthat::skip_if_not(doconv::msoffice_available())
library(doconv)
docx_file <- tempfile(fileext = ".docx")
render_rmd("rmd/plot-basic.Rmd", output_file = docx_file)

expect_snapshot_doc(x = docx_file, name = "plot-basic", engine = "testthat")
})
2 changes: 0 additions & 2 deletions tests/testthat/test-rdocx-sections.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ skip_on_cran()
skip_if_not(rmarkdown::pandoc_available())
skip_if_not(pandoc_version() >= numeric_version("2"))

source("utils.R")

docx_file <- tempfile(fileext = ".docx")
render_rmd("rmd/sections.Rmd", output_file = docx_file)

Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-rdocx-tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ library(rmarkdown)
skip_if_not(rmarkdown::pandoc_available())
skip_if_not(pandoc_version() >= numeric_version("2"))

source("utils.R")

docx_file <- tempfile(fileext = ".docx")
render_rmd("rmd/tables-basic.Rmd", output_file = docx_file)

Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-render-r.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ library(rmarkdown)
skip_if_not(rmarkdown::pandoc_available())
skip_if_not(pandoc_version() >= numeric_version("2"))

source("utils.R")

str <- c(
"#' ---",
"#' output: officedown::rdocx_document",
Expand Down
22 changes: 13 additions & 9 deletions tests/testthat/test-rpptx.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ library(rmarkdown)
skip_if_not(rmarkdown::pandoc_available())
skip_if_not(pandoc_version() >= numeric_version("2"))

source("utils.R")
pptx_file <- tempfile(fileext = ".pptx")
render_rmd("rmd/pptx.Rmd", output_file = pptx_file)


test_that("visual testing tables", {
testthat::skip_if_not_installed("doconv")
testthat::skip_if_not(doconv::msoffice_available())
library(doconv)
pptx_file <- tempfile(fileext = ".pptx")
render_rmd("rmd/pptx.Rmd", output_file = pptx_file)
expect_snapshot_doc(x = pptx_file, name = "pptx-example", engine = "testthat")
})
test_that("find text in PowerPoint file", {
doc <- read_pptx(pptx_file)
all_doc_sum <- pptx_summary(doc)

doc_sum <- all_doc_sum[all_doc_sum$slide_id == 3,]
expect_contains(doc_sum$text, "temperature")
expect_contains(doc_sum$text, "pressure")

doc_sum <- all_doc_sum[all_doc_sum$slide_id == 4,]
expect_contains(doc_sum$text, "temperature")
expect_contains(doc_sum$text, "pressure")
})

0 comments on commit 040e39c

Please sign in to comment.