@coorpacademy/progression-engine
Version:
57 lines (56 loc) • 2.04 kB
JavaScript
;
var _set2 = _interopRequireDefault(require("lodash/fp/set"));
var _ava = _interopRequireDefault(require("ava"));
var _config = require("../../config");
var _variables = _interopRequireDefault(require("../variables"));
var _actions = require("./fixtures/actions");
var _engines = require("./fixtures/engines");
var _states = require("./fixtures/states");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const config = (0, _config.getConfig)(_engines.learner);
(0, _ava.default)('should extract instructions from answerAction and apply them to state', t => {
const state = _states.stateForFirstSlide;
const answerActionWithInstructions = (0, _set2.default)('payload.instructions', [{
value: 1,
type: 'set',
field: 'A'
}, {
value: 3,
type: 'add',
field: 'lives'
}, {
value: 2,
type: 'set',
field: 'stars'
}, {
value: false,
type: 'set',
field: 'reverse'
}], _actions.answerAction);
const newState = (0, _variables.default)(config)(state, answerActionWithInstructions);
t.is(newState.variables.A, 1);
t.is(newState.lives, 4);
t.is(newState.stars, 2);
t.is(newState.variables.reverse, false);
});
(0, _ava.default)('should extract instructions from moveAction and apply them to state', t => {
const state = _states.stateForFirstSlide;
const moveActionWithInstructions = (0, _set2.default)('payload.instructions', [{
value: 0,
type: 'set',
field: 'foo'
}, {
value: 10,
type: 'set',
field: 'bar'
}], _actions.moveAction);
const newState = (0, _variables.default)(config)(state, moveActionWithInstructions);
t.is(newState.variables.foo, 0);
t.is(newState.variables.bar, 10);
});
(0, _ava.default)('should not update variables if there are no instructions into moveAction', t => {
const state = _states.stateForFirstSlide;
const newState = (0, _variables.default)(config)(state, _actions.moveAction);
t.deepEqual(newState.variables, {});
});
//# sourceMappingURL=variables.js.map