Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
feat: 🎸 add preamble to survey trial
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashi1997 committed Feb 17, 2021
1 parent 6bfe25e commit ecf0a0f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
13 changes: 3 additions & 10 deletions tests/survey.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@ const survey = require("../trials/survey.js");

describe("survey trial", () => {
it("survey with require movement", () => {
const preamble = "Q1?";
const message = "What is your age?";
const result = survey(
{message:message});
const data = {
prompt: null,
answer: null,
responses: JSON.stringify({Q0:"response"}),
};
result.on_finish(data);
const result = survey({ preamble: preamble, message: message });
expect(result.preamble).toContain(preamble);
expect(result.questions[0].prompt).toContain(message);
expect(data.prompt[0]).toContain(message);
expect(data.answer).toEqual("response");
});
});
2 changes: 1 addition & 1 deletion trials/multiSurvey.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @module
* @param {Object} options
* @param {string} options.responseType - This tells jsPsych which plugin file to use to run the trial. (default: 'survey_multi_choice')
* @param {string} options.preamble - HTML formatted string to display at the top of the page above all the questions. (default: empty string)
* @param {string} options.preamble - HTML formatted string to display at the top of the page above all the questions. (default: "")
* @param {string|Array} options.prompts - The question prompts, this can be a string (one question) or an Array of strings (multiple questions) (default: "")
* @param {Object} options.ansChoices - Object consisting of the key as the answer choice name and value as the array of answer choices. (default: {})
*/
Expand Down
6 changes: 5 additions & 1 deletion trials/survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,28 @@ const { baseStimulus } = require("../lib/markup/stimuli");
* Builds a trial with a question and with free response text fields. The subject types in answers.
* @module
* @param {Object} options
* @param {string} options.preamble - HTML formatted string to display at the top of the page above all the questions. (default: "")
* @param {string} options.stimulus - Onscreen stimulus in HTML to be shown in the trial, if not set default text is empty. If the stimulus is not provided, message should be provided as a string. (default: "")
* @param {string} options.message - Onscreen message to be shown in the trial. (default: "")
*/

module.exports = function (options) {
const defaults = {
preamble: "",
stimulus: "",
message: "",
};
const { stimulus, message } = { ...defaults, ...options };
const { preamble, stimulus, message } = { ...defaults, ...options };

const stimulusOrMessage =
message !== "" ? baseStimulus(`<h1>${message}</h1>`, true) : stimulus;

return {
type: "survey_text",
preamble: preamble,
questions: [{ prompt: stimulusOrMessage, required: true }],
on_finish: (data) => {
window.scrollTo(0, 0);
data.prompt = [stimulusOrMessage];
data.answer = JSON.parse(data.responses)["Q0"];
},
Expand Down

0 comments on commit ecf0a0f

Please sign in to comment.