😎 Give your xaringan slides some style
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

176 líneas
5.3KB

  1. # test_that()
  2. describe("theme_xaringan()", {
  3. it("errors if no css file or style_xaringan theme called", {
  4. expect_error(
  5. with_clean_session(function() {
  6. xaringanthemer::theme_xaringan()
  7. })
  8. )
  9. })
  10. it("returns a theme using the style_xaringan colors", {
  11. theme <- with_clean_session(function() {
  12. xaringanthemer::style_xaringan(
  13. text_color = "#000001",
  14. background_color = "#000002",
  15. header_color = "#000003",
  16. text_bold_color = "#000004",
  17. text_font_family = "Damogran",
  18. text_font_google = NULL,
  19. header_font_family = "Magrathea",
  20. header_font_google = NULL
  21. )
  22. xaringanthemer::theme_xaringan(
  23. text_font_use_google = FALSE,
  24. title_font_use_google = FALSE
  25. )
  26. })
  27. expect_equal(theme$text$family, "Damogran")
  28. expect_equal(theme$title$family, "Magrathea")
  29. expect_equal(theme$title$colour, "#000003")
  30. expect_equal(theme$plot.background$colour, "#000002")
  31. expect_equal(theme$plot.background$fill, "#000002")
  32. })
  33. it("returns correct theme reading from a css file", {
  34. css <- xaringanthemer::style_xaringan(
  35. text_color = "#000001",
  36. background_color = "#000002",
  37. header_color = "#000003",
  38. text_bold_color = "#000004",
  39. text_font_family = "Damogran",
  40. text_font_google = NULL,
  41. header_font_family = "Magrathea",
  42. header_font_google = NULL,
  43. outfile = NULL
  44. )
  45. theme <- with_clean_session(function(css) {
  46. writeLines(css, "xaringan-themer.css")
  47. xaringanthemer::theme_xaringan(
  48. text_font_use_google = FALSE,
  49. title_font_use_google = FALSE
  50. )
  51. }, list(css = css))
  52. expect_equal(theme$text$family, "Damogran")
  53. expect_equal(theme$title$family, "Magrathea")
  54. expect_equal(theme$title$colour, "#000003")
  55. expect_equal(theme$plot.background$colour, "#000002")
  56. expect_equal(theme$plot.background$fill, "#000002")
  57. })
  58. it("works with 3-digit hex colors", {
  59. theme <- with_clean_session(function() {
  60. xaringanthemer::style_xaringan(
  61. text_color = "#001",
  62. background_color = "#002",
  63. header_color = "#003",
  64. text_bold_color = "#004"
  65. )
  66. xaringanthemer::theme_xaringan(
  67. text_font_use_google = FALSE,
  68. title_font_use_google = FALSE
  69. )
  70. })
  71. expect_equal(theme$title$colour, "#000033")
  72. expect_equal(theme$plot.background$colour, "#000022")
  73. expect_equal(theme$plot.background$fill, "#000022")
  74. })
  75. })
  76. describe("theme_xaringan_inverse()", {
  77. it("errors if no css file or style_xaringan theme called", {
  78. expect_error(
  79. with_clean_session(function() {
  80. xaringanthemer::theme_xaringan_inverse()
  81. })
  82. )
  83. })
  84. it("returns a theme using the style_xaringan colors", {
  85. theme <- with_clean_session(function() {
  86. xaringanthemer::style_xaringan(
  87. text_color = "#000001",
  88. inverse_text_color = "#100000",
  89. background_color = "#000002",
  90. inverse_background_color = "#200000",
  91. header_color = "#000003",
  92. inverse_header_color = "#300000",
  93. text_bold_color = "#000004",
  94. text_font_family = "Damogran",
  95. text_font_google = NULL,
  96. header_font_family = "Magrathea",
  97. header_font_google = NULL
  98. )
  99. xaringanthemer::theme_xaringan_inverse(
  100. text_font_use_google = FALSE,
  101. title_font_use_google = FALSE
  102. )
  103. })
  104. expect_equal(theme$text$family, "Damogran")
  105. expect_equal(theme$title$family, "Magrathea")
  106. expect_equal(theme$title$colour, "#300000")
  107. expect_equal(theme$plot.background$colour, "#200000")
  108. expect_equal(theme$plot.background$fill, "#200000")
  109. })
  110. it("returns correct colors pulling from css file", {
  111. css <- xaringanthemer::style_xaringan(
  112. text_color = "#000001",
  113. inverse_text_color = "#100000",
  114. background_color = "#000002",
  115. inverse_background_color = "#200000",
  116. header_color = "#000003",
  117. inverse_header_color = "#300000",
  118. text_bold_color = "#000004",
  119. text_font_family = "Damogran",
  120. text_font_google = NULL,
  121. header_font_family = "Magrathea",
  122. header_font_google = NULL,
  123. outfile = NULL
  124. )
  125. theme <- with_clean_session(function(css) {
  126. writeLines(css, "basic.css")
  127. xaringanthemer::theme_xaringan_inverse(
  128. text_font_use_google = FALSE,
  129. title_font_use_google = FALSE
  130. )
  131. }, list(css = css))
  132. expect_equal(theme$text$family, "Damogran")
  133. expect_equal(theme$title$family, "Magrathea")
  134. expect_equal(theme$title$colour, "#300000")
  135. expect_equal(theme$plot.background$colour, "#200000")
  136. expect_equal(theme$plot.background$fill, "#200000")
  137. })
  138. it("works with 3-digit hex colors", {
  139. theme <- with_clean_session(function() {
  140. xaringanthemer::style_xaringan(
  141. text_color = "#001",
  142. background_color = "#002",
  143. header_color = "#003",
  144. inverse_text_color = "#100",
  145. inverse_background_color = "#200",
  146. inverse_header_color = "#300",
  147. text_bold_color = "#004"
  148. )
  149. xaringanthemer::theme_xaringan_inverse(
  150. text_font_use_google = FALSE,
  151. title_font_use_google = FALSE
  152. )
  153. })
  154. expect_equal(theme$title$colour, "#330000")
  155. expect_equal(theme$plot.background$colour, "#220000")
  156. expect_equal(theme$plot.background$fill, "#220000")
  157. })
  158. })