Skip to content

Commit

Permalink
Add test for translate_linebreaks()
Browse files Browse the repository at this point in the history
  • Loading branch information
salim-b committed Apr 23, 2020
1 parent 4cbf87d commit 841e7e9
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/testthat/test-plotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,38 @@ test_that("toWebGL() shouldn't complain if it's already webgl", {
toWebGL()
expect_silent(plotly_build(p))
})

test_that("Line breaks are properly translated (R -> HTML)", {
skip_if_not_installed(pkg = "forcats")

# create target labels
suffix <- "\n\n(third line)\n(fourth line)"

target_labels <- iris$Species %>%
unique() %>%
as.character() %>%
paste0(suffix) %>%
gsub(pattern = "\n",
replacement = br(),
x = .,
fixed = TRUE)

# test factor column
d <- iris %>% dplyr::mutate(Species = forcats::fct_relabel(Species,
paste0,
suffix))
p1 <- d %>% plot_ly(x = ~Sepal.Length,
y = ~Species)

expect_equivalent(plotly_build(p1)[["x"]][["layout"]][["yaxis"]][["categoryarray"]],
target_labels)

# test character column
p2 <- d %>%
dplyr::mutate(Species = as.character(Species)) %>%
plot_ly(x = ~Sepal.Length,
y = ~Species)

expect_equivalent(plotly_build(p2)[["x"]][["layout"]][["yaxis"]][["categoryarray"]],
target_labels)
})

0 comments on commit 841e7e9

Please sign in to comment.