test_that("hotwire_demo() initializes", {
demo <- expect_r6(hotwire_demo(), "App")
expect_r6(demo$plugins$turbo, "Turbo")
expect_r6(demo$plugins$stimulus, "Stimulus")
expect_r6(demo$plugins$hotwire, "Hotwire")
later(
function() {
expect_true(demo$lifecycle_is_running())
demo$lifecycle_stop()
},
delay = 3L
)
demo$lifecycle_start(block = TRUE)
})
test_that("hotwire_demo() test request /", {
demo <- hotwire_demo(TestPlugin$new())
res <- demo$test$request("/")
expect_equal(res$status, 200L)
expect_equal(res$headers$`Content-Type`, "text/html")
expect_string(res$body, fixed = "Hotwire for R")
})
test_that("hotwire_demo() test request /turbo_drive", {
demo <- hotwire_demo(TestPlugin$new())
res <- demo$test$request("/turbo_drive")
expect_equal(res$status, 200L)
expect_equal(res$headers$`Content-Type`, "text/html")
expect_string(res$body, fixed = "you navigated to this page with Turbo Drive")
})
test_that("hotwire_demo() test request /swapped_frame", {
demo <- hotwire_demo(TestPlugin$new())
res <- demo$test$request("/swapped_frame")
expect_equal(res$status, 200L)
expect_equal(res$headers$`Content-Type`, "text/html")
expect_string(res$body, fixed = "turbo-frame")
})
test_that("hotwire_demo() test request /slow_drive", {
demo <- hotwire_demo(TestPlugin$new())
res <- demo$test$request("/slow_drive")
expect_equal(res$status, 200L)
expect_equal(res$headers$`Content-Type`, "text/html")
expect_string(res$body, fixed = "deliberately slowed down")
})
test_that("hotwire_demo() test request /slow_drive", {
demo <- hotwire_demo(TestPlugin$new())
res <- demo$test$request("/lazy_loading")
expect_equal(res$status, 200L)
expect_equal(res$headers$`Content-Type`, "text/html")
expect_string(res$body, fixed = "different path")
})
test_that("hotwire_demo() test request /stream/:action", {
demo <- hotwire_demo(TestPlugin$new())
res <- demo$test$request("/stream/replace")
expect_equal(res$status, 200L)
expect_equal(res$headers$`Content-Type`, "text/vnd.turbo-stream.html")
expect_string(res$body, fixed = "turbo-stream")
})
test_that("hotwire_demo() test request /start", {
demo <- hotwire_demo(TestPlugin$new())
res <- demo$test$request("/start", method = "post")
expect_equal(res$status, 303L)
expect_equal(res$headers$`Content-Type`, "text/plain")
expect_string(res$body, fixed = "See Other")
})
test_that("hotwire_demo() websocket turbo stream update", {
demo <- hotwire_demo(TestPlugin$new())
res <- demo$test$request("/multiple/A", method = "post")
expect_equal(res$status, 200L)
expect_equal(res$headers$`Content-Type`, "text/vnd.turbo-stream.html")
expect_string(res$body, fixed = "turbo-stream action")
})
test_that("hotwire_demo() test request currrent time", {
demo <- hotwire_demo(TestPlugin$new())
res <- demo$test$request("/time")
expect_equal(res$status, 200L)
expect_equal(res$headers$`Content-Type`, "text/html")
expect_string(res$body, fixed = as.character(Sys.Date()))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.