tests/testthat/test-stimulus-modifiers.R

test_that("ss_control() work", {

  # Vanilla
  tag <- ss_control("demo", div())
  expect_true(tag_has_attribute(tag, "data-controller"))
  expect_equal(tag_get_attribute(tag, "data-controller"), "demo")
  expect_string(as.character(tag), "demo")

  # With Value
  tag <- ss_control("demo", div(), values = list(hello = 1L))
  expect_equal(tag_get_attribute(tag, "data-demo-hello-value"), "1")

  # With Class
  tag <- ss_control("demo", div(), classes = list(whoosh = "class"))
  expect_equal(tag_get_attribute(tag, "data-demo-whoosh-class"), "class")

})

test_that("ss_target() work", {

  tag <- ss_control("demo", div(ss_target("demo", input())))
  expect_true(tag_has_attribute(tag$children[[1]], "data-demo-target"))
  expect_equal(tag_get_attribute(tag$children[[1]], "data-demo-target"), "demo")
  expect_string(as.character(tag), 'data-demo-target="demo"')

})

test_that("ss_action() work", {

  tag <- ss_control("demo", div(ss_action("click", "action", button())))
  expect_equal(tag_get_attribute(tag$children[[1]], "data-action"),
               "click->demo#action")


})
tjpalanca/hotwire.R documentation built on Dec. 23, 2021, 10:59 a.m.