expect_same_plot <- vdiffr::expect_doppelganger wrap_plots <- patchwork::wrap_plots res <- estimate_risk_partial(quiet = TRUE) color_dat <- data.frame( threshold = c(0.075, 0.2), color = c("forestgreen", "darkblue") ) color_dat_v2 <- rbind( color_dat, # Note threshold being added is between the two existing thresholds, # which also tests that the thresholds are sorted properly data.frame(threshold = 0.12, color = "purple") ) test_that("Error when annotation is not valid, character", { expect_error( plot_risk(res, annotation = "potato"), "`annotation` must be `TRUE` or `FALSE`" ) }) test_that("Error when annotation is not valid, numeric", { expect_error( plot_risk(res, annotation = 1), "`annotation` must be `TRUE` or `FALSE`" ) }) test_that("Error when annotation is not valid, data.frame", { expect_error( plot_risk(res, annotation = data.frame(a = 1, b = "o")), "`annotation` must be `TRUE` or `FALSE`" ) }) test_that("Error when annotation is not valid, NA", { expect_error( plot_risk(res, annotation = NA), "`annotation` must be `TRUE` or `FALSE`" ) }) test_that("Error when lines is not valid, character", { expect_error( plot_risk( res, color_scheme = "categories", color_dat = color_dat, lines = "potato" ), "`lines` must be `TRUE` or `FALSE`" ) }) test_that("Error when lines is not valid, numeric", { expect_error( plot_risk( res, color_scheme = "categories", color_dat = color_dat, lines = 1 ), "`lines` must be `TRUE` or `FALSE`" ) }) test_that("Error when lines is not valid, data.frame", { expect_error( plot_risk( res, color_scheme = "categories", color_dat = color_dat, lines = data.frame(a = 1, b = "o") ), "`lines` must be `TRUE` or `FALSE`" ) }) test_that("Error when lines is not valid, NA", { expect_error( plot_risk( res, color_scheme = "categories", color_dat = color_dat, lines = NA ), "`lines` must be `TRUE` or `FALSE`" ) }) test_that("Error when line_text is not valid, character", { expect_error( plot_risk( res, color_scheme = "categories", color_dat = color_dat, line_text = "potato" ), "`line_text` must be `TRUE` or `FALSE`" ) }) test_that("Error when line_text is not valid, numeric", { expect_error( plot_risk( res, color_scheme = "categories", color_dat = color_dat, line_text = 1 ), "`line_text` must be `TRUE` or `FALSE`" ) }) test_that("Error when line_text is not valid, data.frame", { expect_error( plot_risk( res, color_scheme = "categories", color_dat = color_dat, line_text = data.frame(a = 1, b = "o") ), "`line_text` must be `TRUE` or `FALSE`" ) }) test_that("Error when line_text is not valid, NA", { expect_error( plot_risk( res, color_scheme = "categories", color_dat = color_dat, line_text = NA ), "`line_text` must be `TRUE` or `FALSE`" ) }) test_that("Error when legend is not valid, character", { expect_error( plot_risk( res, color_scheme = "categories", color_dat = color_dat, legend = "potato" ), "`legend` must be `TRUE` or `FALSE`" ) }) test_that("Error when legend is not valid, numeric", { expect_error( plot_risk( res, color_scheme = "categories", color_dat = color_dat, legend = 1 ), "`legend` must be `TRUE` or `FALSE`" ) }) test_that("Error when legend is not valid, data.frame", { expect_error( plot_risk( res, color_scheme = "categories", color_dat = color_dat, legend = data.frame(a = 1, b = "o") ), "`legend` must be `TRUE` or `FALSE`" ) }) test_that("Error when legend is not valid, NA", { expect_error( plot_risk( res, color_scheme = "categories", color_dat = color_dat, legend = NA ), "`legend` must be `TRUE` or `FALSE`" ) }) test_that("Error when color_dat is invalid, color_scheme is single", { expect_snapshot( error = TRUE, plot_risk(res, color_scheme = "single", color_dat = color_dat), ) }) test_that("Error when color_dat is invalid, color_scheme is categories", { expect_snapshot( error = TRUE, plot_risk(res, color_scheme = "categories", color_dat = "potato") ) }) test_that("Error when color_dat is invalid, color_scheme is categories, round 2", { expect_snapshot( error = TRUE, plot_risk(res, color_scheme = "categories", color_dat = data.frame(a = 1, b = "o")), ) }) test_that("Error when color_scheme is not valid", { expect_snapshot( error = TRUE, plot_risk(res, color_scheme = "potato"), ) }) test_that("Basic plotting works", { expect_same_plot("10-year results", plot_risk(res$risk_est_10yr)) expect_same_plot("30-year results", plot_risk(res$risk_est_30yr)) }) test_that("Removing annotation works", { expect_same_plot("10-year results, no annotation", plot_risk(res$risk_est_10yr, annotation = FALSE)) expect_same_plot("30-year results, no annotation", plot_risk(res$risk_est_30yr, annotation = FALSE)) }) test_that("Changing single color works", { expect_same_plot( "10-year results, single color", plot_risk(res$risk_est_10yr, color_scheme = "single", color_dat = "forestgreen") ) expect_same_plot( "30-year results, single color", plot_risk(res$risk_est_30yr, color_scheme = "single", color_dat = "purple") ) }) test_that("Color categories works", { expect_same_plot( "Color categories, wrapped plot", wrap_plots( plot_risk(res, color_scheme = "categories", color_dat = color_dat) ) ) }) test_that("Color categories works, min thresholds", { expect_same_plot( "Color categories, wrapped plot, min thresholds", wrap_plots( plot_risk(res, color_scheme = "categories", color_dat = color_dat[1, ]) ) ) }) test_that("Color categories works, max thresholds", { expect_same_plot( "Color categories, wrapped plot, max thresholds", wrap_plots( plot_risk(res, color_scheme = "categories", color_dat = color_dat_v2) ) ) }) test_that("Remove legend ignored, color_scheme is single", { expect_same_plot( "No legend, color scheme single", wrap_plots(plot_risk(res, legend = FALSE)) ) }) test_that("Remove legend, color_scheme categories", { expect_same_plot( "No legend, color scheme categories", wrap_plots( plot_risk( res, color_scheme = "categories", color_dat = color_dat, legend = FALSE ) ) ) }) test_that("Remove line text, color_scheme categories", { expect_same_plot( "No line text, color scheme categories", wrap_plots( plot_risk( res, color_scheme = "categories", color_dat = color_dat, line_text = FALSE ) ) ) }) test_that("Remove lines, color_scheme is categories", { expect_same_plot( "No lines, color scheme categories", wrap_plots( plot_risk( res, color_scheme = "categories", color_dat = color_dat, lines = FALSE ) ) ) }) test_that("Line text argument has no effect if lines is FALSE", { expect_same_plot( "Line text TRUE when lines is FALSE", wrap_plots( plot_risk( res, color_scheme = "categories", color_dat = color_dat, lines = FALSE, line_text = TRUE ) ) ) }) test_that("Removing all adornments from plot works", { expect_same_plot( "No adornments, color scheme is categories", wrap_plots( plot_risk( res, color_scheme = "categories", color_dat = color_dat, annotation = FALSE, lines = FALSE, line_text = FALSE, legend = FALSE ) ) ) }) test_that("Changing color for final group works", { expect_same_plot( "Change final group color, color scheme categories", wrap_plots( plot_risk( res, color_scheme = "categories", color_dat = color_dat, color_for_last_group = "purple" ) ) ) }) test_that("Changing base size works", { expect_same_plot( "Changing base size, color scheme is single", wrap_plots(plot_risk(res, base_size = 18)) ) })