mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-12 08:38:11 +00:00
adds some tests for #350
but they have problems with shared jsdom window. need to figure out solution.
This commit is contained in:
parent
4d571fee92
commit
c9a975746d
@ -1,45 +1,43 @@
|
|||||||
const root = '../../';
|
const root = '../../';
|
||||||
|
|
||||||
require(root + 'jspsych.js');
|
|
||||||
|
|
||||||
require(root + 'plugins/jspsych-text.js');
|
|
||||||
|
|
||||||
describe('Data recording', function(){
|
describe('Data recording', function(){
|
||||||
|
|
||||||
xtest('record focus events', function(){
|
beforeEach(function(){
|
||||||
var timeline = [
|
require(root + 'jspsych.js');
|
||||||
{type: 'text', text:'hello'}
|
require(root + 'plugins/jspsych-text.js');
|
||||||
];
|
|
||||||
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
|
|
||||||
})
|
})
|
||||||
|
|
||||||
xtest('record blur events', function(){
|
test('record focus events', function(){
|
||||||
var timeline = [
|
var timeline = [
|
||||||
{type: 'text', text:'hello'}
|
{type: 'text', text:'hello'}
|
||||||
];
|
];
|
||||||
jsPsych.init({timeline:timeline});
|
jsPsych.init({timeline:timeline});
|
||||||
|
window.dispatchEvent(new Event('focus'));
|
||||||
// click through first trial
|
// click through first trial
|
||||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
|
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
|
||||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {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 = [
|
var timeline = [
|
||||||
{type: 'text', text:'hello'}
|
{type: 'text', text:'hello'}
|
||||||
];
|
];
|
||||||
jsPsych.init({timeline:timeline});
|
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
|
// click through first trial
|
||||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
|
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
|
||||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {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 = [
|
var timeline = [
|
||||||
{type: 'text', text:'hello'}
|
{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('keydown', {keyCode: 32}));
|
||||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
|
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
|
||||||
// check if data contains rt
|
// 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(){
|
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(){
|
test.skip('fires for fullscreenenter', function(){
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
xtest('fires for fullscreenenter', function(){
|
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user