Skip to content

Commit

Permalink
tests: add testing for internal-funcs standard cases
Browse files Browse the repository at this point in the history
- fix typo in testfile_template_html
- use styler::style_file(..., style = grkstyle::grk_style_transformer)
  • Loading branch information
ilyaZar committed Jul 5, 2023
1 parent 64e11e5 commit 2bb8f16
Showing 1 changed file with 146 additions and 8 deletions.
154 changes: 146 additions & 8 deletions tests/testthat/test-use_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,25 @@ test_that("use_external_XXX_files() function family works properly", {
# 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"
name = "testfile_template_html.html"
)
test_file_download <- readLines(
"inst/app/www/testfile_template_plainfile.html"
"inst/app/www/testfile_template_html.html"
)
expect_identical(
test_file_download,
c("<!DOCTYPE html>", "<html>", "<body>", "",
"<h1>My First Heading</h1>", "", "<p>My first paragraph.</p>", "",
"</body>","</html>")
c(
"<!DOCTYPE html>",
"<html>",
"<body>",
"",
"<h1>My First Heading</h1>",
"",
"<p>My first paragraph.</p>",
"",
"</body>",
"</html>"
)
)

# III. test the external ".js" file download
Expand All @@ -45,8 +54,10 @@ test_that("use_external_XXX_files() function family works properly", {
)
expect_identical(
test_file_download,
c("const myHeading = document.querySelector(\"h1\");",
"myHeading.textContent = \"Hello world!\";")
c(
"const myHeading = document.querySelector(\"h1\");",
"myHeading.textContent = \"Hello world!\";"
)
)

# IV. test the external ".css" file download
Expand All @@ -59,7 +70,134 @@ test_that("use_external_XXX_files() function family works properly", {
)
expect_identical(
test_file_download,
c(" body {",
c(
" body {",
" background-color: lightblue;",
"}",
"",
"h1 {",
" color: white;",
" text-align: center;",
"}",
"",
"p {",
" font-family: verdana;",
" font-size: 20px;",
"}"
)
)
unlink(path_dummy_golem, recursive = TRUE)
}
)
})
test_that("use_internal_XXX_files() function family works properly", {
path_dummy_golem <- tempfile(pattern = "dummygolem")
create_golem(
path = path_dummy_golem,
open = FALSE
)
dir.create(file.path(path_dummy_golem, "tmp_dump_testfiles"))
file.copy(
from = file.path(
.libPaths()[1],
"golem",
"utils",
c(
"testfile_template_plainfile.txt",
"testfile_template_html.html",
"testfile_template_js.js",
"testfile_template_css.css"
)
),
to = file.path(
path_dummy_golem,
"tmp_dump_testfiles"
)
)
with_dir(
path_dummy_golem,
{
# I. test the internal ".txt" file download
use_internal_file(
path = file.path(
path_dummy_golem,
"tmp_dump_testfiles",
"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 internal ".html" file download
use_internal_html_template(
path = file.path(
path_dummy_golem,
"tmp_dump_testfiles",
"testfile_template_html.html"
),
name = "testfile_template_html.html"
)
test_file_download <- readLines(
"inst/app/www/testfile_template_html.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 internal ".js" file download
use_internal_js_file(
path = file.path(
path_dummy_golem,
"tmp_dump_testfiles",
"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 internal ".css" file download
use_internal_css_file(
path = file.path(
path_dummy_golem,
"tmp_dump_testfiles",
"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;",
"}",
"",
Expand Down

0 comments on commit 2bb8f16

Please sign in to comment.