diff --git a/examples/jspsych-categorize-animation.html b/examples/jspsych-categorize-animation.html index 67847649..ca999e65 100644 --- a/examples/jspsych-categorize-animation.html +++ b/examples/jspsych-categorize-animation.html @@ -20,6 +20,7 @@ key_answer: 68, choices: [68, 83], text_answer: 'different', + feedback_duration: 500, correct_text: "
Correct. The faces had %ANS% expressions.
", incorrect_text: "Incorrect. The faces had %ANS% expressions.
", prompt: "Press D if the faces had different emotional expressions. Press S if the faces had the same emotional expression.
", diff --git a/tests/plugins/plugin-categorize-animation.test.js b/tests/plugins/plugin-categorize-animation.test.js index c1cb4569..b33dc94a 100644 --- a/tests/plugins/plugin-categorize-animation.test.js +++ b/tests/plugins/plugin-categorize-animation.test.js @@ -1,4 +1,5 @@ const root = '../../'; +const utils = require('../testing-utils.js'); jest.useFakeTimers(); @@ -13,4 +14,239 @@ describe('categorize-animation plugin', function(){ expect(typeof window.jsPsych.plugins['categorize-animation']).not.toBe('undefined'); }); + test('displays stimulus every 500ms', function(){ + var trial = { + type: 'categorize-animation', + stimuli: ['img/happy_face_1.jpg', 'img/sad_face_1.jpg'], + key_answer: 68 + } + + jsPsych.init({ + timeline: [trial] + }); + + jest.runTimersToTime(500); + expect(jsPsych.getDisplayElement().innerHTML).toBe('Press d if the faces had different emotional expressions. Press S if the faces had the same emotional expression.
" + } + + jsPsych.init({ + timeline: [trial], + }); + + jest.runTimersToTime(1500); + expect(jsPsych.getDisplayElement().innerHTML).toBe('Press d if the faces had different emotional expressions. Press S if the faces had the same emotional expression.
'); + }); + + test('should display correct if key_answer is pressed', function(){ + var trial = { + type: 'categorize-animation', + stimuli: ['img/happy_face_1.jpg', 'img/sad_face_1.jpg'], + key_answer: 68, + choices: [68, 83], + prompt: "Press d if the faces had different emotional expressions. Press S if the faces had the same emotional expression.
" + } + + jsPsych.init({ + timeline: [trial], + }); + + jest.runTimersToTime(1500); + utils.pressKey(68); + jest.runTimersToTime(1000); + expect(jsPsych.getDisplayElement().innerHTML).toBe('Correct.'); + }); + + test('should display incorrect if different key is pressed', function(){ + var trial = { + type: 'categorize-animation', + stimuli: ['img/happy_face_1.jpg', 'img/sad_face_1.jpg'], + key_answer: 68, + choices: [68, 83], + prompt: "Press d if the faces had different emotional expressions. Press S if the faces had the same emotional expression.
" + } + + jsPsych.init({ + timeline: [trial], + }); + + jest.runTimersToTime(1500); + utils.pressKey(83); + jest.runTimersToTime(1000); + expect(jsPsych.getDisplayElement().innerHTML).toBe('Wrong.'); + }); + + test('text answer should replace %ANS%', function(){ + var trials = { + type: 'categorize-animation', + stimuli: ['img/happy_face_1.jpg', 'img/sad_face_3.jpg'], + key_answer: 68, + choices: [68, 83], + text_answer: 'different', + correct_text: "Correct. The faces had %ANS% expressions.
", + incorrect_text: "Incorrect. The faces had %ANS% expressions.
", + prompt: "Press D if the faces had different emotional expressions. Press S if the faces had the same emotional expression.
", + }; + + jsPsych.init({ + timeline: [trials], + }); + + jest.runTimersToTime(1500); + utils.pressKey(68); + jest.runTimersToTime(1000); + expect(jsPsych.getDisplayElement().innerHTML).toBe('Correct. The faces had different expressions.
'); + }); + + test('correct text displays when when key_answer is pressed', function(){ + var trials = { + type: 'categorize-animation', + stimuli: ['img/happy_face_1.jpg', 'img/sad_face_3.jpg'], + key_answer: 68, + choices: [68, 83], + correct_text: "You pressed the correct key
", + incorrect_text: "Incorrect.
", + prompt: "Press D if the faces had different emotional expressions. Press S if the faces had the same emotional expression.
", + }; + + jsPsych.init({ + timeline: [trials], + }); + + jest.runTimersToTime(1500); + utils.pressKey(68); + jest.runTimersToTime(1000); + expect(jsPsych.getDisplayElement().innerHTML).toBe('You pressed the correct key
'); + }); + + test('correct text displays when when key_answer is pressed', function(){ + var trials = { + type: 'categorize-animation', + stimuli: ['img/happy_face_1.jpg', 'img/sad_face_3.jpg'], + key_answer: 68, + choices: [68, 83], + correct_text: "You pressed the correct key
", + incorrect_text: "Incorrect. You pressed the wrong key.
", + prompt: "Press D if the faces had different emotional expressions. Press S if the faces had the same emotional expression.
", + }; + + jsPsych.init({ + timeline: [trials], + }); + + jest.runTimersToTime(1500); + utils.pressKey(83); + jest.runTimersToTime(1000); + expect(jsPsych.getDisplayElement().innerHTML).toBe('Incorrect. You pressed the wrong key.
'); + }); + + test('duration to display image is based on frame_time', function(){ + var trials = { + type: 'categorize-animation', + stimuli: ['img/happy_face_1.jpg', 'img/sad_face_1.jpg'], + key_answer: 68, + choices: [68, 83], + frame_time: 1000, + correct_text: "You pressed the correct key
", + incorrect_text: "Incorrect. You pressed the wrong key.
", + prompt: "Press D if the faces had different emotional expressions. Press S if the faces had the same emotional expression.
", + }; + + jsPsych.init({ + timeline: [trials], + }); + + jest.runTimersToTime(1000); + expect(jsPsych.getDisplayElement().innerHTML).toBe('You pressed the correct key
", + incorrect_text: "Incorrect. You pressed the wrong key.
", + prompt: "Press D if the faces had different emotional expressions. Press S if the faces had the same emotional expression.
", + }; + + jsPsych.init({ + timeline: [trials], + }); + + jest.runTimersToTime(1000); + expect(jsPsych.getDisplayElement().innerHTML).toBe('You pressed the correct key
", + incorrect_text: "Incorrect. You pressed the wrong key.
", + prompt: "Press D if the faces had different emotional expressions. Press S if the faces had the same emotional expression.
", + allow_response_before_complete: true, + }; + + jsPsych.init({ + timeline: [trials], + }); + + jest.runTimersToTime(1500); + utils.pressKey(68); + jest.runTimersToTime(500); + expect(jsPsych.getDisplayElement().innerHTML).toBe('You pressed the correct key
'); + }); + + test('display should clear after feeback_duration is done', function(){ + var trials = { + type: 'categorize-animation', + stimuli: ['img/happy_face_1.jpg', 'img/sad_face_1.jpg'], + key_answer: 68, + choices: [68, 83], + frame_time: 500, + feeback_duration: 500, + correct_text: "You pressed the correct key
", + incorrect_text: "Incorrect. You pressed the wrong key.
", + prompt: "Press D if the faces had different emotional expressions. Press S if the faces had the same emotional expression.
", + }; + + jsPsych.init({ + timeline: [trials], + }); + + jest.runTimersToTime(1500); + utils.pressKey(68); + jest.runTimersToTime(500); + expect(jsPsych.getDisplayElement().innerHTML).toBe('You pressed the correct key
'); + jest.runTimersToTime(2000); + expect(jsPsych.getDisplayElement().innerHTML).toBe(''); + }); + });