# Comprehensive tests for save_html() function # Testing file creation based on real example usage patterns # ============================================================================== # ggplot2 File Creation Tests # ============================================================================== test_that("save_html() creates HTML file for ggplot2 bar plot", { testthat::skip_if_not_installed("ggplot2") p <- create_test_ggplot_bar() tmp_file <- tempfile(fileext = ".html") result <- save_html(p, file = tmp_file) testthat::expect_true(file.exists(tmp_file)) testthat::expect_equal(result, tmp_file) # Verify content content <- readLines(tmp_file) testthat::expect_true(any(grepl("") unlink(tmp_file) }) test_that("save_html() creates HTML file for ggplot2 histogram", { testthat::skip_if_not_installed("ggplot2") p <- create_test_ggplot_histogram() tmp_file <- tempfile(fileext = ".html") result <- save_html(p, file = tmp_file) testthat::expect_true(file.exists(tmp_file)) unlink(tmp_file) }) test_that("save_html() creates HTML file for ggplot2 boxplot", { testthat::skip_if_not_installed("ggplot2") p <- create_test_ggplot_boxplot() tmp_file <- tempfile(fileext = ".html") result <- save_html(p, file = tmp_file) testthat::expect_true(file.exists(tmp_file)) unlink(tmp_file) }) # ============================================================================== # Base R File Creation Tests # ============================================================================== test_that("save_html() creates HTML file for Base R barplot", { barplot(c(10, 20, 30), names.arg = c("A", "B", "C")) tmp_file <- tempfile(fileext = ".html") result <- save_html(file = tmp_file) testthat::expect_true(file.exists(tmp_file)) testthat::expect_equal(result, tmp_file) # Verify content content <- readLines(tmp_file) testthat::expect_true(any(grepl("", ignore.case = TRUE) testthat::expect_match(html_str, "", ignore.case = TRUE) testthat::expect_match(html_str, "", ignore.case = TRUE) # Check for SVG content testthat::expect_match(html_str, "