const utils = require('../testing-utils.js'); const root = '../../'; jest.useFakeTimers(); describe('image-button-response', function(){ beforeEach(function(){ require(root + 'jspsych.js'); require(root + 'plugins/jspsych-image-button-response'); }); test('loads correctly', function(){ expect(typeof window.jsPsych.plugins['image-button-response']).not.toBe('undefined'); }); test('displays image stimulus', function(){ var trial = { type: 'image-button-response', stimulus: '../media/blue.png', choices: ['button-choice'], render_on_canvas: false } jsPsych.init({ timeline: [trial] }); expect(jsPsych.getDisplayElement().innerHTML).toMatch('button-choice1')); expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('')); }); test('display button html', function(){ var trial = { type: 'image-button-response', stimulus: '../media/blue.png', choices: ['buttonChoice'], button_html: '', render_on_canvas: false } jsPsych.init({ timeline: [trial] }); expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('')); }); test('display should clear after button click', function(){ var trial = { type: 'image-button-response', stimulus: '../media/blue.png', choices: ['button-choice'], render_on_canvas: false } jsPsych.init({ timeline: [trial] }); expect(jsPsych.getDisplayElement().innerHTML).toMatch('This is a prompt

', render_on_canvas: false } jsPsych.init({ timeline: [trial] }); expect(jsPsych.getDisplayElement().innerHTML).toMatch('

This is a prompt

'); }); test('should hide stimulus if stimulus-duration is set', function(){ var trial = { type: 'image-button-response', stimulus: '../media/blue.png', choices: ['button-choice'], stimulus_duration: 500, render_on_canvas: false } jsPsych.init({ timeline: [trial] }); expect(jsPsych.getDisplayElement().querySelector('#jspsych-image-button-response-stimulus').style.visibility).toMatch(""); jest.runTimersToTime(500); expect(jsPsych.getDisplayElement().querySelector('#jspsych-image-button-response-stimulus').style.visibility).toMatch('hidden'); }); test('should end trial when trial duration is reached', function(){ var trial = { type: 'image-button-response', stimulus: '../media/blue.png', choices: ['f','j'], trial_duration: 500, render_on_canvas: false } jsPsych.init({ timeline: [trial] }); expect(jsPsych.getDisplayElement().innerHTML).toMatch('