mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-12 08:38:11 +00:00
add a few more JSON and CSV conversion tests with plugins that uses objects and arrays in the data #670
This commit is contained in:
parent
94d72ddf82
commit
ca0c427e8f
@ -1,6 +1,8 @@
|
||||
const root = '../../';
|
||||
const utils = require('../testing-utils.js');
|
||||
|
||||
jest.useFakeTimers();
|
||||
|
||||
describe('data conversion to csv', function(){
|
||||
|
||||
beforeEach(function(){
|
||||
@ -8,7 +10,7 @@ describe('data conversion to csv', function(){
|
||||
require(root + 'plugins/jspsych-survey-text.js');
|
||||
});
|
||||
|
||||
test('survey-text data is correctly converted', function(){
|
||||
test('survey-text data response object is correctly converted', function(){
|
||||
var trial = {
|
||||
type: 'survey-text',
|
||||
questions: [
|
||||
@ -30,4 +32,75 @@ describe('data conversion to csv', function(){
|
||||
expect(csv_data).toBe('"responses","trial_index"\r\n"{""Q0"":""Response 1"",""Q1"":""Response 2""}","0"\r\n');
|
||||
})
|
||||
|
||||
test('same-different-html stimulus array is correctly converted', function(){
|
||||
require(root + 'plugins/jspsych-same-different-html.js');
|
||||
|
||||
var trial = {
|
||||
type: 'same-different-html',
|
||||
stimuli: ['<p>Climbing</p>', '<p>Walking</p>'],
|
||||
answer: 'different',
|
||||
gap_duration: 0,
|
||||
first_stim_duration: null
|
||||
}
|
||||
|
||||
var timeline = [trial];
|
||||
|
||||
jsPsych.init({timeline: timeline});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<p>Climbing</p>');
|
||||
utils.pressKey('q');
|
||||
jest.runAllTimers();
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<p>Walking</p>');
|
||||
utils.pressKey('q');
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
|
||||
|
||||
var csv_data = jsPsych.data.get().ignore(['rt','internal_node_id','time_elapsed','trial_type','rt_stim1','key_press_stim1']).csv();
|
||||
expect(csv_data).toBe('"answer","correct","stimulus","key_press","trial_index"\r\n"different","false","[""<p>Climbing</p>"",""<p>Walking</p>""]","q","0"\r\n')
|
||||
})
|
||||
|
||||
test('video-button-response stimulus array is correctly converted', function(){
|
||||
require(root + 'plugins/jspsych-video-button-response.js');
|
||||
|
||||
var trial = {
|
||||
type: 'video-button-response',
|
||||
stimulus: ['vid/video.mp4'],
|
||||
choices: ['button']
|
||||
}
|
||||
|
||||
var timeline = [trial];
|
||||
|
||||
jsPsych.init({timeline: timeline});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('video.mp4');
|
||||
utils.clickTarget(document.querySelector('#jspsych-video-button-response-button-0'));
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
|
||||
|
||||
var csv_data = jsPsych.data.get().ignore(['rt','internal_node_id','time_elapsed','trial_type']).csv();
|
||||
expect(csv_data).toBe('"stimulus","button_pressed","trial_index"\r\n"[""vid/video.mp4""]","0","0"\r\n');
|
||||
})
|
||||
|
||||
test('survey-multi-select response array is correctly converted', function(){
|
||||
require(root + 'plugins/jspsych-survey-multi-select.js');
|
||||
|
||||
var trial = {
|
||||
type: 'survey-multi-select',
|
||||
questions: [
|
||||
{prompt: "foo", options: ["fuzz", "bizz", "bar"], name: 'q'}
|
||||
]
|
||||
};
|
||||
|
||||
var timeline = [trial];
|
||||
|
||||
jsPsych.init({timeline: timeline});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('foo');
|
||||
utils.clickTarget(document.querySelector('#jspsych-survey-multi-select-response-0-0'));
|
||||
utils.clickTarget(document.querySelector('#jspsych-survey-multi-select-response-0-1'));
|
||||
utils.clickTarget(document.querySelector('#jspsych-survey-multi-select-next'));
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
|
||||
|
||||
var csv_data = jsPsych.data.get().ignore(['rt','internal_node_id','time_elapsed','trial_type','question_order']).csv();
|
||||
expect(csv_data).toBe('"responses","trial_index"\r\n"{""q"":[""fuzz"",""bizz""]}","0"\r\n')
|
||||
})
|
||||
|
||||
});
|
@ -1,14 +1,17 @@
|
||||
const root = '../../';
|
||||
const utils = require('../testing-utils.js');
|
||||
|
||||
jest.useFakeTimers();
|
||||
|
||||
describe('data conversion to json', function(){
|
||||
|
||||
beforeEach(function(){
|
||||
require(root + 'jspsych.js');
|
||||
require(root + 'plugins/jspsych-survey-text.js');
|
||||
});
|
||||
|
||||
test('survey-text data is correctly converted', function(){
|
||||
test('survey-text data response object is correctly converted', function(){
|
||||
require(root + 'plugins/jspsych-survey-text.js');
|
||||
|
||||
var trial = {
|
||||
type: 'survey-text',
|
||||
questions: [
|
||||
@ -30,4 +33,115 @@ describe('data conversion to json', function(){
|
||||
expect(json_data).toBe(JSON.stringify([{responses: {Q0: "Response 1", Q1: "Response 2"}, trial_index: 0}]));
|
||||
})
|
||||
|
||||
test('same-different-html stimulus array is correctly converted', function(){
|
||||
require(root + 'plugins/jspsych-same-different-html.js');
|
||||
|
||||
var trial = {
|
||||
type: 'same-different-html',
|
||||
stimuli: ['<p>Climbing</p>', '<p>Walking</p>'],
|
||||
answer: 'different',
|
||||
gap_duration: 0,
|
||||
first_stim_duration: null
|
||||
}
|
||||
|
||||
var timeline = [trial];
|
||||
|
||||
jsPsych.init({timeline: timeline});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<p>Climbing</p>');
|
||||
utils.pressKey('q');
|
||||
jest.runAllTimers();
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<p>Walking</p>');
|
||||
utils.pressKey('q');
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
|
||||
|
||||
var json_data = jsPsych.data.get().ignore(['rt','internal_node_id','time_elapsed','trial_type','rt_stim1','key_press_stim1']).json();
|
||||
expect(json_data).toBe(JSON.stringify([{answer: 'different', correct: false, stimulus: ['<p>Climbing</p>','<p>Walking</p>'], key_press: 'q', trial_index: 0}]));
|
||||
})
|
||||
|
||||
test('video-button-response stimulus array is correctly converted', function(){
|
||||
require(root + 'plugins/jspsych-video-button-response.js');
|
||||
|
||||
var trial = {
|
||||
type: 'video-button-response',
|
||||
stimulus: ['vid/video.mp4'],
|
||||
choices: ['button']
|
||||
}
|
||||
|
||||
var timeline = [trial];
|
||||
|
||||
jsPsych.init({timeline: timeline});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('video.mp4');
|
||||
utils.clickTarget(document.querySelector('#jspsych-video-button-response-button-0'));
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
|
||||
|
||||
var json_data = jsPsych.data.get().ignore(['rt','internal_node_id','time_elapsed','trial_type']).json();
|
||||
expect(json_data).toBe(JSON.stringify([{stimulus: ['vid/video.mp4'], button_pressed: 0, trial_index: 0}]));
|
||||
})
|
||||
|
||||
test('survey-multi-select response array is correctly converted', function(){
|
||||
require(root + 'plugins/jspsych-survey-multi-select.js');
|
||||
|
||||
var trial = {
|
||||
type: 'survey-multi-select',
|
||||
questions: [
|
||||
{prompt: "foo", options: ["fuzz", "bizz", "bar"], name: 'q'}
|
||||
]
|
||||
};
|
||||
|
||||
var timeline = [trial];
|
||||
|
||||
jsPsych.init({timeline: timeline});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('foo');
|
||||
utils.clickTarget(document.querySelector('#jspsych-survey-multi-select-response-0-0'));
|
||||
utils.clickTarget(document.querySelector('#jspsych-survey-multi-select-response-0-1'));
|
||||
utils.clickTarget(document.querySelector('#jspsych-survey-multi-select-next'));
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
|
||||
|
||||
var json_data = jsPsych.data.get().ignore(['rt','internal_node_id','time_elapsed','trial_type','question_order']).json();
|
||||
var data_js = [
|
||||
{
|
||||
responses: {
|
||||
q: ["fuzz","bizz"],
|
||||
},
|
||||
trial_index: 0
|
||||
}
|
||||
];
|
||||
expect(json_data).toBe(JSON.stringify(data_js));
|
||||
})
|
||||
|
||||
test('jsPsych json function is the same as JSON.stringify', function(){
|
||||
require(root + 'plugins/jspsych-survey-multi-select.js');
|
||||
|
||||
var trial = {
|
||||
type: 'survey-multi-select',
|
||||
questions: [
|
||||
{prompt: "foo", options: ["fuzz", "bizz", "bar"], name: 'q'}
|
||||
]
|
||||
};
|
||||
|
||||
var timeline = [trial];
|
||||
|
||||
jsPsych.init({timeline: timeline});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('foo');
|
||||
utils.clickTarget(document.querySelector('#jspsych-survey-multi-select-response-0-0'));
|
||||
utils.clickTarget(document.querySelector('#jspsych-survey-multi-select-response-0-1'));
|
||||
utils.clickTarget(document.querySelector('#jspsych-survey-multi-select-next'));
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
|
||||
|
||||
var json_data = jsPsych.data.get().ignore(['rt','internal_node_id','time_elapsed','trial_type','question_order']).json();
|
||||
var data_js = [
|
||||
{
|
||||
responses: {
|
||||
q: ["fuzz","bizz"],
|
||||
},
|
||||
trial_index: 0
|
||||
}
|
||||
];
|
||||
expect(json_data).toBe(JSON.stringify(data_js));
|
||||
})
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user