const root = '../../'; const utils = require('../testing-utils.js'); jest.useFakeTimers(); describe('categorize-animation plugin', function(){ beforeEach(function(){ require(root + 'jspsych.js'); require(root + 'plugins/jspsych-categorize-animation.js'); }); test('loads correctly', 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(''); jest.runTimersToTime(500); expect(jsPsych.getDisplayElement().innerHTML).toBe('') }); test('prompt should display after animation', function(){ var trial = { type: 'categorize-animation', stimuli: ['img/happy_face_1.jpg', 'img/sad_face_1.jpg'], key_answer: 68, 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); 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(''); jest.runTimersToTime(500); expect(jsPsych.getDisplayElement().innerHTML).toBe(''); jest.runTimersToTime(500); expect(jsPsych.getDisplayElement().innerHTML).toBe(''); }); test('sequence reps', 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, sequence_reps: 2, 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(''); jest.runTimersToTime(1000); expect(jsPsych.getDisplayElement().innerHTML).toBe(''); jest.runTimersToTime(1000); expect(jsPsych.getDisplayElement().innerHTML).toBe(''); jest.runTimersToTime(1000); expect(jsPsych.getDisplayElement().innerHTML).toBe(''); }); test('subject can response before animation is completed', 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, sequence_reps: 2, 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.

", 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(''); }); });