😎 Give your xaringan slides some style
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

93 lines
2.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. text_font_size = "20px",
  11. header_h3_font_size = "35px",
  12. text_font_family = "'Noto Serif'",
  13. text_font_is_google = TRUE,
  14. header_font_family = "'Yanone Kaffeesatz'",
  15. header_font_is_google = FALSE,
  16. code_font_family = "'Source Code Pro'",
  17. code_font_is_google = FALSE
  18. )
  19. css_vars <- read_css_vars(testthat::test_path("css/mono_light.css"))
  20. for (var in names(expected_vars)) {
  21. expect_equal(!!css_vars[[var]], !!expected_vars[[var]])
  22. }
  23. })
  24. describe("find and choose xaringan themer files", {
  25. tmpdir <- tempfile()
  26. dir.create(tmpdir)
  27. mono_light_css <- normalizePath(test_path("css/mono_light.css"))
  28. xaringan_css <- normalizePath(test_path("css/xaringan.css"))
  29. owd <- setwd(tmpdir)
  30. on.exit(setwd(owd))
  31. file.copy(mono_light_css, tmpdir)
  32. it("finds xaringan themer files with non-standard names", {
  33. candidates <- find_xaringan_themer_css()
  34. picked <- choose_xaringan_themer_css(candidates)
  35. expect_equal(candidates, "./mono_light.css")
  36. expect_equal(picked, "./mono_light.css")
  37. })
  38. it("finds xaringan themer files in presence of other .css files", {
  39. writeLines(c(
  40. "html {",
  41. " color: red;",
  42. "}"
  43. ), "styles.css")
  44. expect_equal(find_xaringan_themer_css(), "./mono_light.css")
  45. expect_equal(read_css_vars()$text_color, "#18273F")
  46. })
  47. it("finds all xaringan themer files", {
  48. file.copy(xaringan_css, "xaringan-themer.css")
  49. candidates <- find_xaringan_themer_css()
  50. picked <- choose_xaringan_themer_css(candidates)
  51. expect_equal(candidates, c("./mono_light.css", "./xaringan-themer.css"))
  52. expect_equal(picked, "./xaringan-themer.css")
  53. expect_equal(read_css_vars()$text_color, "#000")
  54. })
  55. it("chooses the first from the list if ambiguous", {
  56. file.rename("xaringan-themer.css", "xaringan.css")
  57. candidates <- find_xaringan_themer_css()
  58. picked <- expect_message(choose_xaringan_themer_css(candidates))
  59. expect_equal(candidates, c("./mono_light.css", "./xaringan.css"))
  60. expect_equal(picked, "./mono_light.css")
  61. expect_equal(read_css_vars()$text_color, "#18273F")
  62. })
  63. it("throws error if no xaringan themer css files", {
  64. file.remove("xaringan.css")
  65. file.remove("mono_light.css")
  66. candidates <- find_xaringan_themer_css()
  67. expect_equal(candidates, character())
  68. expect_error(choose_xaringan_themer_css(candidates))
  69. })
  70. })
  71. test_that("css_get_root() returns null if no :root exists", {
  72. tmpfile <- tempfile("style", fileext = ".css")
  73. writeLines(c(
  74. "html {",
  75. " color: red;",
  76. "}"
  77. ), tmpfile)
  78. expect_null(css_get_root(tmpfile))
  79. unlink(tmpfile)
  80. })