tests/testthat/test-plot-scatter.R

test_that("scetter plot block constructor", {

  blk <- new_scatter_block()

  expect_s3_class(blk, "scatter_block")

  testServer(
    block_expr_server(blk),
    {
      expect_identical(x_col(), character())
      expect_identical(y_col(), character())

      expect_identical(cols(), colnames(iris))

      expect_identical(session$returned$state$x(), character())
      expect_identical(session$returned$state$y(), character())

      session$setInputs(xcol = "Sepal.Length", ycol = "Sepal.Width")

      expect_identical(x_col(), "Sepal.Length")
      expect_identical(y_col(), "Sepal.Width")

      expect_identical(session$returned$state$x(), "Sepal.Length")
      expect_identical(session$returned$state$y(), "Sepal.Width")
    },
    args = list(data = function() iris)
  )

  testServer(
    get_s3_method("block_server", blk),
    {
      expr <- session$makeScope("expr")
      expr$setInputs(xcol = "Sepal.Length", ycol = "Sepal.Width")
      session$flushReact()

      expect_s3_class(
        attr(session$returned$result(), "plot"),
        "recordedplot"
      )
    },
    args = list(x = blk, data = list(data = function() iris))
  )
})

Try the blockr.core package in your browser

Any scripts or data that you put into this service are public.

blockr.core documentation built on June 8, 2025, 1:43 p.m.