adds some tests for #350

but they have problems with shared jsdom window. need to figure out
solution.
This commit is contained in:
Josh de Leeuw 2017-06-11 23:45:14 -04:00 committed by KristinDiep
parent 4d571fee92
commit c9a975746d

View File

@ -1,45 +1,43 @@
const root = '../../';
require(root + 'jspsych.js');
require(root + 'plugins/jspsych-text.js');
describe('Data recording', function(){
xtest('record focus events', function(){
var timeline = [
{type: 'text', text:'hello'}
];
jsPsych.init({timeline:timeline});
// click through first trial
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
// check if data contains rt
beforeEach(function(){
require(root + 'jspsych.js');
require(root + 'plugins/jspsych-text.js');
})
xtest('record blur events', function(){
test('record focus events', function(){
var timeline = [
{type: 'text', text:'hello'}
];
jsPsych.init({timeline:timeline});
window.dispatchEvent(new Event('focus'));
// click through first trial
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
// check if data contains rt
// check data
expect(jsPsych.data.getInteractionData().filter({event: 'focus'}).count()).toBe(1);
})
xtest('record fullscreenenter events', function(){
test('record blur events', function(){
var timeline = [
{type: 'text', text:'hello'}
];
jsPsych.init({timeline:timeline});
console.log(jsPsych.data.getInteractionData().json())
window.dispatchEvent(new Event('blur'));
console.log(jsPsych.data.getInteractionData().json())
// click through first trial
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
// check if data contains rt
// check data
expect(jsPsych.data.getInteractionData().filter({event: 'blur'}).count()).toBe(1);
})
xtest('record fullscreenexit events', function(){
/* not sure yet how to test fullscreen events with jsdom engine */
test.skip('record fullscreenenter events', function(){
var timeline = [
{type: 'text', text:'hello'}
];
@ -48,24 +46,74 @@ describe('Data recording', function(){
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
// check if data contains rt
})
});
test.skip('record fullscreenexit events', function(){
var timeline = [
{type: 'text', text:'hello'}
];
jsPsych.init({timeline:timeline});
// click through first trial
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
// check if data contains rt
});
})
describe('on_interaction_data_update', function(){
xtest('fires for blur', function(){
beforeEach(function(){
require(root + 'jspsych.js');
require(root + 'plugins/jspsych-text.js');
})
test('fires for blur', function(){
var updatefn = jest.fn();
var timeline = [
{type: 'text', text:'hello'}
];
jsPsych.init({
timeline:timeline,
on_interaction_data_update: updatefn
});
window.dispatchEvent(new Event('blur'));
console.log(jsPsych.data.getInteractionData().json())
expect(updatefn.mock.calls.length).toBe(1);
// click through first trial
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
// check data
});
xtest('fires for focus', function(){
test.only('fires for focus', function(){
var updatefn = jest.fn();
var timeline = [
{type: 'text', text:'hello'}
];
jsPsych.init({
timeline:timeline,
on_interaction_data_update: updatefn
});
window.dispatchEvent(new Event('focus'));
console.log(jsPsych.data.getInteractionData().json())
expect(updatefn.mock.calls.length).toBe(1);
// click through first trial
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
// check data
})
/* not sure yet how to test fullscreen events with jsdom engine */
test.skip('fires for fullscreenexit', function(){
})
xtest('fires for fullscreenexit', function(){
})
xtest('fires for fullscreenenter', function(){
test.skip('fires for fullscreenenter', function(){
})
})