@jspsych/plugin-survey-multi-choice 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.js +71 -79
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.min.js +16 -2
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.cjs +70 -78
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -18
- package/dist/index.js +70 -78
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.spec.ts +32 -1
- package/src/index.ts +40 -71
package/dist/index.js
CHANGED
|
@@ -1,135 +1,125 @@
|
|
|
1
1
|
import { ParameterType } from 'jspsych';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
name: "@jspsych/plugin-survey-multi-choice",
|
|
5
|
-
version: "2.0.0",
|
|
6
|
-
description: "a jspsych plugin for multiple choice survey questions",
|
|
7
|
-
type: "module",
|
|
8
|
-
main: "dist/index.cjs",
|
|
9
|
-
exports: {
|
|
10
|
-
import: "./dist/index.js",
|
|
11
|
-
require: "./dist/index.cjs"
|
|
12
|
-
},
|
|
13
|
-
typings: "dist/index.d.ts",
|
|
14
|
-
unpkg: "dist/index.browser.min.js",
|
|
15
|
-
files: [
|
|
16
|
-
"src",
|
|
17
|
-
"dist"
|
|
18
|
-
],
|
|
19
|
-
source: "src/index.ts",
|
|
20
|
-
scripts: {
|
|
21
|
-
test: "jest",
|
|
22
|
-
"test:watch": "npm test -- --watch",
|
|
23
|
-
tsc: "tsc",
|
|
24
|
-
build: "rollup --config",
|
|
25
|
-
"build:watch": "npm run build -- --watch"
|
|
26
|
-
},
|
|
27
|
-
repository: {
|
|
28
|
-
type: "git",
|
|
29
|
-
url: "git+https://github.com/jspsych/jsPsych.git",
|
|
30
|
-
directory: "packages/plugin-survey-multi-choice"
|
|
31
|
-
},
|
|
32
|
-
author: "Shane Martin",
|
|
33
|
-
license: "MIT",
|
|
34
|
-
bugs: {
|
|
35
|
-
url: "https://github.com/jspsych/jsPsych/issues"
|
|
36
|
-
},
|
|
37
|
-
homepage: "https://www.jspsych.org/latest/plugins/survey-multi-choice",
|
|
38
|
-
peerDependencies: {
|
|
39
|
-
jspsych: ">=7.1.0"
|
|
40
|
-
},
|
|
41
|
-
devDependencies: {
|
|
42
|
-
"@jspsych/config": "^3.0.0",
|
|
43
|
-
"@jspsych/test-utils": "^1.2.0"
|
|
44
|
-
}
|
|
45
|
-
};
|
|
3
|
+
var version = "2.0.2";
|
|
46
4
|
|
|
47
5
|
const info = {
|
|
48
6
|
name: "survey-multi-choice",
|
|
49
|
-
version
|
|
7
|
+
version,
|
|
50
8
|
parameters: {
|
|
9
|
+
/**
|
|
10
|
+
* An array of objects, each object represents a question that appears on the screen. Each object contains a prompt,
|
|
11
|
+
* options, required, and horizontal parameter that will be applied to the question. See examples below for further
|
|
12
|
+
* clarification.`prompt`: Type string, default value is *undefined*. The string is prompt/question that will be
|
|
13
|
+
* associated with a group of options (radio buttons). All questions will get presented on the same page (trial).
|
|
14
|
+
* `options`: Type array, defualt value is *undefined*. An array of strings. The array contains a set of options to
|
|
15
|
+
* display for an individual question.`required`: Type boolean, default value is null. The boolean value indicates
|
|
16
|
+
* if a question is required('true') or not ('false'), using the HTML5 `required` attribute. If this parameter is
|
|
17
|
+
* undefined, the question will be optional. `horizontal`:Type boolean, default value is false. If true, then the
|
|
18
|
+
* question is centered and the options are displayed horizontally. `name`: Name of the question. Used for storing
|
|
19
|
+
* data. If left undefined then default names (`Q0`, `Q1`, `...`) will be used for the questions.
|
|
20
|
+
*/
|
|
51
21
|
questions: {
|
|
52
22
|
type: ParameterType.COMPLEX,
|
|
53
23
|
array: true,
|
|
54
24
|
nested: {
|
|
25
|
+
/** Question prompt. */
|
|
55
26
|
prompt: {
|
|
56
27
|
type: ParameterType.HTML_STRING,
|
|
57
28
|
default: void 0
|
|
58
29
|
},
|
|
30
|
+
/** Array of multiple choice options for this question. */
|
|
59
31
|
options: {
|
|
60
32
|
type: ParameterType.STRING,
|
|
61
33
|
array: true,
|
|
62
34
|
default: void 0
|
|
63
35
|
},
|
|
36
|
+
/** Whether or not a response to this question must be given in order to continue. */
|
|
64
37
|
required: {
|
|
65
38
|
type: ParameterType.BOOL,
|
|
66
39
|
default: false
|
|
67
40
|
},
|
|
41
|
+
/** If true, then the question will be centered and options will be displayed horizontally. */
|
|
68
42
|
horizontal: {
|
|
69
43
|
type: ParameterType.BOOL,
|
|
70
44
|
default: false
|
|
71
45
|
},
|
|
46
|
+
/** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */
|
|
72
47
|
name: {
|
|
73
48
|
type: ParameterType.STRING,
|
|
74
49
|
default: ""
|
|
75
50
|
}
|
|
76
51
|
}
|
|
77
52
|
},
|
|
53
|
+
/**
|
|
54
|
+
* If true, the display order of `questions` is randomly determined at the start of the trial. In the data object,
|
|
55
|
+
* `Q0` will still refer to the first question in the array, regardless of where it was presented visually.
|
|
56
|
+
*/
|
|
78
57
|
randomize_question_order: {
|
|
79
58
|
type: ParameterType.BOOL,
|
|
80
59
|
default: false
|
|
81
60
|
},
|
|
61
|
+
/** HTML formatted string to display at the top of the page above all the questions. */
|
|
82
62
|
preamble: {
|
|
83
63
|
type: ParameterType.HTML_STRING,
|
|
84
64
|
default: null
|
|
85
65
|
},
|
|
66
|
+
/** Label of the button. */
|
|
86
67
|
button_label: {
|
|
87
68
|
type: ParameterType.STRING,
|
|
88
69
|
default: "Continue"
|
|
89
70
|
},
|
|
71
|
+
/**
|
|
72
|
+
* This determines whether or not all of the input elements on the page should allow autocomplete. Setting
|
|
73
|
+
* this to true will enable autocomplete or auto-fill for the form.
|
|
74
|
+
*/
|
|
90
75
|
autocomplete: {
|
|
91
76
|
type: ParameterType.BOOL,
|
|
92
77
|
default: false
|
|
93
78
|
}
|
|
94
79
|
},
|
|
95
80
|
data: {
|
|
81
|
+
/** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */
|
|
96
82
|
response: {
|
|
97
|
-
type: ParameterType.
|
|
98
|
-
nested: {
|
|
99
|
-
identifier: {
|
|
100
|
-
type: ParameterType.STRING
|
|
101
|
-
},
|
|
102
|
-
response: {
|
|
103
|
-
type: ParameterType.STRING | ParameterType.INT | ParameterType.FLOAT | ParameterType.BOOL | ParameterType.OBJECT
|
|
104
|
-
}
|
|
105
|
-
}
|
|
83
|
+
type: ParameterType.OBJECT
|
|
106
84
|
},
|
|
85
|
+
/** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */
|
|
107
86
|
rt: {
|
|
108
87
|
type: ParameterType.INT
|
|
109
88
|
},
|
|
89
|
+
/** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */
|
|
110
90
|
question_order: {
|
|
111
91
|
type: ParameterType.INT,
|
|
112
92
|
array: true
|
|
113
93
|
}
|
|
114
94
|
}
|
|
115
95
|
};
|
|
96
|
+
const plugin_id_name = "jspsych-survey-multi-choice";
|
|
116
97
|
class SurveyMultiChoicePlugin {
|
|
117
98
|
constructor(jsPsych) {
|
|
118
99
|
this.jsPsych = jsPsych;
|
|
119
100
|
}
|
|
101
|
+
static {
|
|
102
|
+
this.info = info;
|
|
103
|
+
}
|
|
120
104
|
trial(display_element, trial) {
|
|
121
|
-
|
|
105
|
+
const trial_form_id = `${plugin_id_name}_form`;
|
|
122
106
|
var html = "";
|
|
123
|
-
html +=
|
|
124
|
-
|
|
125
|
-
|
|
107
|
+
html += `
|
|
108
|
+
<style id="${plugin_id_name}-css">
|
|
109
|
+
.${plugin_id_name}-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }
|
|
110
|
+
.${plugin_id_name}-text span.required {color: darkred;}
|
|
111
|
+
.${plugin_id_name}-horizontal .${plugin_id_name}-text { text-align: center;}
|
|
112
|
+
.${plugin_id_name}-option { line-height: 2; }
|
|
113
|
+
.${plugin_id_name}-horizontal .${plugin_id_name}-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}
|
|
114
|
+
label.${plugin_id_name}-text input[type='radio'] {margin-right: 1em;}
|
|
115
|
+
</style>`;
|
|
126
116
|
if (trial.preamble !== null) {
|
|
127
|
-
html +=
|
|
117
|
+
html += `<div id="${plugin_id_name}-preamble" class="${plugin_id_name}-preamble">${trial.preamble}</div>`;
|
|
128
118
|
}
|
|
129
119
|
if (trial.autocomplete) {
|
|
130
|
-
html +=
|
|
120
|
+
html += `<form id="${trial_form_id}">`;
|
|
131
121
|
} else {
|
|
132
|
-
html +=
|
|
122
|
+
html += `<form id="${trial_form_id}" autocomplete="off">`;
|
|
133
123
|
}
|
|
134
124
|
var question_order = [];
|
|
135
125
|
for (var i = 0; i < trial.questions.length; i++) {
|
|
@@ -141,39 +131,42 @@ class SurveyMultiChoicePlugin {
|
|
|
141
131
|
for (var i = 0; i < trial.questions.length; i++) {
|
|
142
132
|
var question = trial.questions[question_order[i]];
|
|
143
133
|
var question_id = question_order[i];
|
|
144
|
-
var question_classes = [
|
|
134
|
+
var question_classes = [`${plugin_id_name}-question`];
|
|
145
135
|
if (question.horizontal) {
|
|
146
|
-
question_classes.push(
|
|
136
|
+
question_classes.push(`${plugin_id_name}-horizontal`);
|
|
147
137
|
}
|
|
148
|
-
html +=
|
|
149
|
-
html +=
|
|
138
|
+
html += `<div id="${plugin_id_name}-${question_id}" class="${question_classes.join(" ")}" data-name="${question.name}">`;
|
|
139
|
+
html += `<p class="${plugin_id_name}-text survey-multi-choice">${question.prompt}`;
|
|
150
140
|
if (question.required) {
|
|
151
141
|
html += "<span class='required'>*</span>";
|
|
152
142
|
}
|
|
153
143
|
html += "</p>";
|
|
154
144
|
for (var j = 0; j < question.options.length; j++) {
|
|
155
|
-
var option_id_name =
|
|
156
|
-
var input_name =
|
|
157
|
-
var input_id =
|
|
145
|
+
var option_id_name = `${plugin_id_name}-option-${question_id}-${j}`;
|
|
146
|
+
var input_name = `${plugin_id_name}-response-${question_id}`;
|
|
147
|
+
var input_id = `${plugin_id_name}-response-${question_id}-${j}`;
|
|
158
148
|
var required_attr = question.required ? "required" : "";
|
|
159
|
-
html +=
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
149
|
+
html += `
|
|
150
|
+
<div id="${option_id_name}" class="${plugin_id_name}-option">
|
|
151
|
+
<label class="${plugin_id_name}-text" for="${input_id}">
|
|
152
|
+
<input type="radio" name="${input_name}" id="${input_id}" value="${question.options[j]}" ${required_attr} />
|
|
153
|
+
${question.options[j]}
|
|
154
|
+
</label>
|
|
155
|
+
</div>`;
|
|
164
156
|
}
|
|
165
157
|
html += "</div>";
|
|
166
158
|
}
|
|
167
|
-
html +=
|
|
159
|
+
html += `<input type="submit" id="${plugin_id_name}-next" class="${plugin_id_name} jspsych-btn"${trial.button_label ? ' value="' + trial.button_label + '"' : ""} />`;
|
|
168
160
|
html += "</form>";
|
|
169
161
|
display_element.innerHTML = html;
|
|
170
|
-
|
|
162
|
+
const trial_form = display_element.querySelector(`#${trial_form_id}`);
|
|
163
|
+
trial_form.addEventListener("submit", (event) => {
|
|
171
164
|
event.preventDefault();
|
|
172
165
|
var endTime = performance.now();
|
|
173
166
|
var response_time = Math.round(endTime - startTime);
|
|
174
167
|
var question_data = {};
|
|
175
168
|
for (var i2 = 0; i2 < trial.questions.length; i2++) {
|
|
176
|
-
var match = display_element.querySelector(
|
|
169
|
+
var match = display_element.querySelector(`#${plugin_id_name}-${i2}`);
|
|
177
170
|
var id = "Q" + i2;
|
|
178
171
|
var val;
|
|
179
172
|
if (match.querySelector("input[type=radio]:checked") !== null) {
|
|
@@ -237,7 +230,7 @@ class SurveyMultiChoicePlugin {
|
|
|
237
230
|
for (let i = 0; i < answers.length; i++) {
|
|
238
231
|
this.jsPsych.pluginAPI.clickTarget(
|
|
239
232
|
display_element.querySelector(
|
|
240
|
-
|
|
233
|
+
`#${plugin_id_name}-response-${i}-${trial.questions[i].options.indexOf(
|
|
241
234
|
answers[i][1]
|
|
242
235
|
)}`
|
|
243
236
|
),
|
|
@@ -245,12 +238,11 @@ class SurveyMultiChoicePlugin {
|
|
|
245
238
|
);
|
|
246
239
|
}
|
|
247
240
|
this.jsPsych.pluginAPI.clickTarget(
|
|
248
|
-
display_element.querySelector(
|
|
241
|
+
display_element.querySelector(`#${plugin_id_name}-next`),
|
|
249
242
|
data.rt
|
|
250
243
|
);
|
|
251
244
|
}
|
|
252
245
|
}
|
|
253
|
-
SurveyMultiChoicePlugin.info = info;
|
|
254
246
|
|
|
255
247
|
export { SurveyMultiChoicePlugin as default };
|
|
256
248
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"survey-multi-choice\",\n version: version,\n parameters: {\n /**\n * An array of objects, each object represents a question that appears on the screen. Each object contains a prompt,\n * options, required, and horizontal parameter that will be applied to the question. See examples below for further\n * clarification.`prompt`: Type string, default value is *undefined*. The string is prompt/question that will be\n * associated with a group of options (radio buttons). All questions will get presented on the same page (trial).\n * `options`: Type array, defualt value is *undefined*. An array of strings. The array contains a set of options to\n * display for an individual question.`required`: Type boolean, default value is null. The boolean value indicates\n * if a question is required('true') or not ('false'), using the HTML5 `required` attribute. If this parameter is\n * undefined, the question will be optional. `horizontal`:Type boolean, default value is false. If true, then the\n * question is centered and the options are displayed horizontally. `name`: Name of the question. Used for storing\n * data. If left undefined then default names (`Q0`, `Q1`, `...`) will be used for the questions.\n */\n questions: {\n type: ParameterType.COMPLEX,\n array: true,\n nested: {\n /** Question prompt. */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: undefined,\n },\n /** Array of multiple choice options for this question. */\n options: {\n type: ParameterType.STRING,\n array: true,\n default: undefined,\n },\n /** Whether or not a response to this question must be given in order to continue. */\n required: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** If true, then the question will be centered and options will be displayed horizontally. */\n horizontal: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */\n name: {\n type: ParameterType.STRING,\n default: \"\",\n },\n },\n },\n /**\n * If true, the display order of `questions` is randomly determined at the start of the trial. In the data object,\n * `Q0` will still refer to the first question in the array, regardless of where it was presented visually.\n */\n randomize_question_order: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** HTML formatted string to display at the top of the page above all the questions. */\n preamble: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** Label of the button. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n },\n /**\n * This determines whether or not all of the input elements on the page should allow autocomplete. Setting\n * this to true will enable autocomplete or auto-fill for the form.\n */\n autocomplete: {\n type: ParameterType.BOOL,\n default: false,\n },\n },\n data: {\n /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n response: {\n type: ParameterType.COMPLEX,\n nested: {\n identifier: {\n type: ParameterType.STRING,\n },\n response: {\n type:\n ParameterType.STRING |\n ParameterType.INT |\n ParameterType.FLOAT |\n ParameterType.BOOL |\n ParameterType.OBJECT,\n },\n },\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */\n rt: {\n type: ParameterType.INT,\n },\n /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n question_order: {\n type: ParameterType.INT,\n array: true,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * **survey-multi-choice**\n *\n * The survey-multi-choice plugin displays a set of questions with multiple choice response fields. The participant selects a single answer.\n *\n * @author Shane Martin\n * @see {@link https://www.jspsych.org/latest/plugins/survey-multi-choice/ survey-multi-choice plugin documentation on jspsych.org}\n */\nclass SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var plugin_id_name = \"jspsych-survey-multi-choice\";\n\n var html = \"\";\n\n // inject CSS for trial\n html += '<style id=\"jspsych-survey-multi-choice-css\">';\n html +=\n \".jspsych-survey-multi-choice-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }\" +\n \".jspsych-survey-multi-choice-text span.required {color: darkred;}\" +\n \".jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-text { text-align: center;}\" +\n \".jspsych-survey-multi-choice-option { line-height: 2; }\" +\n \".jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}\" +\n \"label.jspsych-survey-multi-choice-text input[type='radio'] {margin-right: 1em;}\";\n html += \"</style>\";\n\n // show preamble text\n if (trial.preamble !== null) {\n html +=\n '<div id=\"jspsych-survey-multi-choice-preamble\" class=\"jspsych-survey-multi-choice-preamble\">' +\n trial.preamble +\n \"</div>\";\n }\n\n // form element\n if (trial.autocomplete) {\n html += '<form id=\"jspsych-survey-multi-choice-form\">';\n } else {\n html += '<form id=\"jspsych-survey-multi-choice-form\" autocomplete=\"off\">';\n }\n // generate question order. this is randomized here as opposed to randomizing the order of trial.questions\n // so that the data are always associated with the same question regardless of order\n var question_order = [];\n for (var i = 0; i < trial.questions.length; i++) {\n question_order.push(i);\n }\n if (trial.randomize_question_order) {\n question_order = this.jsPsych.randomization.shuffle(question_order);\n }\n\n // add multiple-choice questions\n for (var i = 0; i < trial.questions.length; i++) {\n // get question based on question_order\n var question = trial.questions[question_order[i]];\n var question_id = question_order[i];\n\n // create question container\n var question_classes = [\"jspsych-survey-multi-choice-question\"];\n if (question.horizontal) {\n question_classes.push(\"jspsych-survey-multi-choice-horizontal\");\n }\n\n html +=\n '<div id=\"jspsych-survey-multi-choice-' +\n question_id +\n '\" class=\"' +\n question_classes.join(\" \") +\n '\" data-name=\"' +\n question.name +\n '\">';\n\n // add question text\n html += '<p class=\"jspsych-survey-multi-choice-text survey-multi-choice\">' + question.prompt;\n if (question.required) {\n html += \"<span class='required'>*</span>\";\n }\n html += \"</p>\";\n\n // create option radio buttons\n for (var j = 0; j < question.options.length; j++) {\n // add label and question text\n var option_id_name = \"jspsych-survey-multi-choice-option-\" + question_id + \"-\" + j;\n var input_name = \"jspsych-survey-multi-choice-response-\" + question_id;\n var input_id = \"jspsych-survey-multi-choice-response-\" + question_id + \"-\" + j;\n\n var required_attr = question.required ? \"required\" : \"\";\n\n // add radio button container\n html += '<div id=\"' + option_id_name + '\" class=\"jspsych-survey-multi-choice-option\">';\n html += '<label class=\"jspsych-survey-multi-choice-text\" for=\"' + input_id + '\">';\n html +=\n '<input type=\"radio\" name=\"' +\n input_name +\n '\" id=\"' +\n input_id +\n '\" value=\"' +\n question.options[j] +\n '\" ' +\n required_attr +\n \"></input>\";\n html += question.options[j] + \"</label>\";\n html += \"</div>\";\n }\n\n html += \"</div>\";\n }\n\n // add submit button\n html +=\n '<input type=\"submit\" id=\"' +\n plugin_id_name +\n '-next\" class=\"' +\n plugin_id_name +\n ' jspsych-btn\"' +\n (trial.button_label ? ' value=\"' + trial.button_label + '\"' : \"\") +\n \"></input>\";\n html += \"</form>\";\n\n // render\n display_element.innerHTML = html;\n\n document.querySelector(\"form\").addEventListener(\"submit\", (event) => {\n event.preventDefault();\n // measure response time\n var endTime = performance.now();\n var response_time = Math.round(endTime - startTime);\n\n // create object to hold responses\n var question_data = {};\n for (var i = 0; i < trial.questions.length; i++) {\n var match = display_element.querySelector(\"#jspsych-survey-multi-choice-\" + i);\n var id = \"Q\" + i;\n var val: String;\n if (match.querySelector(\"input[type=radio]:checked\") !== null) {\n val = match.querySelector<HTMLInputElement>(\"input[type=radio]:checked\").value;\n } else {\n val = \"\";\n }\n var obje = {};\n var name = id;\n if (match.attributes[\"data-name\"].value !== \"\") {\n name = match.attributes[\"data-name\"].value;\n }\n obje[name] = val;\n Object.assign(question_data, obje);\n }\n // save data\n var trial_data = {\n rt: response_time,\n response: question_data,\n question_order: question_order,\n };\n\n // next trial\n this.jsPsych.finishTrial(trial_data);\n });\n\n var startTime = performance.now();\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const question_data = {};\n let rt = 1000;\n\n for (const q of trial.questions) {\n const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;\n question_data[name] = this.jsPsych.randomization.sampleWithoutReplacement(q.options, 1)[0];\n rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);\n }\n\n const default_data = {\n response: question_data,\n rt: rt,\n question_order: trial.randomize_question_order\n ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])\n : [...Array(trial.questions.length).keys()],\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n this.trial(display_element, trial);\n load_callback();\n\n const answers = Object.entries(data.response);\n for (let i = 0; i < answers.length; i++) {\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\n `#jspsych-survey-multi-choice-response-${i}-${trial.questions[i].options.indexOf(\n answers[i][1]\n )}`\n ),\n ((data.rt - 1000) / answers.length) * (i + 1)\n );\n }\n\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\"#jspsych-survey-multi-choice-next\"),\n data.rt\n );\n }\n}\n\nexport default SurveyMultiChoicePlugin;\n"],"names":["version","i"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAM,IAAc,GAAA;AAAA,EAClB,IAAM,EAAA,qBAAA;AAAA,WACNA,gBAAA;AAAA,EACA,UAAY,EAAA;AAAA,IAaV,SAAW,EAAA;AAAA,MACT,MAAM,aAAc,CAAA,OAAA;AAAA,MACpB,KAAO,EAAA,IAAA;AAAA,MACP,MAAQ,EAAA;AAAA,QAEN,MAAQ,EAAA;AAAA,UACN,MAAM,aAAc,CAAA,WAAA;AAAA,UACpB,OAAS,EAAA,KAAA,CAAA;AAAA,SACX;AAAA,QAEA,OAAS,EAAA;AAAA,UACP,MAAM,aAAc,CAAA,MAAA;AAAA,UACpB,KAAO,EAAA,IAAA;AAAA,UACP,OAAS,EAAA,KAAA,CAAA;AAAA,SACX;AAAA,QAEA,QAAU,EAAA;AAAA,UACR,MAAM,aAAc,CAAA,IAAA;AAAA,UACpB,OAAS,EAAA,KAAA;AAAA,SACX;AAAA,QAEA,UAAY,EAAA;AAAA,UACV,MAAM,aAAc,CAAA,IAAA;AAAA,UACpB,OAAS,EAAA,KAAA;AAAA,SACX;AAAA,QAEA,IA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IAAA,CAAA,KAAA,CAAM,iBAAiB,KAAK,CAAA,CAAA;AACjC,IAAc,aAAA,EAAA,CAAA;AAEd,IAAA,MAAM,OAAU,GAAA,MAAA,CAAO,OAAQ,CAAA,IAAA,CAAK,QAAQ,CAAA,CAAA;AAC5C,IAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,OAAA,CAAQ,QAAQ,CAAK,EAAA,EAAA;AACvC,MAAA,IAAA,CAAK,QAAQ,SAAU,CAAA,WAAA;AAAA,QACrB,eAAgB,CAAA,aAAA;AAAA,UACd,CAAyC,sCAAA,EAAA,CAAA,CAAA,CAAA,EAAK,KAAM,CAAA,SAAA,CAAU,GAAG,OAAQ,CAAA,OAAA;AAAA,YACvE,QAAQ,CAAG,CAAA,CAAA,CAAA,CAAA;AAAA,WACb,CAAA,CAAA;AAAA,SACF;AAAA,QAAA,CACE,IAAK,CAAA,EAAA,GAAK,GAAQ,IAAA,OAAA,CAAQ,UAAW,CAAI,GAAA,CAAA,CAAA;AAAA,OAC7C,CAAA;AAAA,KACF;AAEA,IAAA,IAAA,CAAK,QAAQ,SAAU,CAAA,WAAA;AAAA,MACrB,eAAA,CAAgB,cAAc,mCAAmC,CAAA;AAAA,MACjE,IAAK,CAAA,EAAA;AAAA,KACP,CAAA;AAAA,GACF;AACF,CAAA;AAlOM,uBAAA,CACG,IAAO,GAAA,IAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@jspsych/plugin-survey-multi-choice\",\n \"version\": \"2.0.2\",\n \"description\": \"a jspsych plugin for multiple choice survey questions\",\n \"type\": \"module\",\n \"main\": \"dist/index.cjs\",\n \"exports\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"typings\": \"dist/index.d.ts\",\n \"unpkg\": \"dist/index.browser.min.js\",\n \"files\": [\n \"src\",\n \"dist\"\n ],\n \"source\": \"src/index.ts\",\n \"scripts\": {\n \"test\": \"jest\",\n \"test:watch\": \"npm test -- --watch\",\n \"tsc\": \"tsc\",\n \"build\": \"rollup --config\",\n \"build:watch\": \"npm run build -- --watch\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/jspsych/jsPsych.git\",\n \"directory\": \"packages/plugin-survey-multi-choice\"\n },\n \"author\": \"Shane Martin\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/jspsych/jsPsych/issues\"\n },\n \"homepage\": \"https://www.jspsych.org/latest/plugins/survey-multi-choice\",\n \"peerDependencies\": {\n \"jspsych\": \">=7.1.0\"\n },\n \"devDependencies\": {\n \"@jspsych/config\": \"^3.1.1\",\n \"@jspsych/test-utils\": \"^1.2.0\"\n }\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"survey-multi-choice\",\n version: version,\n parameters: {\n /**\n * An array of objects, each object represents a question that appears on the screen. Each object contains a prompt,\n * options, required, and horizontal parameter that will be applied to the question. See examples below for further\n * clarification.`prompt`: Type string, default value is *undefined*. The string is prompt/question that will be\n * associated with a group of options (radio buttons). All questions will get presented on the same page (trial).\n * `options`: Type array, defualt value is *undefined*. An array of strings. The array contains a set of options to\n * display for an individual question.`required`: Type boolean, default value is null. The boolean value indicates\n * if a question is required('true') or not ('false'), using the HTML5 `required` attribute. If this parameter is\n * undefined, the question will be optional. `horizontal`:Type boolean, default value is false. If true, then the\n * question is centered and the options are displayed horizontally. `name`: Name of the question. Used for storing\n * data. If left undefined then default names (`Q0`, `Q1`, `...`) will be used for the questions.\n */\n questions: {\n type: ParameterType.COMPLEX,\n array: true,\n nested: {\n /** Question prompt. */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: undefined,\n },\n /** Array of multiple choice options for this question. */\n options: {\n type: ParameterType.STRING,\n array: true,\n default: undefined,\n },\n /** Whether or not a response to this question must be given in order to continue. */\n required: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** If true, then the question will be centered and options will be displayed horizontally. */\n horizontal: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */\n name: {\n type: ParameterType.STRING,\n default: \"\",\n },\n },\n },\n /**\n * If true, the display order of `questions` is randomly determined at the start of the trial. In the data object,\n * `Q0` will still refer to the first question in the array, regardless of where it was presented visually.\n */\n randomize_question_order: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** HTML formatted string to display at the top of the page above all the questions. */\n preamble: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** Label of the button. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n },\n /**\n * This determines whether or not all of the input elements on the page should allow autocomplete. Setting\n * this to true will enable autocomplete or auto-fill for the form.\n */\n autocomplete: {\n type: ParameterType.BOOL,\n default: false,\n },\n },\n data: {\n /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n response: {\n type: ParameterType.OBJECT,\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */\n rt: {\n type: ParameterType.INT,\n },\n /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n question_order: {\n type: ParameterType.INT,\n array: true,\n },\n },\n};\n\ntype Info = typeof info;\n\nconst plugin_id_name = \"jspsych-survey-multi-choice\";\n\n/**\n * **survey-multi-choice**\n *\n * The survey-multi-choice plugin displays a set of questions with multiple choice response fields. The participant selects a single answer.\n *\n * @author Shane Martin\n * @see {@link https://www.jspsych.org/latest/plugins/survey-multi-choice/ survey-multi-choice plugin documentation on jspsych.org}\n */\nclass SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) { }\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n\n const trial_form_id = `${plugin_id_name}_form`;\n\n var html = \"\";\n\n // inject CSS for trial\n html += `\n <style id=\"${plugin_id_name}-css\">\n .${plugin_id_name}-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }\n .${plugin_id_name}-text span.required {color: darkred;}\n .${plugin_id_name}-horizontal .${plugin_id_name}-text { text-align: center;}\n .${plugin_id_name}-option { line-height: 2; }\n .${plugin_id_name}-horizontal .${plugin_id_name}-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}\n label.${plugin_id_name}-text input[type='radio'] {margin-right: 1em;}\n </style>`;\n\n // show preamble text\n if (trial.preamble !== null) {\n html += `<div id=\"${plugin_id_name}-preamble\" class=\"${plugin_id_name}-preamble\">${trial.preamble}</div>`;\n }\n\n // form element\n if (trial.autocomplete) {\n html += `<form id=\"${trial_form_id}\">`;\n } else {\n html += `<form id=\"${trial_form_id}\" autocomplete=\"off\">`;\n }\n\n // generate question order. this is randomized here as opposed to randomizing the order of trial.questions\n // so that the data are always associated with the same question regardless of order\n var question_order = [];\n for (var i = 0; i < trial.questions.length; i++) {\n question_order.push(i);\n }\n if (trial.randomize_question_order) {\n question_order = this.jsPsych.randomization.shuffle(question_order);\n }\n\n // add multiple-choice questions\n for (var i = 0; i < trial.questions.length; i++) {\n // get question based on question_order\n var question = trial.questions[question_order[i]];\n var question_id = question_order[i];\n\n // create question container\n var question_classes = [`${plugin_id_name}-question`];\n if (question.horizontal) {\n question_classes.push(`${plugin_id_name}-horizontal`);\n }\n\n html += `<div id=\"${plugin_id_name}-${question_id}\" class=\"${question_classes.join(\" \")}\" data-name=\"${question.name}\">`;\n\n // add question text\n html += `<p class=\"${plugin_id_name}-text survey-multi-choice\">${question.prompt}`;\n if (question.required) {\n html += \"<span class='required'>*</span>\";\n }\n html += \"</p>\";\n\n // create option radio buttons\n for (var j = 0; j < question.options.length; j++) {\n // add label and question text\n var option_id_name = `${plugin_id_name}-option-${question_id}-${j}`;\n var input_name = `${plugin_id_name}-response-${question_id}`;\n var input_id = `${plugin_id_name}-response-${question_id}-${j}`;\n\n var required_attr = question.required ? \"required\" : \"\";\n\n // add radio button container\n html += `\n <div id=\"${option_id_name}\" class=\"${plugin_id_name}-option\">\n <label class=\"${plugin_id_name}-text\" for=\"${input_id}\">\n <input type=\"radio\" name=\"${input_name}\" id=\"${input_id}\" value=\"${question.options[j]}\" ${required_attr} />\n ${question.options[j]}\n </label>\n </div>`;\n }\n\n html += \"</div>\";\n }\n\n // add submit button\n html += `<input type=\"submit\" id=\"${plugin_id_name}-next\" class=\"${plugin_id_name} jspsych-btn\"${trial.button_label ? ' value=\"' + trial.button_label + '\"' : \"\"} />`;\n html += \"</form>\";\n\n // render\n display_element.innerHTML = html;\n\n const trial_form = display_element.querySelector<HTMLFormElement>(`#${trial_form_id}`);\n\n trial_form.addEventListener(\"submit\", (event) => {\n event.preventDefault();\n // measure response time\n var endTime = performance.now();\n var response_time = Math.round(endTime - startTime);\n\n // create object to hold responses\n var question_data = {};\n for (var i = 0; i < trial.questions.length; i++) {\n var match = display_element.querySelector(`#${plugin_id_name}-${i}`);\n var id = \"Q\" + i;\n var val: String;\n if (match.querySelector(\"input[type=radio]:checked\") !== null) {\n val = match.querySelector<HTMLInputElement>(\"input[type=radio]:checked\").value;\n } else {\n val = \"\";\n }\n var obje = {};\n var name = id;\n if (match.attributes[\"data-name\"].value !== \"\") {\n name = match.attributes[\"data-name\"].value;\n }\n obje[name] = val;\n Object.assign(question_data, obje);\n }\n // save data\n var trial_data = {\n rt: response_time,\n response: question_data,\n question_order: question_order,\n };\n\n // next trial\n this.jsPsych.finishTrial(trial_data);\n });\n\n var startTime = performance.now();\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const question_data = {};\n let rt = 1000;\n\n for (const q of trial.questions) {\n const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;\n question_data[name] = this.jsPsych.randomization.sampleWithoutReplacement(q.options, 1)[0];\n rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);\n }\n\n const default_data = {\n response: question_data,\n rt: rt,\n question_order: trial.randomize_question_order\n ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])\n : [...Array(trial.questions.length).keys()],\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n this.trial(display_element, trial);\n load_callback();\n\n const answers = Object.entries(data.response);\n for (let i = 0; i < answers.length; i++) {\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\n `#${plugin_id_name}-response-${i}-${trial.questions[i].options.indexOf(\n answers[i][1]\n )}`\n ),\n ((data.rt - 1000) / answers.length) * (i + 1)\n );\n }\n\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(`#${plugin_id_name}-next`),\n data.rt\n );\n }\n}\n\nexport default SurveyMultiChoicePlugin;\n"],"names":["i"],"mappings":";;AAEE,IAAW,OAAA,GAAA,OAAA;;ACEb,MAAM,IAAc,GAAA;AAAA,EAClB,IAAM,EA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OAAA,CAAQ,iBAAkB,EAAA,CAAA;AAEvD,IAAK,IAAA,CAAA,KAAA,CAAM,iBAAiB,KAAK,CAAA,CAAA;AACjC,IAAc,aAAA,EAAA,CAAA;AAEd,IAAA,MAAM,OAAU,GAAA,MAAA,CAAO,OAAQ,CAAA,IAAA,CAAK,QAAQ,CAAA,CAAA;AAC5C,IAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,OAAA,CAAQ,QAAQ,CAAK,EAAA,EAAA;AACvC,MAAA,IAAA,CAAK,QAAQ,SAAU,CAAA,WAAA;AAAA,QACrB,eAAgB,CAAA,aAAA;AAAA,UACd,CAAA,CAAA,EAAI,cAAc,CAAa,UAAA,EAAA,CAAC,IAAI,KAAM,CAAA,SAAA,CAAU,CAAC,CAAA,CAAE,OAAQ,CAAA,OAAA;AAAA,YAC7D,OAAA,CAAQ,CAAC,CAAA,CAAE,CAAC,CAAA;AAAA,WACb,CAAA,CAAA;AAAA,SACH;AAAA,QAAA,CACE,IAAK,CAAA,EAAA,GAAK,GAAQ,IAAA,OAAA,CAAQ,UAAW,CAAI,GAAA,CAAA,CAAA;AAAA,OAC7C,CAAA;AAAA,KACF;AAEA,IAAA,IAAA,CAAK,QAAQ,SAAU,CAAA,WAAA;AAAA,MACrB,eAAgB,CAAA,aAAA,CAAc,CAAI,CAAA,EAAA,cAAc,CAAO,KAAA,CAAA,CAAA;AAAA,MACvD,IAAK,CAAA,EAAA;AAAA,KACP,CAAA;AAAA,GACF;AACF;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jspsych/plugin-survey-multi-choice",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "a jspsych plugin for multiple choice survey questions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"jspsych": ">=7.1.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@jspsych/config": "^3.
|
|
40
|
+
"@jspsych/config": "^3.1.1",
|
|
41
41
|
"@jspsych/test-utils": "^1.2.0"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src/index.spec.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { clickTarget, simulateTimeline, startTimeline } from "@jspsych/test-utils";
|
|
2
2
|
|
|
3
|
+
import { initJsPsych } from "jspsych";
|
|
3
4
|
import surveyMultiChoice from ".";
|
|
4
5
|
|
|
5
6
|
jest.useFakeTimers();
|
|
@@ -10,6 +11,36 @@ const getInputElement = (choiceId: number, value: string) =>
|
|
|
10
11
|
) as HTMLInputElement;
|
|
11
12
|
|
|
12
13
|
describe("survey-multi-choice plugin", () => {
|
|
14
|
+
test("properly ends when has sibling form", async () => {
|
|
15
|
+
|
|
16
|
+
const container = document.createElement('div')
|
|
17
|
+
const outerForm = document.createElement('form')
|
|
18
|
+
outerForm.id = 'outer_form'
|
|
19
|
+
container.appendChild(outerForm)
|
|
20
|
+
const innerDiv = document.createElement('div')
|
|
21
|
+
innerDiv.id = 'target_id';
|
|
22
|
+
container.appendChild(innerDiv);
|
|
23
|
+
document.body.appendChild(container)
|
|
24
|
+
const jsPsychInst = initJsPsych({ display_element: innerDiv })
|
|
25
|
+
const options = ["a", "b", "c"];
|
|
26
|
+
|
|
27
|
+
const { getData, expectFinished } = await startTimeline([
|
|
28
|
+
{
|
|
29
|
+
type: surveyMultiChoice,
|
|
30
|
+
questions: [
|
|
31
|
+
{ prompt: "Q0", options },
|
|
32
|
+
{ prompt: "Q1", options },
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
], jsPsychInst);
|
|
36
|
+
|
|
37
|
+
getInputElement(0, "a").checked = true;
|
|
38
|
+
await clickTarget(document.querySelector("#jspsych-survey-multi-choice-next"));
|
|
39
|
+
await expectFinished();
|
|
40
|
+
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
|
|
13
44
|
test("data are logged with the right question when randomize order is true", async () => {
|
|
14
45
|
var scale = ["a", "b", "c", "d", "e"];
|
|
15
46
|
const { getData, expectFinished } = await startTimeline([
|
|
@@ -45,7 +76,7 @@ describe("survey-multi-choice plugin", () => {
|
|
|
45
76
|
});
|
|
46
77
|
});
|
|
47
78
|
|
|
48
|
-
describe("survey-
|
|
79
|
+
describe("survey-multi-choice plugin simulation", () => {
|
|
49
80
|
test("data-only mode works", async () => {
|
|
50
81
|
const scale = ["a", "b", "c", "d", "e"];
|
|
51
82
|
const { getData, expectFinished } = await simulateTimeline([
|