😎 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.

127 lines
3.9KB

  1. test_that("read theme settings from css variables", {
  2. expected_vars <- list(
  3. background_color = "#E9EBEE",
  4. text_color = "#18273F",
  5. header_color = "#23395b",
  6. text_bold_color = "#23395b",
  7. inverse_background_color = "#23395b",
  8. inverse_text_color = "#E9EBEE",
  9. inverse_header_color = "#E9EBEE",
  10. base_font_size = "20px",
  11. text_font_size = "1rem",
  12. header_h3_font_size = "1.75rem",
  13. text_font_family = "'Noto Serif'",
  14. text_font_is_google = TRUE,
  15. header_font_family = "Cabin",
  16. header_font_is_google = TRUE,
  17. header_background_color = "#23395b",
  18. header_background_text_color = "#E9EBEE",
  19. code_font_family = "'Source Code Pro'",
  20. code_font_is_google = TRUE
  21. )
  22. css_vars <- read_css_vars(testthat::test_path("css/mono_light.css"))
  23. for (var in names(expected_vars)) {
  24. expect_equal(!!css_vars[[var]], !!expected_vars[[var]])
  25. }
  26. })
  27. describe("find and choose xaringan themer files", {
  28. tmpdir <- tempfile()
  29. dir.create(tmpdir)
  30. mono_light_css <- normalizePath(test_path("css/mono_light.css"))
  31. xaringan_css <- normalizePath(test_path("css/xaringan.css"))
  32. owd <- setwd(tmpdir)
  33. on.exit(setwd(owd))
  34. file.copy(mono_light_css, tmpdir)
  35. it("finds xaringan themer files with non-standard names", {
  36. candidates <- find_xaringan_themer_css()
  37. picked <- choose_xaringan_themer_css(candidates)
  38. expect_equal(candidates, "./mono_light.css")
  39. expect_equal(picked, "./mono_light.css")
  40. })
  41. it("finds xaringan themer files in presence of other .css files", {
  42. writeLines(c(
  43. "html {",
  44. " color: red;",
  45. "}"
  46. ), "styles.css")
  47. expect_equal(find_xaringan_themer_css(), "./mono_light.css")
  48. expect_equal(read_css_vars()$text_color, "#18273F")
  49. })
  50. it("finds all xaringan themer files", {
  51. file.copy(xaringan_css, "xaringan-themer.css")
  52. candidates <- find_xaringan_themer_css()
  53. picked <- choose_xaringan_themer_css(candidates)
  54. expect_equal(candidates, c("./mono_light.css", "./xaringan-themer.css"))
  55. expect_equal(picked, "./xaringan-themer.css")
  56. expect_equal(read_css_vars()$text_color, "#000")
  57. })
  58. it("chooses the first from the list if ambiguous", {
  59. file.rename("xaringan-themer.css", "xaringan.css")
  60. candidates <- find_xaringan_themer_css()
  61. expect_message(picked <- choose_xaringan_themer_css(candidates))
  62. expect_equal(candidates, c("./mono_light.css", "./xaringan.css"))
  63. expect_equal(picked, "./mono_light.css")
  64. expect_message(expect_equal(read_css_vars()$text_color, "#18273F"))
  65. })
  66. it("throws error if no xaringan themer css files", {
  67. file.remove("xaringan.css")
  68. file.remove("mono_light.css")
  69. candidates <- find_xaringan_themer_css()
  70. expect_equal(candidates, character())
  71. expect_error(choose_xaringan_themer_css(candidates))
  72. })
  73. })
  74. test_that("css_get_root() returns null if no :root exists", {
  75. tmpfile <- tempfile("style", fileext = ".css")
  76. writeLines(c(
  77. "html {",
  78. " color: red;",
  79. "}"
  80. ), tmpfile)
  81. expect_null(css_get_root(tmpfile))
  82. unlink(tmpfile)
  83. })
  84. describe("css_get_padding()", {
  85. it("processes 1 element padding", {
  86. p <- css_get_padding("1em")
  87. expect_equal(p$top, "1em")
  88. expect_equal(p$right, "1em")
  89. expect_equal(p$bottom, "1em")
  90. expect_equal(p$left, "1em")
  91. })
  92. it("processes 2 element padding", {
  93. p <- css_get_padding("1em 2em")
  94. expect_equal(p$top, "1em")
  95. expect_equal(p$right, "2em")
  96. expect_equal(p$bottom, "1em")
  97. expect_equal(p$left, "2em")
  98. })
  99. it("processes 4 element padding", {
  100. p <- css_get_padding("1em 2em 3em 4em")
  101. expect_equal(p$top, "1em")
  102. expect_equal(p$right, "2em")
  103. expect_equal(p$bottom, "3em")
  104. expect_equal(p$left, "4em")
  105. })
  106. it("throws an error if padding is a vector", {
  107. expect_error(css_get_padding(c("1em", "2em")))
  108. })
  109. it("throws an error if result is not 1, 2, 4 element", {
  110. expect_error(css_get_padding("1em 2em 3em"))
  111. expect_error(css_get_padding("1em 2em 3em 4em 5em"))
  112. })
  113. })