library(dplyr)
library(tibble)
# tools ---------------------------------------
load_demo_trials <- function(type, fn = NULL) {
if (is.null(fn)) fn <- demo_file(paste0("jspsych-", type, ".json"))
jspsychread::read_jspsych(fn) %>% dplyr::filter(trial_type == type)
}
# tests ---------------------------------------
test_that("Parsers run", {
expect_equal(load_demo_trials("html-keyboard-response") %>% nrow(), 3)
expect_equal(load_demo_trials("animation") %>% nrow(), 1)
expect_equal(load_demo_trials("audio-button-response") %>% nrow(), 3)
expect_equal(load_demo_trials("audio-keyboard-response") %>% nrow(), 4)
expect_equal(load_demo_trials("audio-slider-response") %>% nrow(), 3)
# expect_equal(load_demo_trials("browser-check"))
expect_equal(load_demo_trials("call-function") %>% nrow(), 2)
expect_equal(load_demo_trials("canvas-button-response") %>% nrow(), 6)
expect_equal(load_demo_trials("canvas-keyboard-response") %>% nrow(), 5)
expect_equal(load_demo_trials("canvas-slider-response") %>% nrow(), 2)
expect_equal(load_demo_trials("categorize-animation") %>% nrow(), 1)
expect_equal(load_demo_trials("categorize-html") %>% nrow(), 1)
expect_equal(load_demo_trials("categorize-image") %>% nrow(), 1)
expect_equal(load_demo_trials("cloze") %>% nrow(), 2)
expect_equal(load_demo_trials("external-html") %>% nrow(), 1)
expect_equal(load_demo_trials("free-sort") %>% nrow(), 4)
expect_equal(load_demo_trials("fullscreen") %>% nrow(), 2)
# expect_equal(load_demo_trials("html-audio-response"))
expect_equal(load_demo_trials("html-button-response") %>% nrow(), 3)
expect_equal(load_demo_trials("html-keyboard-response") %>% nrow(), 3)
expect_equal(load_demo_trials("html-slider-response") %>% nrow(), 3)
# expect_equal(load_demo_trials("iat-html"))
# expect_equal(load_demo_trials("iat-image"))
expect_equal(load_demo_trials("image-button-response") %>% nrow(), 8)
expect_equal(load_demo_trials("image-keyboard-response") %>% nrow(), 16)
expect_equal(load_demo_trials("image-slider-response") %>% nrow(), 7)
# expect_equal(load_demo_trials("initialize-microphone"))
expect_equal(load_demo_trials("instructions") %>% nrow(), 2)
expect_equal(load_demo_trials("maxdiff") %>% nrow(), 2)
expect_equal(load_demo_trials("preload") %>% nrow(), 3)
expect_equal(load_demo_trials("reconstruction") %>% nrow(), 1)
expect_equal(load_demo_trials("resize") %>% nrow(), 1)
expect_equal(load_demo_trials("same-different-html") %>% nrow(), 1)
expect_equal(load_demo_trials("same-different-image") %>% nrow(), 1)
expect_equal(load_demo_trials("serial-reaction-time") %>% nrow(), 40)
expect_equal(load_demo_trials("serial-reaction-time-mouse") %>% nrow(), 12)
# expect_equal(load_demo_trials("sketchpad"))
expect_equal(load_demo_trials("survey-html-form") %>% nrow(), 2)
expect_equal(load_demo_trials("survey-likert") %>% nrow(), 2)
expect_equal(load_demo_trials("survey-multi-choice") %>% nrow(), 2)
expect_equal(load_demo_trials("survey-multi-select") %>% nrow(), 1)
expect_equal(load_demo_trials("survey-text") %>% nrow(), 2)
expect_equal(load_demo_trials("video-button-response") %>% nrow(), 2)
expect_equal(load_demo_trials("video-keyboard-response") %>% nrow(), 2)
expect_equal(load_demo_trials("video-slider-response") %>% nrow(), 2)
# expect_equal(load_demo_trials("virtual-chinrest"))
expect_equal(load_demo_trials("visual-search-circle") %>% nrow(), 4)
# expect_equal(load_demo_trials("webgazer-calibrate"))
# expect_equal(load_demo_trials("webgazer-init-camera"))
# expect_equal(load_demo_trials("webgazer-validate"))
})
check_detection <- function(type, fn = NULL) {
if (is.null(fn)) fn <- demo_file(paste0("jspsych-", type, ".json"))
trials <- jspsychread::read_jspsych(fn) %>% dplyr::filter(trial_type == type)
d_auto <- trials %>% jspsychread::process_records()
d_manual <- trials %>% jspsychread::process_records(.using = default_parsers()[[type]])
expect_equal(d_auto, d_manual)
}
test_that("Parsers reach same values with autodetection", {
check_detection("animation")
check_detection("audio-button-response")
check_detection("audio-keyboard-response")
check_detection("audio-slider-response")
check_detection("call-function")
check_detection("canvas-button-response")
check_detection("canvas-keyboard-response")
check_detection("canvas-slider-response")
check_detection("categorize-animation")
check_detection("categorize-html")
check_detection("categorize-image")
check_detection("cloze")
check_detection("external-html")
check_detection("free-sort")
check_detection("fullscreen")
check_detection("html-button-response")
check_detection("html-keyboard-response")
check_detection("html-slider-response")
check_detection("image-button-response")
check_detection("image-keyboard-response")
check_detection("image-slider-response")
check_detection("instructions")
check_detection("maxdiff")
check_detection("preload")
check_detection("reconstruction")
check_detection("resize")
check_detection("same-different-html")
check_detection("same-different-image")
check_detection("serial-reaction-time")
check_detection("serial-reaction-time-mouse")
check_detection("survey-html-form")
check_detection("survey-likert")
check_detection("survey-multi-choice")
check_detection("survey-multi-select")
check_detection("survey-text")
check_detection("video-button-response")
check_detection("video-keyboard-response")
check_detection("video-slider-response")
check_detection("visual-search-circle")
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.