# Test suite for report functions test_that("render_report creates HTML file", { # Create sample data res <- tibble::tibble( location = 1, raw_text = "t(28) = 2.21", test_type = "t", stat_value = 2.21, df1 = 28, status = "PASS", uncertainty_level = "low" ) out_file <- tempfile(fileext = ".html") result <- render_report(res, out_file) expect_true(file.exists(out_file)) expect_true(file.size(out_file) > 0) # Check it's valid HTML content <- readLines(out_file, warn = FALSE) expect_true(any(grepl("", content, ignore.case = TRUE))) unlink(out_file) }) test_that("export_csv creates CSV file", { res <- tibble::tibble( location = 1, test_type = "t", status = "PASS" ) out_file <- tempfile(fileext = ".csv") result <- export_csv(res, out_file) expect_true(file.exists(out_file)) expect_true(file.size(out_file) > 0) # Check it can be read back read_back <- utils::read.csv(out_file) expect_equal(nrow(read_back), 1) unlink(out_file) }) test_that("export_json creates JSON file", { # Skip if jsonlite not available skip_if_not_installed("jsonlite") res <- tibble::tibble( location = 1, test_type = "t", status = "PASS" ) out_file <- tempfile(fileext = ".json") result <- export_json(res, out_file) expect_true(file.exists(out_file)) expect_true(file.size(out_file) > 0) # Check it's valid JSON json_data <- jsonlite::fromJSON(out_file) expect_true("metadata" %in% names(json_data)) expect_true("results" %in% names(json_data)) unlink(out_file) }) test_that("render_report handles empty results", { res <- tibble::tibble() out_file <- tempfile(fileext = ".html") result <- render_report(res, out_file) expect_true(file.exists(out_file)) unlink(out_file) }) test_that("export_csv handles NA values", { res <- tibble::tibble( location = 1, test_type = "t", d_ind = NA_real_, status = "PASS" ) out_file <- tempfile(fileext = ".csv") result <- export_csv(res, out_file, na = "") expect_true(file.exists(out_file)) unlink(out_file) }) # =========================================================================== # generate_report() tests # =========================================================================== test_that("generate_report creates self-contained HTML", { res <- check_text("t(28) = 2.21, p = .035, d = 0.80") out_file <- tempfile(fileext = ".html") result <- generate_report(res, out_file) expect_true(file.exists(out_file)) content <- paste(readLines(out_file, warn = FALSE), collapse = "\n") expect_true(grepl("", content, ignore.case = TRUE)) expect_true(grepl("EffectCheck Report", content)) expect_true(grepl("EffectCheck v", content)) unlink(out_file) }) test_that("generate_report includes executive summary bars", { res <- check_text("t(28) = 2.21, p = .035, d = 0.80") out_file <- tempfile(fileext = ".html") generate_report(res, out_file) content <- paste(readLines(out_file, warn = FALSE), collapse = "\n") expect_true(grepl("exec-summary", content)) expect_true(grepl("bar-pass", content)) expect_true(grepl("bar-ok", content)) expect_true(grepl("bar-note", content)) expect_true(grepl("bar-warn", content)) expect_true(grepl("bar-error", content)) unlink(out_file) }) test_that("generate_report color-codes rows by status", { res <- check_text("t(28) = 2.21, p = .035, d = 0.80") out_file <- tempfile(fileext = ".html") generate_report(res, out_file) content <- paste(readLines(out_file, warn = FALSE), collapse = "\n") expect_true(grepl("row-PASS|row-OK|row-NOTE|row-WARN|row-ERROR", content)) unlink(out_file) }) test_that("generate_report handles empty results", { res <- tibble::tibble() class(res) <- c("tbl_df", "tbl", "data.frame") out_file <- tempfile(fileext = ".html") generate_report(res, out_file) content <- paste(readLines(out_file, warn = FALSE), collapse = "\n") expect_true(grepl("No statistics detected", content)) unlink(out_file) }) test_that("generate_report includes source_name and author", { res <- check_text("t(28) = 2.21, p = .035, d = 0.80") out_file <- tempfile(fileext = ".html") generate_report(res, out_file, source_name = "test_paper.pdf", author = "Test Author") content <- paste(readLines(out_file, warn = FALSE), collapse = "\n") expect_true(grepl("test_paper.pdf", content)) expect_true(grepl("Test Author", content)) unlink(out_file) }) test_that("generate_report includes repro code section", { res <- check_text("t(28) = 2.21, p = .035, d = 0.80") out_file <- tempfile(fileext = ".html") generate_report(res, out_file, include_repro_code = TRUE) content <- paste(readLines(out_file, warn = FALSE), collapse = "\n") expect_true(grepl("Reproducible R Code", content)) unlink(out_file) }) test_that("generate_report omits repro code when disabled", { res <- check_text("t(28) = 2.21, p = .035, d = 0.80") out_file <- tempfile(fileext = ".html") generate_report(res, out_file, include_repro_code = FALSE) content <- paste(readLines(out_file, warn = FALSE), collapse = "\n") expect_false(grepl("Collated Reproducible R Code", content)) unlink(out_file) }) test_that("generate_report with custom title", { res <- check_text("t(28) = 2.21, p = .035, d = 0.80") out_file <- tempfile(fileext = ".html") generate_report(res, out_file, title = "My Custom Report") content <- paste(readLines(out_file, warn = FALSE), collapse = "\n") expect_true(grepl("My Custom Report", content)) unlink(out_file) })