context("test-r-create_report.R")
dir_name <- here::here()
test_that("Test if body report is generated", {
file_name <- "test-body.html"
file_dir <- file.path(dir_name, file_name)
skip_on_cran()
create_report(
output = "test-body.html",
title = "Body statistics",
template_name = "body",
params = list(
name = "John Doe",
weight = 80,
height = 180,
sex = "male",
age = 30,
waist = 80,
neck = 35,
hip = 50,
desired_bmi = 23,
squat = 75,
bench = 50
),
quiet = TRUE
)
# Expect file to exist
expect_true(file.exists(file_dir))
# Expect file size to be at least 10000 bytes
expect_gte(file.info(file_dir)$size, 100000)
# Expect error when wrong template name.
expect_error(
create_report(
output = "test-body.html",
title = "Body statistics",
template_name = "wrong_template"
)
)
# Remove file
if (file.exists(file_dir)) {
file.remove(file_dir)
}
})
test_that("Test if kcal report is generated", {
file_name <- "test-kcal.html"
file_dir <- file.path(dir_name, file_name)
skip_on_cran()
create_report(
output = "test-kcal.html",
title = "kcal measures",
template_name = "kcal",
params = list(
name = "John Doe",
weight = 80,
height = 180,
sex = "male",
age = 30,
bfp = 15,
objective = 1,
effort = 1.3
),
quiet = TRUE
)
# Expect file to exist
expect_true(file.exists(file_dir))
# Expect file size to be at least 10000 bytes
expect_gte(file.info(file_dir)$size, 100000)
# Remove file
if (file.exists(file_dir)) {
file.remove(file_dir)
}
})
test_that("an error is generated when not all body params are filled", {
skip_on_cran()
# Expect error when not all params are filled.
expect_error(
create_report(
output = "test-body.html",
title = "Body statistics",
template_name = "body",
params = list(
name = "John Doe",
weight = 80,
height = 180,
sex = "male",
age = 30,
# waist = 80,
neck = 35,
hip = 50,
desired_bmi = 23
),
quiet = TRUE
)
)
})
test_that("an error is generated when not all kcal params are filled", {
skip_on_cran()
# Expect error when not all params are filled.
expect_error(
create_report(
output = "test-body.html",
title = "Body statistics",
template_name = "body",
params = list(
name = "John Doe",
weight = 80,
height = 180,
sex = "male",
age = 30,
bfp = 15,
# objective = 1,
effort = 1.3
),
quiet = TRUE
)
)
})
test_that("see_now works when creating a report", {
file_name <- "test-body.html"
file_dir <- file.path(dir_name, file_name)
skip_on_cran()
expect_invisible(create_report(
output = "test-body.html",
title = "Body statistics",
template_name = "body",
params = list(
name = "John Doe",
weight = 80,
height = 180,
sex = "male",
age = 30,
waist = 80,
neck = 35,
hip = 50,
desired_bmi = 23,
squat = 75,
bench = 50
),
quiet = TRUE,
see_now = TRUE
))
# Remove file
if (file.exists(file_dir)) {
file.remove(file_dir)
}
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.