Skip to content

Commit 91dc0e7

Browse files
committed
update "group" tests in "markers" and "lines" modes
1 parent e49b2b0 commit 91dc0e7

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

tests/testthat/test-plotly.R

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,26 @@ test_that("plot_ly() handles a simple scatterplot", {
1717
expect_identical(l$layout$yaxis$title, "Petal.Length")
1818
})
1919

20-
test_that("Using group argument creates multiple traces", {
21-
skip("FIXME disabled since group doesn't create new traces now")
22-
p <- plot_ly(data = iris, x = Sepal.Length, y = Petal.Length, group = Species)
23-
l <- expect_traces(p, 3, "scatterplot-group")
20+
test_that("Using group argument doesn't transform the data in markers mode", {
21+
p <- plot_ly(data = iris, x = Sepal.Length, y = Petal.Length, group = Species, mode = "markers")
22+
l <- expect_traces(p, 1, "scatterplot-group-markers")
2423
expect_identical(l$layout$xaxis$title, "Sepal.Length")
2524
expect_identical(l$layout$yaxis$title, "Petal.Length")
25+
expect_identical(l$data[[1]]$group, iris$Species)
26+
})
27+
28+
test_that("Using group argument for scatter plot in lines mode introduces breaks (NA values separating different groups)", {
29+
p <- plot_ly(data = iris, x = Sepal.Length, y = Petal.Length, group = Species, mode = "lines")
30+
l <- expect_traces(p, 1, "scatterplot-group")
31+
expect_identical(l$layout$xaxis$title, "Sepal.Length")
32+
expect_identical(l$layout$yaxis$title, "Petal.Length")
33+
n_groups <- length(unique(iris$Species))
34+
n_pts <- length(l$data[[1]]$x)
35+
expect_identical(n_pts, nrow(iris)+n_groups-1L)
36+
expect_identical(sum(is.na(l$data[[1]]$x)), n_groups-1L)
37+
expect_true(all(is.na(l$data[[1]]$group[-1]) |
38+
is.na(l$data[[1]]$group[-n_pts]) |
39+
(l$data[[1]]$group[-1] == l$data[[1]]$group[-n_pts])))
2640
})
2741

2842
test_that("Mapping a variable to symbol works", {

0 commit comments

Comments
 (0)