mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
test functions implemented
This commit is contained in:
parent
c17572b5ff
commit
890c9bd563
@ -25,7 +25,7 @@
|
||||
// another example with checking if all the blanks are filled in
|
||||
timeline.push({
|
||||
type: jsPsychCloze,
|
||||
text: 'The %% is the largest terrestrial mammal. It lives in both %% and %%.',
|
||||
text: 'Science notebooks have a %%-colored front cover. Math notebooks have a %%-colored front cover.',
|
||||
check_blanks: true,
|
||||
mistake_fn: function () { alert("You have not filled in all the blanks!"); }
|
||||
});
|
||||
|
@ -73,6 +73,20 @@ describe("cloze", () => {
|
||||
await expectFinished();
|
||||
});
|
||||
|
||||
test("ends trial on button click when all answers are checked for completion and are complete", async () => {
|
||||
const { expectFinished } = await startTimeline([
|
||||
{
|
||||
type: cloze,
|
||||
text: "This is a %cloze% text.",
|
||||
check_blanks: true,
|
||||
},
|
||||
]);
|
||||
|
||||
getInputElementById("input0").value = "filler";
|
||||
clickTarget(document.querySelector("#finish_cloze_button"));
|
||||
await expectFinished();
|
||||
});
|
||||
|
||||
test("does not end trial on button click when answers are checked and not correct", async () => {
|
||||
const { expectRunning } = await startTimeline([
|
||||
{
|
||||
@ -87,6 +101,20 @@ describe("cloze", () => {
|
||||
await expectRunning();
|
||||
});
|
||||
|
||||
test("does not end trial on button click when answers are checked for completion and some are missing", async () => {
|
||||
const { expectRunning } = await startTimeline([
|
||||
{
|
||||
type: cloze,
|
||||
text: "This is a %cloze% text.",
|
||||
check_answers: true,
|
||||
},
|
||||
]);
|
||||
|
||||
getInputElementById("input0").value = "";
|
||||
clickTarget(document.querySelector("#finish_cloze_button"));
|
||||
await expectRunning();
|
||||
});
|
||||
|
||||
test("does not call mistake function on button click when answers are checked and correct", async () => {
|
||||
const mistakeFn = jest.fn();
|
||||
|
||||
@ -104,6 +132,23 @@ describe("cloze", () => {
|
||||
expect(mistakeFn).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("does not call mistake function on button click when answers are checked for completion and are complete", async () => {
|
||||
const mistakeFn = jest.fn();
|
||||
|
||||
await startTimeline([
|
||||
{
|
||||
type: cloze,
|
||||
text: "This is a %cloze% text.",
|
||||
check_blanks: true,
|
||||
mistake_fn: mistakeFn,
|
||||
},
|
||||
]);
|
||||
|
||||
getInputElementById("input0").value = "cloze";
|
||||
clickTarget(document.querySelector("#finish_cloze_button"));
|
||||
expect(mistakeFn).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("calls mistake function on button click when answers are checked and not correct", async () => {
|
||||
const mistakeFn = jest.fn();
|
||||
|
||||
@ -121,6 +166,23 @@ describe("cloze", () => {
|
||||
expect(mistakeFn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("calls mistake function on button click when answers are checked for completion and are not complete", async () => {
|
||||
const mistakeFn = jest.fn();
|
||||
|
||||
await startTimeline([
|
||||
{
|
||||
type: cloze,
|
||||
text: "This is a %cloze% text.",
|
||||
check_answers: true,
|
||||
mistake_fn: mistakeFn,
|
||||
},
|
||||
]);
|
||||
|
||||
getInputElementById("input0").value = "";
|
||||
clickTarget(document.querySelector("#finish_cloze_button"));
|
||||
expect(mistakeFn).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("response data is stored as an array", async () => {
|
||||
const { getData, getHTML } = await startTimeline([
|
||||
{
|
||||
|
@ -89,7 +89,7 @@ class ClozePlugin implements JsPsychPlugin<Info> {
|
||||
}
|
||||
}
|
||||
if (trial.check_blanks) {
|
||||
if (answers[i].trim() === "") {
|
||||
if (answers[i] === "") {
|
||||
answers_filled = false;
|
||||
}
|
||||
}
|
||||
@ -105,16 +105,6 @@ class ClozePlugin implements JsPsychPlugin<Info> {
|
||||
display_element.innerHTML = "";
|
||||
this.jsPsych.finishTrial(trial_data);
|
||||
}
|
||||
// if (!trial.check_answers || (trial.check_answers && answers_correct)) {
|
||||
// var trial_data = {
|
||||
// response: answers,
|
||||
// };
|
||||
|
||||
// display_element.innerHTML = "";
|
||||
// this.jsPsych.finishTrial(trial_data);
|
||||
// } else {
|
||||
// trial.mistake_fn();
|
||||
// }
|
||||
};
|
||||
|
||||
display_element.innerHTML +=
|
||||
|
Loading…
Reference in New Issue
Block a user