Skip to content

Commit

Permalink
Merge pull request #9 from openjusticeok/testthat
Browse files Browse the repository at this point in the history
testthat
  • Loading branch information
andrewjbe authored Nov 12, 2024
2 parents 3d7cdd1 + 204aa27 commit 5a855fe
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 13 deletions.
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ Imports:
sysfonts,
tidyselect
Suggests:
ggrepel,
testthat (>= 3.0.0)
ggrepel,
testthat (>= 3.0.0),
tibble,
vdiffr
Config/testthat/edition: 3
URL: https://openjusticeok.github.io/ojothemes/
2 changes: 1 addition & 1 deletion R/geoms.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ GeomColOJO <- ggplot2::ggproto(

draw_panel = function(self, data, panel_params, coord, width = NULL) {
# Hack to ensure that width is detected as a parameter
ggplot2::ggproto_parent(GeomRect, self)$draw_panel(data, panel_params, coord)
ggplot2::ggproto_parent(ggplot2::GeomRect, self)$draw_panel(data, panel_params, coord)
}
)

Expand Down
10 changes: 5 additions & 5 deletions R/theme_ojo.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ theme_ojo_base <- function(base_size = 16,

ggplot2::theme(
line = ggplot2::element_line(colour = "#000000",
size = base_line_size,
linewidth = base_line_size,
linetype = 1L,
lineend = "butt"),
rect = ggplot2::element_rect(fill = "#FFFFFF",
colour = "#000000",
size = base_rect_size,
linewidth = base_rect_size,
linetype = 1L),
text = ggplot2::element_text(family = base_family,
face = "plain",
Expand Down Expand Up @@ -85,14 +85,14 @@ theme_ojo_base <- function(base_size = 16,
axis.ticks = ggplot2::element_line(),
axis.ticks.length = ggplot2::unit(4L, "pt"),
axis.ticks.x = ggplot2::element_line(colour = NULL,
size = NULL,
linewidth = NULL,
linetype = NULL,
lineend = NULL),
axis.ticks.y = ggplot2::element_blank(),

axis.line = ggplot2::element_line(),
axis.line.x = ggplot2::element_line(colour = NULL,
size = NULL,
linewidth = NULL,
linetype = NULL,
lineend = NULL),
axis.line.y = ggplot2::element_blank(),
Expand Down Expand Up @@ -142,7 +142,7 @@ theme_ojo_base <- function(base_size = 16,
# strip attributes (Faceting)
strip.background = ggplot2::element_rect(fill = "#dedddd",
colour = NA,
size = 10L),
linewidth = 10L),
strip.text = ggplot2::element_text(face = "bold",
size = base_size * 9.5 / 8.5,
margin = ggplot2::margin(t = 0L, r = 0L, b = 0L, l = 0L)),
Expand Down
4 changes: 2 additions & 2 deletions R/theme_okpi.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ theme_okpi_base <- function(base_size = 16,

ggplot2::theme(
line = ggplot2::element_line(colour = "#333333",
size = base_line_size,
linewidth = base_line_size,
linetype = 1L,
lineend = "butt"),
rect = ggplot2::element_rect(fill = "#ffffff",
colour = NA,
size = base_rect_size,
linewidth = base_rect_size,
linetype = 1L),
text = ggplot2::element_text(family = base_family,
face = "plain",
Expand Down
14 changes: 11 additions & 3 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# library(testthat)
# library(ojothemes)
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# test_check("ojothemes")
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(ojothemes)

test_check("ojothemes")
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions tests/testthat/_snaps/theme_okpi/demo-theme-okpi.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions tests/testthat/test-ojo_gt.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
test_that("gt_okpi style is consistent", {
data <- tibble::tibble(
county = c("Tulsa", "Oklahoma"),
variable1 = c(95, 85),
variable2 = c(4.25, 3.12),
variable3 = c("factor1", "factor2")
)

vdiffr::expect_doppelganger("demo-ojo_gt", {
gt_okpi(
data,
title = "A demo table",
subtitle = "Towards beauty in our tables",
analyst_name = "Brancen Gregory",
source = ojo_source_text("oscn")
)
})
})
18 changes: 18 additions & 0 deletions tests/testthat/test-theme_okpi.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
test_that("theme_okpi is stable", {
data <- tibble::tibble(
county = c("Tulsa", "Oklahoma"),
variable1 = c(95, 85),
variable2 = c(4.25, 3.12),
variable3 = c("factor1", "factor2")
)

vdiffr::expect_doppelganger("demo-theme_okpi", {
ojo_set_theme()

ggplot2::ggplot(
data,
ggplot2::aes(x = variable1, y = variable2, group = variable3)
) +
geom_col()
})
})

0 comments on commit 5a855fe

Please sign in to comment.