mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-11 16:18:11 +00:00
add basic test for #390
This commit is contained in:
parent
15c6ec4385
commit
31251b7dcb
@ -27,10 +27,7 @@ jsPsych.plugins["serial-reaction-time-mouse"] = (function() {
|
||||
|
||||
var startTime = -1;
|
||||
var response = {
|
||||
rt: -1,
|
||||
row: -1,
|
||||
column: -1,
|
||||
correct: false
|
||||
rt: -1
|
||||
}
|
||||
|
||||
// display stimulus
|
||||
@ -52,16 +49,12 @@ jsPsych.plugins["serial-reaction-time-mouse"] = (function() {
|
||||
}
|
||||
|
||||
function showTarget(){
|
||||
|
||||
display_element.querySelector('#jspsych-serial-reaction-time-stimulus-cell-'+trial.target[0]+'-'+trial.target[1]).addEventListener('mousedown', function(e){
|
||||
if(startTime == -1){
|
||||
return;
|
||||
} else {
|
||||
var info = {}
|
||||
info.rt = Date.now() - startTime;
|
||||
var node = e.target;
|
||||
info.row = parseInt(node.dataset.row);
|
||||
info.column = parseInt(node.dataset.column);
|
||||
after_response(info);
|
||||
}
|
||||
});
|
||||
|
@ -1,3 +1,4 @@
|
||||
const utils = require('../testing-utils.js');
|
||||
const root = '../../';
|
||||
|
||||
jest.useFakeTimers();
|
||||
@ -13,4 +14,29 @@ describe('serial-reaction-time-mouse plugin', function(){
|
||||
expect(typeof window.jsPsych.plugins['serial-reaction-time-mouse']).not.toBe('undefined');
|
||||
});
|
||||
|
||||
test('default behavior', function(){
|
||||
var trial = {
|
||||
type: 'serial-reaction-time-mouse',
|
||||
target: [0,0]
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
});
|
||||
|
||||
expect(document.querySelector('#jspsych-serial-reaction-time-stimulus-cell-0-0').style.backgroundColor).toBe('rgb(153, 153, 153)');
|
||||
expect(document.querySelector('#jspsych-serial-reaction-time-stimulus-cell-0-1').style.backgroundColor).toBe('');
|
||||
expect(document.querySelector('#jspsych-serial-reaction-time-stimulus-cell-0-2').style.backgroundColor).toBe('');
|
||||
expect(document.querySelector('#jspsych-serial-reaction-time-stimulus-cell-0-3').style.backgroundColor).toBe('');
|
||||
|
||||
utils.clickTarget(document.querySelector('#jspsych-serial-reaction-time-stimulus-cell-0-1'));
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).not.toBe('');
|
||||
|
||||
utils.clickTarget(document.querySelector('#jspsych-serial-reaction-time-stimulus-cell-0-0'));
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
|
||||
|
||||
})
|
||||
|
||||
});
|
||||
|
@ -2,3 +2,8 @@ exports.pressKey = function(key){
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: key}));
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: key}));
|
||||
}
|
||||
|
||||
exports.clickTarget = function(target){
|
||||
target.dispatchEvent(new MouseEvent('mousedown', {bubbles: true, detail: {target: target}}));
|
||||
target.dispatchEvent(new MouseEvent('mouseup', {bubbles: true, detail: {target: target}}));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user