mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
94 lines
3.0 KiB
TypeScript
94 lines
3.0 KiB
TypeScript
import sameDifferentHtml from "@jspsych/plugin-same-different-html";
|
|
import surveyMultiSelect from "@jspsych/plugin-survey-multi-select";
|
|
import surveyText from "@jspsych/plugin-survey-text";
|
|
|
|
import jsPsych from "../../src";
|
|
import { clickTarget, pressKey } from "../utils";
|
|
|
|
jest.useFakeTimers();
|
|
|
|
describe("data conversion to csv", function () {
|
|
test("survey-text data response object is correctly converted", function () {
|
|
var trial = {
|
|
type: surveyText,
|
|
questions: [{ prompt: "Q1" }, { prompt: "Q2" }],
|
|
};
|
|
|
|
var timeline = [trial];
|
|
|
|
jsPsych.init({ timeline });
|
|
|
|
document.querySelector<HTMLInputElement>("#input-0").value = "Response 1";
|
|
document.querySelector<HTMLInputElement>("#input-1").value = "Response 2";
|
|
|
|
clickTarget(document.querySelector("#jspsych-survey-text-next"));
|
|
|
|
var csv_data = jsPsych.data
|
|
.get()
|
|
.ignore(["rt", "internal_node_id", "time_elapsed", "trial_type"])
|
|
.csv();
|
|
expect(csv_data).toBe(
|
|
'"response","trial_index"\r\n"{""Q0"":""Response 1"",""Q1"":""Response 2""}","0"\r\n'
|
|
);
|
|
});
|
|
|
|
test("same-different-html stimulus array is correctly converted", function () {
|
|
var trial = {
|
|
type: sameDifferentHtml,
|
|
stimuli: ["<p>Climbing</p>", "<p>Walking</p>"],
|
|
answer: "different",
|
|
gap_duration: 0,
|
|
first_stim_duration: null,
|
|
};
|
|
|
|
var timeline = [trial];
|
|
|
|
jsPsych.init({ timeline: timeline });
|
|
|
|
expect(jsPsych.getDisplayElement().innerHTML).toMatch("<p>Climbing</p>");
|
|
pressKey("q");
|
|
jest.runAllTimers();
|
|
expect(jsPsych.getDisplayElement().innerHTML).toMatch("<p>Walking</p>");
|
|
pressKey("q");
|
|
expect(jsPsych.getDisplayElement().innerHTML).toBe("");
|
|
|
|
var csv_data = jsPsych.data
|
|
.get()
|
|
.ignore([
|
|
"rt",
|
|
"internal_node_id",
|
|
"time_elapsed",
|
|
"trial_type",
|
|
"rt_stim1",
|
|
"response_stim1",
|
|
])
|
|
.csv();
|
|
expect(csv_data).toBe(
|
|
'"answer","correct","stimulus","response","trial_index"\r\n"different","false","[""<p>Climbing</p>"",""<p>Walking</p>""]","q","0"\r\n'
|
|
);
|
|
});
|
|
|
|
test("survey-multi-select response array is correctly converted", function () {
|
|
var trial = {
|
|
type: surveyMultiSelect,
|
|
questions: [{ prompt: "foo", options: ["fuzz", "bizz", "bar"], name: "q" }],
|
|
};
|
|
|
|
var timeline = [trial];
|
|
|
|
jsPsych.init({ timeline: timeline });
|
|
|
|
expect(jsPsych.getDisplayElement().innerHTML).toMatch("foo");
|
|
clickTarget(document.querySelector("#jspsych-survey-multi-select-response-0-0"));
|
|
clickTarget(document.querySelector("#jspsych-survey-multi-select-response-0-1"));
|
|
clickTarget(document.querySelector("#jspsych-survey-multi-select-next"));
|
|
expect(jsPsych.getDisplayElement().innerHTML).toBe("");
|
|
|
|
var csv_data = jsPsych.data
|
|
.get()
|
|
.ignore(["rt", "internal_node_id", "time_elapsed", "trial_type", "question_order"])
|
|
.csv();
|
|
expect(csv_data).toBe('"response","trial_index"\r\n"{""q"":[""fuzz"",""bizz""]}","0"\r\n');
|
|
});
|
|
});
|