Skip to content

Commit

Permalink
tests: add testing for external-funcs standard cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyaZar committed Jul 5, 2023
1 parent cccb60f commit 64e11e5
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions tests/testthat/test-use_files.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
test_that("use_external_XXX_files() function family works properly", {
path_dummy_golem <- tempfile(pattern = "dummygolem")
create_golem(
path = path_dummy_golem,
open = FALSE
)
with_dir(
path_dummy_golem,
{
# I. test the external ".txt" file download
use_external_file(
url = "https://raw.githubusercontent.com/ilyaZar/golem/fix-1058/inst/utils/testfile_template_plainfile.txt",
name = "testfile_template_plainfile.txt"
)
test_file_download <- readLines(
"inst/app/www/testfile_template_plainfile.txt"
)
expect_identical(
test_file_download,
"Some text."
)

# II. test the external ".html" file download
use_external_html_template(
url = "https://raw.githubusercontent.com/ilyaZar/golem/fix-1058/inst/utils/testfile_template_html.html",
name = "testfile_template_plainfile.html"
)
test_file_download <- readLines(
"inst/app/www/testfile_template_plainfile.html"
)
expect_identical(
test_file_download,
c("<!DOCTYPE html>", "<html>", "<body>", "",
"<h1>My First Heading</h1>", "", "<p>My first paragraph.</p>", "",
"</body>","</html>")
)

# III. test the external ".js" file download
use_external_js_file(
url = "https://raw.githubusercontent.com/ilyaZar/golem/fix-1058/inst/utils/testfile_template_js.js",
name = "testfile_template_js.js"
)
test_file_download <- readLines(
"inst/app/www/testfile_template_js.js"
)
expect_identical(
test_file_download,
c("const myHeading = document.querySelector(\"h1\");",
"myHeading.textContent = \"Hello world!\";")
)

# IV. test the external ".css" file download
use_external_css_file(
url = "https://raw.githubusercontent.com/ilyaZar/golem/fix-1058/inst/utils/testfile_template_css.css",
name = "testfile_template_css.css"
)
test_file_download <- readLines(
"inst/app/www/testfile_template_css.css"
)
expect_identical(
test_file_download,
c(" body {",
" background-color: lightblue;",
"}",
"",
"h1 {",
" color: white;",
" text-align: center;",
"}",
"",
"p {",
" font-family: verdana;",
" font-size: 20px;",
"}"
)
)
unlink(path_dummy_golem, recursive = TRUE)
}
)
})

0 comments on commit 64e11e5

Please sign in to comment.