add tests for change from JSON strings to objects/arrays in data

This commit is contained in:
Becky Gilbert 2021-02-16 15:25:16 -08:00
parent 2312550127
commit 62db853317
3 changed files with 81 additions and 1 deletions

View File

@ -136,5 +136,22 @@ describe('cloze', function(){
expect(called).toBeTruthy(); expect(called).toBeTruthy();
}); });
test('response data is stored as an array', function(){
var trial = {
type: 'cloze',
text: 'This is a %cloze% text. Here is another cloze response box %%.'
}
jsPsych.init({
timeline: [trial]
});
document.getElementById('input0').value = 'cloze1';
document.getElementById('input1').value = 'cloze2';
utils.clickTarget(document.querySelector('#finish_cloze_button'));
var data = jsPsych.data.get().values()[0].answers;
expect(data.length).toBe(2);
expect(data[0]).toBe('cloze1');
expect(data[1]).toBe('cloze2');
});
}); });

View File

@ -63,4 +63,23 @@ describe('instructions plugin', function(){
expect(jsPsych.getDisplayElement().innerHTML).toBe(''); expect(jsPsych.getDisplayElement().innerHTML).toBe('');
}) })
test('view history data is stored as array of objects', function(){
var trial = {
type: 'instructions',
pages: ['page 1', 'page 2'],
key_forward: 'a'
}
jsPsych.init({
timeline: [trial]
});
utils.pressKey('a');
utils.pressKey('a');
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
var data = jsPsych.data.get().values()[0].view_history;
expect(data[0].page_index).toBe(0);
expect(data[1].page_index).toBe(1);
})
}); });

View File

@ -14,4 +14,48 @@ describe('rdk plugin', function(){
expect(typeof window.jsPsych.plugins['rdk']).not.toBe('undefined'); expect(typeof window.jsPsych.plugins['rdk']).not.toBe('undefined');
}); });
test('choices and frame data are stored as arrays', function(){
var trial = {
type: 'rdk',
number_of_dots: 200,
RDK_type: 3,
choices: ['a', 'l'],
correct_choice: 'l',
coherent_direction: 0
}
jsPsych.init({
timeline: [trial]
});
utils.pressKey('l')
var data = jsPsych.data.get().values()[0];
expect(Array.isArray(data.choices)).toBe(true);
expect(data.choices).toStrictEqual(['a', 'l']);
expect(Array.isArray(data.frame_rate_array)).toBe(true);
});
test('responses are scored correctly', function(){
var trial = {
type: 'rdk',
number_of_dots: 200,
RDK_type: 3,
choices: ['a', 'l'],
correct_choice: 'l',
coherent_direction: 0
}
jsPsych.init({
timeline: [trial,trial]
});
utils.pressKey('l');
utils.pressKey('a');
var data = jsPsych.data.get().values();
expect(data[0].key_press).toBe('l');
expect(data[0].correct).toBe(true);
expect(data[1].key_press).toBe('a');
expect(data[1].correct).toBe(false);
});
}); });