tests/testthat/test-report_html.R

test_that("export_report renders a self-contained HTML document", {
  skip_if_not_installed("rmarkdown")
  skip_if_not_installed("knitr")

  # Small end-to-end fixture: rank three records, plan, invent
  # decisions, and render the report.
  records <- data.frame(
    id = paste0("r", 1:6),
    title = paste("Title", 1:6),
    abstract = paste("Abstract", 1:6)
  )
  criteria <- define_criteria("Scope",
                              c("Criterion A.", "Criterion B."))
  ens <- default_ensemble(backend = backend_mock())
  ranked <- rank_records(records, criteria, ensemble = ens, verbose = FALSE)
  plan <- plan_screening(ranked, safe_run_length = 5, spot_check_n = 3)
  decisions <- data.frame(
    id = ranked$id[1:3],
    human_decision = c("Accept", "Accept", "Reject"),
    stringsAsFactors = FALSE
  )

  out <- tempfile(fileext = ".html")
  export_report(
    output_file = out,
    project = "test-project",
    ranked = ranked, plan = plan, decisions = decisions,
    criteria = criteria, ensemble = ens
  )
  expect_true(file.exists(out))
  html <- paste(readLines(out, warn = FALSE), collapse = "\n")
  expect_match(html, "test-project")
  expect_match(html, "SAFE plan|Screening summary")
})

test_that("export_report tolerates missing artefacts", {
  skip_if_not_installed("rmarkdown")
  skip_if_not_installed("knitr")

  out <- tempfile(fileext = ".html")
  # All params NULL should still render (the template writes "(not
  # recorded)" placeholders).
  export_report(output_file = out, project = "minimal")
  expect_true(file.exists(out))
  html <- paste(readLines(out, warn = FALSE), collapse = "\n")
  expect_match(html, "minimal")
})

Try the screenllm package in your browser

Any scripts or data that you put into this service are public.

screenllm documentation built on Sept. 24, 2026, 5:11 p.m.