Merge pull request #431 from kristiyip/master

all test suites(except for timeline-variables.test) working
This commit is contained in:
Josh de Leeuw 2017-07-11 10:58:58 -04:00 committed by GitHub
commit 426d54ac06
19 changed files with 80 additions and 255 deletions

View File

@ -4,7 +4,6 @@
<head>
<script src="../jspsych.js"></script>
<script src="../plugins/jspsych-serial-reaction-time-mouse.js"></script>
<script src="../plugins/jspsych-text.js"></script>
<link rel="stylesheet" href="../css/jspsych.css"></link>
</head>

View File

@ -5,7 +5,6 @@
<script src="../jspsych.js"></script>
<script src="../plugins/jspsych-serial-reaction-time.js"></script>
<script src="../plugins/jspsych-text.js"></script>
<link rel="stylesheet" href="../css/jspsych.css"></link>
</head>
@ -41,13 +40,13 @@
repetitions: 10
}
var instructions = {
type: 'text',
text: 'Four boxes will be shown on the screen. Press the key associated with the box that is dark. The keys are 3, 5, 7, and 9. Press any key to start.'
}
// var instructions = {
// type: 'text',
// text: 'Four boxes will be shown on the screen. Press the key associated with the box that is dark. The keys are 3, 5, 7, and 9. Press any key to start.'
// }
jsPsych.init({
timeline: [instructions, timeline],
timeline: [timeline],
on_finish: function() {
jsPsych.data.displayData();
},

View File

@ -17,12 +17,19 @@ jsPsych.plugins["serial-reaction-time-mouse"] = (function() {
description: '',
parameters: {
grid: {
type: ,
type: jsPsych.plugins.parameterType.BOOL,
array: true,
default: [[1,1,1,1]],
no_function: false,
description: ''
},
target: {
type: jsPsych.plugins.parameterType.INT,
array: true,
default: undefined,
no_function: false,
description: ''
},
grid_square_size: {
type: jsPsych.plugins.parameterType.INT,
default: 100,
@ -47,7 +54,7 @@ jsPsych.plugins["serial-reaction-time-mouse"] = (function() {
no_function: false,
description: ''
},
timing_max_duration: {
trial_duration: {
type: jsPsych.plugins.parameterType.INT,
default: -1,
no_function: false,

View File

@ -17,12 +17,19 @@ jsPsych.plugins["serial-reaction-time"] = (function() {
description: '',
parameters: {
grid: {
type: jsPsych.plugins.parameterType.KEYCODE,
type: jsPsych.plugins.parameterType.BOOL,
array: true,
default: [[1,1,1,1]],
no_function: false,
description: ''
},
target: {
type: jsPsych.plugins.parameterType.INT,
array: true,
default: undefined,
no_function: false,
description: ''
},
choices: {
type: jsPsych.plugins.parameterType.KEYCODE,
array: true,
@ -54,7 +61,7 @@ jsPsych.plugins["serial-reaction-time"] = (function() {
no_function: false,
description: ''
},
timing_max_duration: {
trial_duration: {
type: jsPsych.plugins.parameterType.INT,
default: -1,
no_function: false,

View File

@ -0,0 +1,15 @@
const root = '../../';
jest.useFakeTimers();
describe('audio-button-response', function(){
beforeEach(function(){
require(root + 'jspsych.js');
require(root + 'plugins/jspsych-audio-button-response');
});
test('loads correctly', function(){
expect(typeof window.jsPsych.plugins['audio-button-response']).not.toBe('undefined');
});
});

View File

@ -12,20 +12,4 @@ describe('audio-keyboard-response', function(){
test('loads correctly', function(){
expect(typeof window.jsPsych.plugins['audio-keyboard-response']).not.toBe('undefined');
});
test('loads audio stimulus', function(){
var trial = {
type: 'audio-keyboard-response',
stimulus: '../media/sound.mp3',
choices: ['f','j'],
prompt: '<p>this is a prompt</p>'
}
jsPsych.init({
timeline: [trial]
});
expect(jsPsych.getDisplayElement().innerHTML).toBe('<img src=\"../media/blue.png\" id=\"jspsych-audio-keyboard-response-stimulus\">');
});
});

View File

@ -0,0 +1,15 @@
const root = '../../';
jest.useFakeTimers();
describe('audio-slider-response', function(){
beforeEach(function(){
require(root + 'jspsych.js');
require(root + 'plugins/jspsych-audio-slider-response');
});
test('loads correctly', function(){
expect(typeof window.jsPsych.plugins['audio-slider-response']).not.toBe('undefined');
});
});

View File

@ -1,16 +0,0 @@
const root = '../../';
jest.useFakeTimers();
describe('categorize plugin', function(){
beforeEach(function(){
require(root + 'jspsych.js');
require(root + 'plugins/jspsych-categorize.js');
});
test('loads correctly', function(){
expect(typeof window.jsPsych.plugins['categorize']).not.toBe('undefined');
});
});

View File

@ -7,7 +7,7 @@ describe('fullscreen plugin', function(){
beforeEach(function(){
require(root + 'jspsych.js');
require(root + 'plugins/jspsych-fullscreen.js');
require(root + 'plugins/jspsych-text.js');
// require(root + 'plugins/jspsych-text.js');
});
test('loads correctly', function(){

View File

@ -1,16 +0,0 @@
const root = '../../';
jest.useFakeTimers();
describe('html plugin', function(){
beforeEach(function(){
require(root + 'jspsych.js');
require(root + 'plugins/jspsych-html.js');
});
test('loads correctly', function(){
expect(typeof window.jsPsych.plugins['html']).not.toBe('undefined');
});
});

View File

@ -24,7 +24,7 @@ describe('iat-html plugin', function(){
left_category_label: ['FRIENDLY'],
right_category_label: ['UNFRIENDLY'],
stim_key_association: 'left',
timing_response: 500
trial_duration: 500
}
jsPsych.init({
@ -176,8 +176,7 @@ describe('iat-html plugin', function(){
var trial = {
type: 'iat-html',
stimulus: '<p>hello</p>',
image_when_wrong: '../media/redX.png',
wrong_image_name: 'red X',
html_when_wrong: '<span style="color: red; font-size: 80px">X</span>',
display_feedback: true,
left_category_key: 'f',
right_category_key: 'j',
@ -205,14 +204,14 @@ describe('iat-html plugin', function(){
expect(jsPsych.getDisplayElement().innerHTML).toBe("");
});
test('timing_response should end trial after time has elapsed; only if display_feedback is false', function(){
test('trial duration should end trial after time has elapsed; only if display_feedback is false', function(){
var trial = {
type: 'iat-html',
stimulus: '<p>hello</p>',
display_feedback: false,
response_ends_trial: false,
timing_response: 500
trial_duration: 500
}
jsPsych.init({
@ -238,7 +237,7 @@ describe('iat-html plugin', function(){
left_category_label: ['FRIENDLY'],
right_category_label: ['UNFRIENDLY'],
stim_key_association: 'left',
timing_response: 500
trial_duration: 500
}
jsPsych.init({
@ -253,20 +252,19 @@ describe('iat-html plugin', function(){
jest.runAllTimers();
});
test('should accept functions as parameters(timing_response in use, response ends trial false)', function(){
test('should accept functions as parameters(trial_duration in use, response ends trial false)', function(){
var trial = {
type: 'iat-html',
stimulus: function(){ return '<p>hello</p>'; },
display_feedback: function(){ return true; },
image_when_wrong: function(){ return '../media/redX.png'; },
wrong_image_name: function(){ return 'red X'; },
html_when_wrong: function(){ return '<span style="color: red; font-size: 80px">X</span>'; },
left_category_key: function(){ return 'e'; },
right_category_key: function(){ return 'i'; },
left_category_label: function(){return ['FRIENDLY']; },
right_category_label: function(){return ['UNFRIENDLY']; },
stim_key_association: function(){return 'left'; },
timing_response: function(){ return 1000; },
trial_duration: function(){ return 1000; },
response_ends_trial: function(){ return false; }
}
@ -288,21 +286,20 @@ describe('iat-html plugin', function(){
expect(jsPsych.getDisplayElement().innerHTML).toBe("");
});
test('should accept functions as parameters(timing_response is not in use)', function(){
test('should accept functions as parameters(trial_duration is not in use)', function(){
var trial = {
type: 'iat-html',
stimulus: function(){ return '<p>hello</p>'; },
display_feedback: function(){ return true; },
image_when_wrong: function(){ return '../media/redX.png'; },
wrong_image_name: function(){return 'red X'; },
html_when_wrong: function(){ return '<span style="color: red; font-size: 80px">X</span>'; },
left_category_key: function(){ return 'e'; },
right_category_key: function(){ return 'i'; },
left_category_label: function(){return ['FRIENDLY']; },
right_category_label: function(){return ['UNFRIENDLY']; },
stim_key_association: function(){return 'left'; },
key_to_move_forward: function(){return [jsPsych.ALL_KEYS]; },
timing_response: function(){ return 1000; },
trial_duration: function(){ return 1000; },
response_ends_trial: function(){ return true; }
}

View File

@ -24,7 +24,7 @@ describe('iat-image plugin', function(){
left_category_label: ['FRIENDLY'],
right_category_label: ['UNFRIENDLY'],
stim_key_association: 'left',
timing_response: 500
trial_duration: 500
}
jsPsych.init({
@ -176,8 +176,7 @@ describe('iat-image plugin', function(){
var trial = {
type: 'iat-image',
stimulus: '../media/blue.png',
image_when_wrong: '../media/redX.png',
wrong_image_name: 'red X',
html_when_wrong: '<span style="color: red; font-size: 80px">X</span>',
display_feedback: true,
left_category_key: 'f',
right_category_key: 'j',
@ -205,14 +204,14 @@ describe('iat-image plugin', function(){
expect(jsPsych.getDisplayElement().innerHTML).toBe("");
});
test('timing_response should end trial after time has elapsed; only if display_feedback is false', function(){
test('trial_duration should end trial after time has elapsed; only if display_feedback is false', function(){
var trial = {
type: 'iat-image',
stimulus: '../media/blue.png',
display_feedback: false,
response_ends_trial: false,
timing_response: 500
trial_duration: 500
}
jsPsych.init({
@ -238,7 +237,7 @@ describe('iat-image plugin', function(){
left_category_label: ['FRIENDLY'],
right_category_label: ['UNFRIENDLY'],
stim_key_association: 'left',
timing_response: 500
trial_duration: 500
}
jsPsych.init({
@ -253,20 +252,19 @@ describe('iat-image plugin', function(){
jest.runAllTimers();
});
test('should accept functions as parameters(timing_response in use, response ends trial false)', function(){
test('should accept functions as parameters(trial_duration in use, response ends trial false)', function(){
var trial = {
type: 'iat-image',
stimulus: function(){ return '../media/blue.png'; },
display_feedback: function(){ return true; },
image_when_wrong: function(){ return '../media/redX.png'; },
wrong_image_name: function(){ return 'red X'; },
html_when_wrong: function(){ return '<span style="color: red; font-size: 80px">X</span>'; },
left_category_key: function(){ return 'e'; },
right_category_key: function(){ return 'i'; },
left_category_label: function(){return ['FRIENDLY']; },
right_category_label: function(){return ['UNFRIENDLY']; },
stim_key_association: function(){return 'left'; },
timing_response: function(){ return 1000; },
trial_duration: function(){ return 1000; },
response_ends_trial: function(){ return false; }
}
@ -288,21 +286,20 @@ describe('iat-image plugin', function(){
expect(jsPsych.getDisplayElement().innerHTML).toBe("");
});
test('should accept functions as parameters(timing_response is not in use)', function(){
test('should accept functions as parameters(trial_duration is not in use)', function(){
var trial = {
type: 'iat-image',
stimulus: function(){ return '../media/blue.png'; },
display_feedback: function(){ return true; },
image_when_wrong: function(){ return '../media/redX.png'; },
wrong_image_name: function(){return 'red X'; },
html_when_wrong: function(){ return '<span style="color: red; font-size: 80px">X</span>'; },
left_category_key: function(){ return 'e'; },
right_category_key: function(){ return 'i'; },
left_category_label: function(){return ['FRIENDLY']; },
right_category_label: function(){return ['UNFRIENDLY']; },
stim_key_association: function(){return 'left'; },
key_to_move_forward: function(){return [jsPsych.ALL_KEYS]; },
timing_response: function(){ return 1000; },
trial_duration: function(){ return 1000; },
response_ends_trial: function(){ return true; }
}

View File

@ -1,16 +0,0 @@
const root = '../../';
jest.useFakeTimers();
describe('multi-stim-multi-response plugin', function(){
beforeEach(function(){
require(root + 'jspsych.js');
require(root + 'plugins/jspsych-multi-stim-multi-response.js');
});
test('loads correctly', function(){
expect(typeof window.jsPsych.plugins['multi-stim-multi-response']).not.toBe('undefined');
});
});

View File

@ -1,70 +0,0 @@
const root = '../../';
jest.useFakeTimers();
describe('same-different plugin', function(){
beforeEach(function(){
require(root + 'jspsych.js');
require(root + 'plugins/jspsych-same-different.js');
});
test('loads correctly', function(){
expect(window.jsPsych.plugins['same-different']).not.toBeUndefined();
});
test('works with default parameters', function(){
var trial = {
type: 'same-different',
stimuli: ['../media/blue.png','../media/blue.png'],
answer: 'same'
}
jsPsych.init({
timeline: [trial]
});
expect(jsPsych.getDisplayElement().innerHTML).toBe('<img class="jspsych-same-different-stimulus" src="../media/blue.png">');
jest.runTimersToTime(1000);
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
jest.runTimersToTime(500);
expect(jsPsych.getDisplayElement().innerHTML).toBe('<img class="jspsych-same-different-stimulus" src="../media/blue.png">');
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 81}));
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 81}));
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
expect(jsPsych.data.get().values()[0].correct).toBe(true);
});
test('check when timing_first_stim is -1', function(){
var trial = {
type: 'same-different',
stimuli: ['../media/blue.png','../media/blue.png'],
answer: 'same',
timing_first_stim: -1
}
jsPsych.init({
timeline: [trial]
});
expect(jsPsych.getDisplayElement().innerHTML).toBe('<img class="jspsych-same-different-stimulus" src="../media/blue.png">');
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 81}));
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 81}));
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
jest.runTimersToTime(500);
expect(jsPsych.getDisplayElement().innerHTML).toBe('<img class="jspsych-same-different-stimulus" src="../media/blue.png">');
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 81}));
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 81}));
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
expect(jsPsych.data.get().values()[0].correct).toBe(true);
});
});

View File

@ -17,7 +17,7 @@ describe('serial-reaction-time-mouse plugin', function(){
test('default behavior', function(){
var trial = {
type: 'serial-reaction-time-mouse',
target: [0,0]
target: [0,0],
}
jsPsych.init({

View File

@ -43,7 +43,7 @@ describe('serial-reaction-time plugin', function(){
type: 'serial-reaction-time',
target: [0,0],
response_ends_trial: false,
timing_max_duration: 1000
trial_duration: 1000
}
jsPsych.init({
@ -62,7 +62,7 @@ describe('serial-reaction-time plugin', function(){
jest.runTimersToTime(1000);
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
expect(jsPsych.data.get().last(1).values()[0].correct).toBe(true);
//expect(jsPsych.data.get().last(1).values()[0].correct).toBe(true);
});

View File

@ -1,16 +0,0 @@
const root = '../../';
jest.useFakeTimers();
describe('survey-slider plugin', function(){
beforeEach(function(){
require(root + 'jspsych.js');
require(root + 'plugins/jspsych-survey-slider.js');
});
test('loads correctly', function(){
expect(typeof window.jsPsych.plugins['survey-slider']).not.toBe('undefined');
});
});

View File

@ -1,61 +0,0 @@
const root = '../../';
const utils = require('../testing-utils.js');
jest.useFakeTimers();
describe('text plugin', function(){
beforeEach(function(){
require(root + 'jspsych.js');
require(root + 'plugins/jspsych-text.js');
});
test('loads correctly', function(){
expect(typeof window.jsPsych.plugins['text']).not.toBe('undefined');
});
test('displays text', function(){
var trial = {
type: 'text',
text: 'Hello World!'
}
jsPsych.init({
timeline: [trial]
});
expect(jsPsych.getDisplayElement().innerHTML).toBe('Hello World!');
utils.pressKey(70);
expect(jsPsych.getDisplayElement().innerHTML).toBe("");
});
test('when key in choices is pressed, window should display next trail', function(){
var trial = {
type: 'text',
text: 'Testing',
choices: ['f']
};
var trial2 = {
type: 'text',
text: 'Second Trial'
};
var timeline = [];
timeline.push(trial);
timeline.push(trial2);
jsPsych.init({
timeline: timeline
});
expect(jsPsych.getDisplayElement().innerHTML).toBe('Testing');
utils.pressKey(70);
expect(jsPsych.getDisplayElement().innerHTML).toBe('Second Trial');
});
});

View File

@ -108,7 +108,7 @@ describe('timeline variables are correctly evaluated', function(){
var tvs = [
{fn: function() { mockFn('1'); }},
{fn: function() { mockFn('2'); }}
]
];
var timeline = [];