diff --git a/tests/testthat/test-theme_grattan.R b/tests/testthat/test-theme_grattan.R index a73723e7..aae6dc6c 100644 --- a/tests/testthat/test-theme_grattan.R +++ b/tests/testthat/test-theme_grattan.R @@ -44,15 +44,28 @@ test_that("grattan colour functions work as expected", { expect_length(grattan_pal(), 5) + expect_length(grattan_pal(n = 1), 1) expect_length(grattan_pal(n = 2), 2) - + expect_length(grattan_pal(n = 3), 3) + expect_length(grattan_pal(n = 4), 4) + expect_length(grattan_pal(n = 5), 5) + expect_length(grattan_pal(n = 6), 6) + expect_length(suppressWarnings(grattan_pal(n = 7)), 7) + expect_length(suppressWarnings(grattan_pal(n = 8)), 8) + expect_length(suppressWarnings(grattan_pal(n = 9)), 9) expect_length(suppressWarnings(grattan_pal(n = 10)), 10) + expect_length(grattan_pal(n = 3, reverse = TRUE), 3) expect_warning(grattan_pal(n = 10)) expect_error(grattan_pal(n = 11)) - plot_w_col <- base_plot + + expect_equal(grattan_pal(n = 5), + c(grattantheme::grattan_yellow, grattantheme::grattan_lightorange, + grattantheme::grattan_darkorange, grattantheme::grattan_red, + grattantheme::grattan_darkred)) + + plot_w_col <- base_plot + geom_point(aes(col = factor(cyl))) + grattan_colour_manual(n = 3) diff --git a/tests/testthat/test-wrap_labs.R b/tests/testthat/test-wrap_labs.R new file mode 100644 index 00000000..2c71aef5 --- /dev/null +++ b/tests/testthat/test-wrap_labs.R @@ -0,0 +1,41 @@ + +base_plot <- ggplot(mtcars, aes(x = mpg, y = wt)) + + geom_point() + +test_that("long title fails", { + p <- base_plot + + labs(title = "This is a really long title that should fail wrap_labs with an error because it flows onto more than two lines, so it should definitely fail blah blah blah") + + expect_error(wrap_labs(p, type = "fullslide")) + + p <- base_plot + + labs(title = "Regular title", + subtitle = "Extremely long subtitle that should fail wrap_labs with an error, it'll take up too many lines even for a monster chart etc etc etc etc lorem ipsum lorem ipsum") + + expect_error(wrap_labs(p, type = "fullslide")) + +}) + + +test_that("two line title wraps", { + + p <- base_plot + + labs(title = "This is a slightly long title that should wrap onto two lines but work blah blah blah") + + p <- wrap_labs(p, type = "fullslide") + + expect_true(grepl("\n", p$labels$title)) + +}) + +test_that("caption wraps onto two lines", { + + p <- base_plot + + labs(caption = "Notes: notes go here. Source: source goes here.") + + p <- wrap_labs(p, type = "fullslide") + + expect_true(grepl("\n", p$labels$caption)) + +}) +