@coorpacademy/progression-engine
Version:
418 lines (417 loc) • 10.7 kB
JavaScript
"use strict";
var _ava = _interopRequireDefault(require("ava"));
var _config = require("../../config");
var _ = require("..");
var _slides = _interopRequireDefault(require("./fixtures/slides"));
var _states = require("./fixtures/states");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
// on fixtures the order is 1, 2, 3, 5, 4
const [firstSlide, secondSlide, thirdSlide, fifthSlide, fourthSlide] = _slides.default;
const config = (0, _config.getConfig)({
ref: 'review',
version: '1'
});
(0, _ava.default)('should return the next slide when user has answered the 1st slide and there are available slides', t => {
const partialAction = {
type: 'answer',
payload: {
content: {
ref: '1.A1.1',
type: 'slide'
},
answer: ['foo', 'bar'],
godMode: false
}
};
const availableContent = [{
ref: 'skill_41BBqFKoS',
slides: [firstSlide, secondSlide, thirdSlide, fourthSlide, fifthSlide],
rules: null
}];
const nextStep = (0, _.computeNextStepAfterAnswerForReview)(config, _states.firstStateReview, availableContent, firstSlide, partialAction);
t.deepEqual(nextStep, {
type: 'answer',
payload: {
answer: ['foo', 'bar'],
content: {
ref: '1.A1.1',
type: 'slide'
},
godMode: false,
nextContent: {
ref: '1.A1.2',
type: 'slide'
},
isCorrect: true,
instructions: null
}
});
});
(0, _ava.default)('should return the next slide when user has answered the 2nd slide and there are available slides', t => {
const partialAction = {
type: 'answer',
payload: {
content: {
ref: '1.A1.2',
type: 'slide'
},
answer: ['foo', 'bar'],
godMode: true
}
};
const availableContent = [{
ref: 'skill_41BBqFKoS',
slides: [secondSlide, thirdSlide, fourthSlide, fifthSlide],
rules: null
}];
const nextStep = (0, _.computeNextStepAfterAnswerForReview)(config, _states.secondStateReview, availableContent, secondSlide, partialAction);
t.deepEqual(nextStep, {
type: 'answer',
payload: {
answer: ['foo', 'bar'],
content: {
ref: '1.A1.2',
type: 'slide'
},
godMode: true,
nextContent: {
ref: '1.A1.3',
type: 'slide'
},
isCorrect: true,
instructions: null
}
});
});
(0, _ava.default)('should return the next slide when user has answered the 3rd slide and there are available slides', t => {
const partialAction = {
type: 'answer',
payload: {
content: {
ref: '1.A1.3',
type: 'slide'
},
answer: ['foo', 'bar'],
godMode: true
}
};
const availableContent = [{
ref: 'skill_41BBqFKoS',
slides: [thirdSlide, fourthSlide, fifthSlide],
rules: null
}];
const nextStep = (0, _.computeNextStepAfterAnswerForReview)(config, _states.thirdStateReview, availableContent, thirdSlide, partialAction);
t.deepEqual(nextStep, {
type: 'answer',
payload: {
answer: ['foo', 'bar'],
content: {
ref: '1.A1.3',
type: 'slide'
},
godMode: true,
nextContent: {
ref: '1.A1.4',
type: 'slide'
},
isCorrect: true,
instructions: null
}
});
});
(0, _ava.default)('should return the next slide when user has answered the 4th slide and there are available slides', t => {
const partialAction = {
type: 'answer',
payload: {
content: {
ref: '1.A1.4',
type: 'slide'
},
answer: ['foo', 'bar'],
godMode: true
}
};
const availableContent = [{
ref: 'skill_41BBqFKoS',
slides: [fourthSlide, fifthSlide],
rules: null
}];
const nextStep = (0, _.computeNextStepAfterAnswerForReview)(config, _states.fourthStateReview, availableContent, fourthSlide, partialAction);
t.deepEqual(nextStep, {
type: 'answer',
payload: {
answer: ['foo', 'bar'],
content: {
ref: '1.A1.4',
type: 'slide'
},
godMode: true,
nextContent: {
ref: '1.A1.5',
type: 'slide'
},
isCorrect: true,
instructions: null
}
});
});
(0, _ava.default)('should return the exitNode when user has answered the 5th slide correctly, all other are also true', t => {
const partialAction = {
type: 'answer',
payload: {
content: {
ref: '1.A1.5',
type: 'slide'
},
answer: ['foo', 'bar'],
godMode: true
}
};
const availableContent = [{
ref: 'skill_41BBqFKoS',
slides: [fifthSlide],
rules: null
}];
const nextStep = (0, _.computeNextStepAfterAnswerForReview)(config, _states.allRightAnswersBeforeLastStepStateReview, availableContent, fifthSlide, partialAction);
t.deepEqual(nextStep, {
type: 'answer',
payload: {
answer: ['foo', 'bar'],
content: {
ref: '1.A1.5',
type: 'slide'
},
godMode: true,
nextContent: {
type: 'success',
ref: 'successExitNode'
},
isCorrect: true,
instructions: null
}
});
});
(0, _ava.default)('should return the exitNode when user has only one question correct and there is no available slide', t => {
const partialAction = {
type: 'answer',
payload: {
content: {
ref: '1.A1.1',
type: 'slide'
},
answer: ['foo', 'bar'],
godMode: false
}
};
const availableContent = [{
ref: 'skill_41BBqFKoS',
slides: [],
rules: null
}];
const nextStep = (0, _.computeNextStepAfterAnswerForReview)(config, _states.firstStateReview, availableContent, firstSlide, partialAction);
t.deepEqual(nextStep, {
type: 'answer',
payload: {
answer: ['foo', 'bar'],
content: {
ref: '1.A1.1',
type: 'slide'
},
godMode: false,
nextContent: {
type: 'success',
ref: 'successExitNode'
},
isCorrect: true,
instructions: null
}
});
});
(0, _ava.default)('should return one pending slide when user has answered the 5th slide', t => {
const partialAction = {
type: 'answer',
payload: {
content: {
ref: '1.A1.5',
type: 'slide'
},
answer: ['foo', 'bar'],
godMode: false
}
};
const availableContent = [{
ref: 'skill_41BBqFKoS',
slides: [fifthSlide],
rules: null
}];
const nextStep = (0, _.computeNextStepAfterAnswerForReview)(config, _states.wrongAnswersBeforeLastStepStateReview, availableContent, fifthSlide, partialAction);
t.deepEqual(nextStep, {
type: 'answer',
payload: {
answer: ['foo', 'bar'],
content: {
ref: '1.A1.5',
type: 'slide'
},
godMode: false,
nextContent: {
type: 'slide',
ref: '1.A1.2'
},
isCorrect: false,
instructions: null
}
});
});
(0, _ava.default)('should return the next wrong slide when user has finished the 5 slides and has still remaining questions to validate', t => {
const answerForSlide2 = {
type: 'answer',
payload: {
content: {
ref: '1.A1.2',
type: 'slide'
},
answer: ['foo'],
godMode: false
}
};
const availableContent = [{
ref: 'skill_41BBqFKoS',
slides: _slides.default,
rules: null
}];
const nextStepWithSlide4 = (0, _.computeNextStepAfterAnswerForReview)(config, _states.wrongAnswersAfterLastStepStateReview, availableContent, secondSlide, answerForSlide2);
if (!nextStepWithSlide4) {
t.fail();
return;
}
t.deepEqual(nextStepWithSlide4, {
type: 'answer',
payload: {
answer: ['foo'],
content: {
ref: '1.A1.2',
type: 'slide'
},
godMode: false,
nextContent: {
type: 'slide',
ref: '1.A1.4'
},
isCorrect: false,
instructions: null
}
});
const answerForSlide4 = {
type: 'answer',
payload: {
content: {
ref: '1.A1.4',
type: 'slide'
},
answer: ['foo'],
godMode: false
}
};
const nextStepWithSlide5 = (0, _.computeNextStepAfterAnswerForReview)(config, {
..._states.wrongAnswersAfterLastStepStateReview,
nextContent: {
ref: '1.A1.4',
type: 'slide'
}
}, availableContent, fourthSlide, answerForSlide4);
if (!nextStepWithSlide5) {
t.fail();
return;
}
t.deepEqual(nextStepWithSlide5, {
type: 'answer',
payload: {
answer: ['foo'],
content: {
ref: '1.A1.4',
type: 'slide'
},
godMode: false,
nextContent: {
type: 'slide',
ref: '1.A1.5'
},
isCorrect: false,
instructions: null
}
});
});
(0, _ava.default)('should return the same slide when user has answered wrong, has finished the 5 slides and has still remaining one questions to validate', t => {
const partialAction = {
type: 'answer',
payload: {
content: {
ref: '1.A1.4',
type: 'slide'
},
answer: ['xxx'],
godMode: false
}
};
const availableContent = [{
ref: 'skill_41BBqFKoS',
slides: _slides.default,
rules: null
}];
const nextStep = (0, _.computeNextStepAfterAnswerForReview)(config, _states.stillOneWrongAnswersAfterLastStepStateReview, availableContent, fourthSlide, partialAction);
t.deepEqual(nextStep, {
type: 'answer',
payload: {
answer: ['xxx'],
content: {
ref: '1.A1.4',
type: 'slide'
},
godMode: false,
nextContent: {
type: 'slide',
ref: '1.A1.4'
},
isCorrect: false,
instructions: null
}
});
});
(0, _ava.default)('should return the successExitNode when user has finished the 5 slides after several wrong attempts', t => {
const partialAction = {
type: 'answer',
payload: {
content: {
ref: '1.A1.4',
type: 'slide'
},
answer: ['xxx'],
godMode: true
}
};
const availableContent = [{
ref: 'skill_41BBqFKoS',
slides: _slides.default,
rules: null
}];
const nextStep = (0, _.computeNextStepAfterAnswerForReview)(config, _states.stillOneWrongAnswersAfterLastStepStateReview, availableContent, fourthSlide, partialAction);
t.deepEqual(nextStep, {
type: 'answer',
payload: {
answer: ['xxx'],
content: {
ref: '1.A1.4',
type: 'slide'
},
godMode: true,
nextContent: {
type: 'success',
ref: 'successExitNode'
},
isCorrect: true,
instructions: null
}
});
});
//# sourceMappingURL=compute-next-step-after-answer.review.js.map