test_that("plot helper returns ggplot", { p <- vb_plot(iris, "Sepal.Length", type = "histogram") expect_s3_class(p, "ggplot") }) test_that("dashboard returns html tags", { d <- vb_dashboard(iris) expect_true(inherits(d, "shiny.tag.list") || inherits(d, "shiny.tag")) }) test_that("vb_plot creates all supported plot types", { dat <- data.frame( group = factor(c("A", "B", "A", "B")), x = c(1, 2, 3, 4), y = c(2, 4, 3, 5) ) p_bar <- vb_plot(dat, "group", type = "bar") expect_s3_class(p_bar, "ggplot") p_hist <- vb_plot(dat, "x", type = "histogram") expect_s3_class(p_hist, "ggplot") p_density <- vb_plot(dat, "x", type = "density") expect_s3_class(p_density, "ggplot") p_scatter <- vb_plot(dat, "x", "y", type = "scatter") expect_s3_class(p_scatter, "ggplot") p_line <- vb_plot(dat, "x", "y", type = "line") expect_s3_class(p_line, "ggplot") p_box <- vb_plot(dat, "group", "y", type = "boxplot") expect_s3_class(p_box, "ggplot") }) test_that("vb_plot validates x and y variables", { dat <- data.frame( x = 1:4, y = 5:8 ) expect_error( vb_plot(dat, "missing", type = "bar"), "`x` must name a column in `data`." ) expect_error( vb_plot(dat, "x", y = "missing", type = "scatter"), "`y` must name a column in `data`." ) expect_error( vb_plot(dat, "x", type = "scatter"), "requires `y`" ) expect_error( vb_plot(dat, "x", type = "line"), "requires `y`" ) expect_error( vb_plot(dat, "x", type = "boxplot"), "requires `y`" ) }) test_that("vb_plot rejects invalid plot types", { dat <- data.frame(x = 1:4) expect_error( vb_plot(dat, "x", type = "invalid"), "arg.*should be one of" ) }) test_that("autoviz creates an autoviz object", { dat <- data.frame( group = factor(c("A", "B", "A", "B")), x = c(1, 2, 3, 4), y = c(2, 4, 3, 5) ) result <- autoviz(dat) expect_s3_class(result, "autoviz") expect_equal(result$data, dat) expect_true(is.data.frame(result$profile)) expect_true(is.data.frame(result$summary)) expect_true(is.data.frame(result$missing)) expect_true(is.data.frame(result$outliers)) expect_true(is.data.frame(result$recommendations)) }) test_that("autoviz respects max_plots", { dat <- data.frame( a = 1:5, b = 6:10, c = 11:15, d = 16:20 ) result <- autoviz(dat, max_plots = 2) expect_s3_class(result, "autoviz") expect_lte(nrow(result$recommendations), 2) }) test_that("autoviz validates max_plots", { dat <- data.frame(x = 1:4) expect_error( autoviz(dat, max_plots = 0), "`max_plots` must be a positive number." ) expect_error( autoviz(dat, max_plots = -1), "`max_plots` must be a positive number." ) expect_error( autoviz(dat, max_plots = "two"), "`max_plots` must be a positive number." ) }) test_that("print.autoviz prints a summary", { dat <- data.frame( group = factor(c("A", "B", "A", "B")), x = c(1, 2, 3, 4) ) obj <- autoviz(dat) output <- capture.output(print(obj)) expect_true(any(grepl("", output))) expect_true(any(grepl("Rows:", output))) expect_true(any(grepl("Columns:", output))) expect_true(any(grepl("Recommended visualizations:", output))) expect_identical(print(obj), obj) }) test_that("dashboard renders recommendations table", { dat <- data.frame( group = factor(c("A", "B", "A", "B")), x = c(1, 2, 3, 4), y = c(2, 4, 3, 5) ) d <- vb_dashboard(dat) expect_true(inherits(d, "shiny.tag.list") || inherits(d, "shiny.tag")) html <- as.character(d) expect_match(html, "Visualization recommendations") expect_match(html, "Dataset profile") expect_match(html, "Missing values") expect_match(html, "Categorical frequency") }) test_that("dashboard renders missing-value table", { dat <- data.frame( group = factor(c("A", "B", NA, "A")), x = c(1, NA, 3, 4), y = c(2, 4, NA, 5) ) d <- vb_dashboard(dat) expect_true(inherits(d, "shiny.tag.list") || inherits(d, "shiny.tag")) html <- as.character(d) expect_match(html, "Missing values") expect_match(html, "Missing %") expect_match(html, "group") expect_match(html, "x") expect_match(html, "y") }) test_that("dashboard uses custom title", { dat <- data.frame( x = 1:4, y = 5:8 ) d <- vb_dashboard( dat, title = "My Custom Dashboard" ) html <- as.character(d) expect_match(html, "My Custom Dashboard") expect_match(html, "AutoViz 1.0.0") }) test_that("dashboard handles data with no missing values", { dat <- data.frame( x = 1:4, y = 5:8 ) d <- vb_dashboard(dat) html <- as.character(d) expect_match(html, "No missing values detected.") })