diff --git a/docs/markdown_docs/plugins/jspsych-iat.md b/docs/markdown_docs/plugins/jspsych-iat.md index f648f94e..a6b2e8db 100644 --- a/docs/markdown_docs/plugins/jspsych-iat.md +++ b/docs/markdown_docs/plugins/jspsych-iat.md @@ -12,8 +12,9 @@ Parameter | Type | Default Value | Description ----------|------|---------------|------------ stimulus | string | *undefined* | The stimulus to display. Either HTML-formatted, or the path to an image. is_html | boolean | false | If `stimulus` is an HTML-formatted string, this parameter needs to be set to `true`. -image_when_wrong | string | *undefined* | Displays image feedback when user presses wrong key. Only needed when display_feedback == true. -wrong_image_name | string | 'wrong image' | The name associated with image_when_wrong. +htm_when_wrong | string | 'X' | The image to display when a user presses the wrong key. +bottom_instructions | string | "
If you press the wrong key, a red X will appear. Press any key to continue.
" | Instructions about making a wrong key press and whether another key press is needed to continue. +force_correct_key_press | boolean | false | If this is true and the user presses the wrong key then they have to press the other key to continue. An example would be two keys 'E' and 'I'. If the key associated with the stimulus is 'E' and key 'I' was pressed, then pressing 'E' is needed to continue the trial. When this is true, then parameter key_to_move_forward is not used. display_feedback | boolean | false | If true, then image_when_wrong and wrong_image_name is required. If false, timing_response is needed and trial will continue automatically. left_category_key | string | 'E' | Key press that is associated with the left_category_label. right_category_key | string | 'I' | Key press that is associated with the right_category_label. @@ -43,15 +44,15 @@ var trial_block = { stimulus: 'img/blue.png', stim_key_association: 'left', is_html: false, - image_when_wrong: 'img/redX.png', - wrong_image_name: 'red X', + html_when_wrong: 'X', + bottom_instructions: 'If you press the wrong key, a red X will appear. Press the other key to continue
', + force_correct_key_press: true, display_feedback: true, timing_response: 3000, //Only if display_feedback is false left_category_key: 'E', right_category_key: 'I', left_category_label: ['OLD'], right_category_label: ['YOUNG'], - key_to_move_forward: [jsPsych.ALL_KEYS], response_ends_trial: true } diff --git a/examples/jspsych-iat.html b/examples/jspsych-iat.html index ed11e043..958bbb80 100644 --- a/examples/jspsych-iat.html +++ b/examples/jspsych-iat.html @@ -60,15 +60,15 @@ var trial_block = { stimulus: jsPsych.timelineVariable('stimulus'), stim_key_association: jsPsych.timelineVariable('stim_key_association'), is_html: false, - image_when_wrong: 'img/redX.png', - wrong_image_name: 'red X', + html_when_wrong: 'X', + bottom_instructions: 'If you press the wrong key, a red X will appear. Press the other key to continue
', + force_correct_key_press: true, display_feedback: true, timing_response: 3000, //Only if display_feedback is false left_category_key: 'E', right_category_key: 'I', left_category_label: ['OLD'], right_category_label: ['YOUNG'], - key_to_move_forward: [jsPsych.ALL_KEYS], response_ends_trial: true } ], @@ -110,15 +110,15 @@ var trial_block2 = { is_html: true, stimulus: jsPsych.timelineVariable('stimulus'), stim_key_association: jsPsych.timelineVariable('stim_key_association'), - image_when_wrong: 'img/redX.png', - wrong_image_name: 'red X', + html_when_wrong: 'X', + bottom_instructions: 'If you press the wrong key, a red X will appear. Press the other key to continue
', + force_correct_key_press: true, display_feedback: true, timing_response: 3000, //Only if display_feedback is false left_category_key: 'E', right_category_key: 'I', left_category_label: ['BAD'], right_category_label: ['GOOD'], - key_to_move_forward: [jsPsych.ALL_KEYS], response_ends_trial: true } ], @@ -164,15 +164,15 @@ var trial_block3 = { is_html: jsPsych.timelineVariable('is_html'), stimulus: jsPsych.timelineVariable('stimulus'), stim_key_association: jsPsych.timelineVariable('stim_key_association'), - image_when_wrong: 'img/redX.png', - wrong_image_name: 'red X', + html_when_wrong: 'X', + bottom_instructions: 'If you press the wrong key, a red X will appear. Press the other key to continue
', + force_correct_key_press: true, display_feedback: true, timing_response: 3000, //Only if display_feedback is false left_category_key: 'E', right_category_key: 'I', left_category_label: ['BAD', 'OLD'], right_category_label: ['GOOD', 'YOUNG'], - key_to_move_forward: [jsPsych.ALL_KEYS], response_ends_trial: true } ], @@ -226,19 +226,19 @@ var instructions_block4 = { var trial_block4 = { timeline: [ { - type: 'iat', - is_html: jsPsych.timelineVariable('is_html'), - stimulus: jsPsych.timelineVariable('stimulus'), - stim_key_association: jsPsych.timelineVariable('stim_key_association'), - image_when_wrong: 'img/redX.png', - wrong_image_name: 'red X', - display_feedback: true, + type: 'iat', + is_html: jsPsych.timelineVariable('is_html'), + stimulus: jsPsych.timelineVariable('stimulus'), + stim_key_association: jsPsych.timelineVariable('stim_key_association'), + html_when_wrong: 'X', + bottom_instructions: 'If you press the wrong key, a red X will appear. Press the other key to continue
', + force_correct_key_press: true, + display_feedback: true, timing_response: 3000, //Only if display_feedback is false left_category_key: 'E', right_category_key: 'I', left_category_label: ['BAD', 'OLD'], right_category_label: ['GOOD', 'YOUNG'], - key_to_move_forward: [jsPsych.ALL_KEYS], response_ends_trial: true } ], @@ -294,15 +294,15 @@ var trial_block4 = { is_html: false, stimulus: jsPsych.timelineVariable('stimulus'), stim_key_association: jsPsych.timelineVariable('stim_key_association'), - image_when_wrong: 'img/redX.png', - wrong_image_name: 'red X', + html_when_wrong: 'X', + bottom_instructions: 'If you press the wrong key, a red X will appear. Press the other key to continue
', + force_correct_key_press: true, display_feedback: true, timing_response: 3000, //Only if display_feedback is false left_category_key: 'E', right_category_key: 'I', left_category_label: ['YOUNG'], right_category_label: ['OLD'], - key_to_move_forward: [jsPsych.ALL_KEYS], response_ends_trial: true } ], @@ -343,15 +343,16 @@ var trial_block4 = { is_html: jsPsych.timelineVariable('is_html'), stimulus: jsPsych.timelineVariable('stimulus'), stim_key_association: jsPsych.timelineVariable('stim_key_association'), - image_when_wrong: 'img/redX.png', - wrong_image_name: 'red X', + html_when_wrong: 'X', + bottom_instructions: 'If you press the wrong key, a red X will appear. Press the other key to continue
', + force_correct_key_press: true, display_feedback: true, timing_response: 3000, //Only if display_feedback is false left_category_key: 'E', right_category_key: 'I', left_category_label: ['BAD', 'OLD'], right_category_label: ['GOOD', 'YOUNG'], - key_to_move_forward: [jsPsych.ALL_KEYS], + response_ends_trial: true } ], timeline_variables: [ @@ -419,22 +420,22 @@ var trial_block4 = { }; var timeline = []; - // timeline.push(welcome_block); - // timeline.push(category_block); - //timeline.push(instructions_block); - timeline.push(trial_block); - // timeline.push(instructions_block2); - // timeline.push(trial_block2); - // timeline.push(instructions_block3); - // timeline.push(trial_block3); - // timeline.push(instructions_block4); - // timeline.push(trial_block4); - // timeline.push(instructions_block5); - // timeline.push(trial_block5); - // timeline.push(instructions_block6); - // timeline.push(trial_block6); - // timeline.push(instructions_block7); - // timeline.push(trial_block6); + timeline.push(welcome_block); + timeline.push(category_block); + timeline.push(instructions_block); + timeline.push(trial_block); + timeline.push(instructions_block2); + timeline.push(trial_block2); + timeline.push(instructions_block3); + timeline.push(trial_block3); + timeline.push(instructions_block4); + timeline.push(trial_block4); + timeline.push(instructions_block5); + timeline.push(trial_block5); + timeline.push(instructions_block6); + timeline.push(trial_block6); + timeline.push(instructions_block7); + timeline.push(trial_block6); timeline.push(debrief_block); jsPsych.init({ diff --git a/plugins/jspsych-iat.js b/plugins/jspsych-iat.js index aebb4d6c..0b0a267c 100644 --- a/plugins/jspsych-iat.js +++ b/plugins/jspsych-iat.js @@ -32,8 +32,9 @@ // set default values for the parameters trial.display_feedback = typeof trial.display_feedback == 'undefined' ? false : trial.display_feedback; - trial.image_when_wrong = trial.image_when_wrong || 'undefined'; - trial.wrong_image_name = trial.wrong_image_name || 'wrong image'; + trial.html_when_wrong = trial.html_when_wrong || 'X'; + trial.bottom_instructions = trial.bottom_instructions || "If you press the wrong key, a red X will appear. Press any key to continue.
"; + trial.force_correct_key_press = trial.force_correct_key_press || false; //If true, key_to_move_forward is no longer needed trial.left_category_key = trial.left_category_key || 'E'; trial.right_category_key = trial.right_category_key || 'I'; trial.left_category_label = trial.left_category_label || ['left']; @@ -43,13 +44,6 @@ trial.timing_response = trial.timing_response || -1; trial.key_to_move_forward = trial.key_to_move_forward || jsPsych.ALL_KEYS; - //Get keys to continue and put them in a string - var keysToContinue = ""; - var lastKey = trial.key_to_move_forward.length - 1; - for(var i = 0; i < lastKey; i++) { - keysToContinue += trial.key_to_move_forward[i] + ", "; - } - var html_str = ""; if (!trial.is_html) { @@ -82,47 +76,11 @@ html_str += "Trial will continue automatically.
"; - } - - if(!trial.response_ends_trial && !trial.display_feedback) { - html_str += "Trial will continue automatically.
"; - } - - if(trial.response_ends_trial && trial.display_feedback == true) { - html_str += "If you press the wrong key, a " + trial.wrong_image_name + " will appear. Press the other key to continue.
" - } else if(trial.key_to_move_forward[0] == jsPsych.ALL_KEYS) { - html_str += "If you press the wrong key, a " + trial.wrong_image_name + " will appear. Press any key to continue.
" - } else { - html_str += "If you press the wrong key, a " + trial.wrong_image_name + " will appear. Press " + trial.key_to_move_forward[0] + " to continue.
"; - } - } else { - html_str += "If you press the wrong key, a " + trial.wrong_image_name + " will appear. Press " + - keysToContinue + " " + trial.key_to_move_forward[lastKey] + " to continue.
"; - } - } else if (trial.response_ends_trial && trial.display_feedback != true) { - html_str += ""; - if(trial.key_to_move_forward.length == 1) { - if(trial.key_to_move_forward[0] == "other key") { - html_str += "If you press the wrong key, press the other key to continue.
" - } else if(trial.key_to_move_forward[0] == jsPsych.ALL_KEYS) { - html_str += "If you press the wrong key, press any key to continue.
" - } else { - html_str += "If you press the wrong key, press " + trial.key_to_move_forward[0] + " to continue.
"; - } - } else { - html_str += "If you press the wrong key, press " + - keysToContinue + " " + trial.key_to_move_forward[lastKey] + " to continue.
"; - } + if(trial.display_feedback === true) { + html_str += ""+trial.html_when_wrong+"
button
', + choices: ['HAPPY'], + is_html: true, + } + + jsPsych.init({ + timeline: [trial] + }); + + expect(jsPsych.getDisplayElement().innerHTML).toMatch(' '); + }); + + test('displays buttons in button array', function(){ + var trial = { + type: 'button-response', + button_html: ['img/button1.png', 'img/button2.png'], + choices: ['HAPPY', 'SAD'], + } + + jsPsych.init({ + timeline: [trial] + }); + + expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp(' ')); + }); + + test('prompt should append html below stimulus', function(){ + var trial = { + type: 'button-response', + stimulus: 'hello
', + is_html: true, + choices: ['HAPPY'], + prompt: 'hello
', + is_html: true, + choices: ['HAPPY'], + timing_stim: 500 + } + + jsPsych.init({ + timeline: [trial] + }); + + expect(jsPsych.getDisplayElement().innerHTML).toMatch(' '); + + jest.runAllTimers(); + + expect(jsPsych.getDisplayElement().innerHTML).toMatch(' '); + }); + + test('timing_response should end trial after time has elapsed', function(){ + var trial = { + type: 'button-response', + stimulus: 'hello
', + is_html: true, + choices: ['HAPPY'], + timing_response: 500 + } + + jsPsych.init({ + timeline: [trial] + }); + + expect(jsPsych.getDisplayElement().innerHTML).toMatch(' '); + + jest.runAllTimers(); + + expect(jsPsych.getDisplayElement().innerHTML).toBe(''); + }); + + test('trial should not end when response_ends_trial is false and stimulus should get responded class', function(){ + var trial = { + type: 'button-response', + stimulus: 'hello
', + is_html: true, + choices: ['HAPPY'], + response_ends_trial: false, + timing_response: 500 + } + + jsPsych.init({ + timeline: [trial] + }); + + document.querySelector('#jspsych-button-response-button-0').click(); + + expect(jsPsych.getDisplayElement().innerHTML).toBe('hello
I am a function'; + } + + var trial = { + type: 'call-function', + func: myFunc + } + + jsPsych.init({ + timeline: [trial] + }); + + expect(jsPsych.getDisplayElement().innerHTML).toBe(""); + }); + }); diff --git a/tests/testing-utils.js b/tests/testing-utils.js index 71ad098c..7473614a 100644 --- a/tests/testing-utils.js +++ b/tests/testing-utils.js @@ -3,7 +3,11 @@ exports.pressKey = function(key){ document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: key})); } -exports.clickTarget = function(target){ - target.dispatchEvent(new MouseEvent('mousedown', {bubbles: true, detail: {target: target}})); - target.dispatchEvent(new MouseEvent('mouseup', {bubbles: true, detail: {target: target}})); +exports.mouseDownMouseUpTarget = function(target){ + target.dispatchEvent(new MouseEvent('mousedown', {bubbles: true})); + target.dispatchEvent(new MouseEvent('mouseup', {bubbles: true})); +} + +exports.clickTarget = function(target){ + target.dispatchEvent(new MouseEvent('click', {bubbles: true})); }