[Core] Complete spec for capailities
Complete specs for capabilities introduced in platform/core, part of ongoing transition of this bundle. WTD-573.
This commit is contained in:
@@ -9,7 +9,50 @@ define(
|
||||
"use strict";
|
||||
|
||||
describe("The mutation capability", function () {
|
||||
var testModel,
|
||||
domainObject = { getModel: function () { return testModel; } },
|
||||
mutation;
|
||||
|
||||
function mockPromise(value) {
|
||||
return {
|
||||
then: function (callback) {
|
||||
return (value && value.then) ?
|
||||
value : mockPromise(callback(value));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
testModel = { number: 6 };
|
||||
mutation = new MutationCapability(
|
||||
{ when: mockPromise }, // $q
|
||||
domainObject
|
||||
);
|
||||
});
|
||||
|
||||
it("allows mutation of a model", function () {
|
||||
mutation.invoke(function (m) {
|
||||
m.number = m.number * 7;
|
||||
});
|
||||
expect(testModel.number).toEqual(42);
|
||||
});
|
||||
|
||||
it("allows setting a model", function () {
|
||||
mutation.invoke(function (m) {
|
||||
return { someKey: "some value" };
|
||||
});
|
||||
expect(testModel.number).toBeUndefined();
|
||||
expect(testModel.someKey).toEqual("some value");
|
||||
});
|
||||
|
||||
it("allows model mutation to be aborted", function () {
|
||||
mutation.invoke(function (m) {
|
||||
m.number = m.number * 7;
|
||||
return false; // Should abort change
|
||||
});
|
||||
// Number should not have been changed
|
||||
expect(testModel.number).toEqual(6);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user