😎 Give your xaringan slides some style
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

92 lines
3.4KB

  1. context("test-themes")
  2. test_theme_file <- function(theme = "duo", theme_file = paste0(theme, ".css"), ...) {
  3. theme_fun <- switch(
  4. theme,
  5. "duo" = style_duo,
  6. "duo_accent" = style_duo_accent,
  7. "duo_accent_inverse" = style_duo_accent_inverse,
  8. "mono_accent" = style_mono_accent,
  9. "mono_accent_inverse" = style_mono_accent_inverse,
  10. "mono_dark" = style_mono_dark,
  11. "mono_light" = style_mono_light,
  12. "solarized_dark" = style_solarized_dark,
  13. "solarized_light" = style_solarized_light,
  14. "xaringan" = style_xaringan,
  15. stop("Unknown theme")
  16. )
  17. tmpfile <- tempfile()
  18. theme_fun(outfile = tmpfile, ..., text_font_google = google_font("Noto Serif"))
  19. theme_css <- readLines(tmpfile)
  20. # Mask package version in test files
  21. theme_css <- sub("( \\* Version: )[\\d.-]+", "\\1a.b.c.d.eeee", theme_css, perl = TRUE)
  22. theme_css <- paste(theme_css, collapse = "\n")
  23. expect_known_output(cat(theme_css), test_path("css", theme_file))
  24. }
  25. test_that("style_duo()", test_theme_file("duo"))
  26. test_that("style_duo_accent()", test_theme_file("duo_accent"))
  27. test_that("style_duo_accent_inverse()", test_theme_file("duo_accent_inverse"))
  28. test_that("style_mono_accent()", test_theme_file("mono_accent"))
  29. test_that("style_mono_accent_inverse()", test_theme_file("mono_accent_inverse"))
  30. test_that("style_mono_dark()", test_theme_file("mono_dark"))
  31. test_that("style_mono_light()", test_theme_file("mono_light"))
  32. test_that("style_solarized_dark()", test_theme_file("solarized_dark"))
  33. test_that("style_solarized_light()", test_theme_file("solarized_light"))
  34. test_that("header_background_auto = TRUE", {
  35. test_theme_file("duo", "duo-header_bg.css", header_background_auto = TRUE)
  36. test_theme_file("mono_light", "mono_light-header_bg.css", header_background_auto = TRUE)
  37. test_theme_file("solarized_dark", "solarized_dark-header_bg.css", header_background_auto = TRUE)
  38. })
  39. test_that("style colors are added to themes", {
  40. test_theme_file("xaringan", colors = c('light-blue' = "#bad4ed"))
  41. })
  42. test_that("setting individual font overrides google font", {
  43. theme_vars <- with_clean_session(function() {
  44. xf <- xaringanthemer::style_xaringan(
  45. text_font_family = "Damogran",
  46. header_font_family = "Magrathea"
  47. )
  48. xaringanthemer:::read_css_vars(xf)
  49. })
  50. expect_equal(theme_vars$text_font_family, "Damogran")
  51. expect_false(theme_vars$text_font_is_google)
  52. expect_equal(theme_vars$header_font_family, "Magrathea")
  53. expect_false(theme_vars$header_font_is_google)
  54. })
  55. test_that("default fonts are correctly identified as google font", {
  56. theme_vars <- with_clean_session(function() {
  57. xf <- xaringanthemer::style_xaringan()
  58. xaringanthemer:::read_css_vars(xf)
  59. })
  60. expect_equal(theme_vars$text_font_family, quote_elements_w_spaces(formals(style_xaringan)$text_font_family))
  61. expect_true(theme_vars$text_font_is_google)
  62. expect_equal(theme_vars$header_font_family, quote_elements_w_spaces(formals(style_xaringan)$header_font_family))
  63. expect_true(theme_vars$header_font_is_google)
  64. })
  65. test_that("NULL output returns CSS as text", {
  66. expect_false(
  67. with_clean_session(function() {
  68. xaringanthemer::style_xaringan(outfile = NULL)
  69. file.exists("xaringan-themer.css")
  70. })
  71. )
  72. xt <- with_clean_session(function() {
  73. xaringanthemer::style_xaringan(outfile = NULL)
  74. })
  75. expect_type(xt, "character")
  76. expect_true(any(grepl("generated by xaringanthemer", xt)))
  77. })