tests/testthat/test_new_categorical_legend.R

context("new_categorical_legend")

test_that("initialization", {
  # create object
  x <- new_categorical_legend(c(0, 1, 2), c("#000000", "#444444", "#AAAAAA"))
  # run tests
  expect_equal(x$values, c(0, 1, 2))
  expect_equal(x$colors, c("#000000", "#444444", "#AAAAAA"))
})

test_that("export method", {
  # create object
  x <- new_categorical_legend(c(0, 1, 2), c("#000000", "#444444", "#AAAAAA"))
  # run tests
  expect_equal(
    x$export(),
    list(
      type = "categorical",
      colors = c("#000000", "#444444", "#AAAAAA")
    )
  )
})

test_that("widget method", {
  # create object
  x <- new_categorical_legend(c(0, 1, 2), c("#000000", "#444444", "#AAAAAA"))
  # run tests
  expect_equal(
    x$get_widget_data(),
    list(
      values = x$values,
      colors = x$colors,
      type = "CategoricalLegend"
    )
  )
})
NCC-CNC/wheretowork documentation built on Feb. 27, 2025, 6:11 p.m.