mirror of
https://github.com/nasa/openmct.git
synced 2025-04-08 20:04:27 +00:00
[Common UI] Complete specs for edit mode
Add specs for remaining capabilities and capability wrappers employed by Edit mode. Completes coverage for bundle platform/commonUI/edit, which is being transitioned along with other commonUI bundles in WTD-574.
This commit is contained in:
parent
7ddfcbca9b
commit
c432a4eb1e
@ -0,0 +1,75 @@
|
||||
/*global define,describe,it,expect,beforeEach,jasmine*/
|
||||
|
||||
define(
|
||||
["../../src/capabilities/EditableContextCapability"],
|
||||
function (EditableContextCapability) {
|
||||
"use strict";
|
||||
|
||||
describe("An editable context capability", function () {
|
||||
var mockContext,
|
||||
mockEditableObject,
|
||||
mockDomainObject,
|
||||
mockTestObject,
|
||||
someValue,
|
||||
factory,
|
||||
capability;
|
||||
|
||||
beforeEach(function () {
|
||||
// EditableContextCapability should watch ALL
|
||||
// methods for domain objects, so give it an
|
||||
// arbitrary interface to wrap.
|
||||
mockContext = jasmine.createSpyObj(
|
||||
"context",
|
||||
[
|
||||
"getSomething",
|
||||
"getDomainObject",
|
||||
"getDomainObjectArray"
|
||||
]
|
||||
);
|
||||
mockTestObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getModel", "getCapability" ]
|
||||
);
|
||||
factory = {
|
||||
getEditableObject: function (v) {
|
||||
return {
|
||||
isFromTestFactory: true,
|
||||
calledWith: v
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
someValue = { x: 42 };
|
||||
|
||||
mockContext.getSomething.andReturn(someValue);
|
||||
mockContext.getDomainObject.andReturn(mockTestObject);
|
||||
mockContext.getDomainObjectArray.andReturn([mockTestObject]);
|
||||
|
||||
capability = new EditableContextCapability(
|
||||
mockContext,
|
||||
mockEditableObject,
|
||||
mockDomainObject,
|
||||
factory
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
it("wraps retrieved domain objects", function () {
|
||||
var object = capability.getDomainObject();
|
||||
expect(object.isFromTestFactory).toBe(true);
|
||||
expect(object.calledWith).toEqual(mockTestObject);
|
||||
});
|
||||
|
||||
it("wraps retrieved domain object arrays", function () {
|
||||
var object = capability.getDomainObjectArray()[0];
|
||||
expect(object.isFromTestFactory).toBe(true);
|
||||
expect(object.calledWith).toEqual(mockTestObject);
|
||||
});
|
||||
|
||||
it("does not wrap non-domain-objects", function () {
|
||||
expect(capability.getSomething()).toEqual(someValue);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
@ -6,6 +6,48 @@ define(
|
||||
"use strict";
|
||||
|
||||
describe("An editable persistence capability", function () {
|
||||
var mockPersistence,
|
||||
mockEditableObject,
|
||||
mockDomainObject,
|
||||
mockCache,
|
||||
capability;
|
||||
|
||||
beforeEach(function () {
|
||||
mockPersistence = jasmine.createSpyObj(
|
||||
"persistence",
|
||||
[ "persist" ]
|
||||
);
|
||||
mockEditableObject = jasmine.createSpyObj(
|
||||
"editableObject",
|
||||
[ "getId", "getModel", "getCapability" ]
|
||||
);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"editableObject",
|
||||
[ "getId", "getModel", "getCapability" ]
|
||||
);
|
||||
mockCache = jasmine.createSpyObj(
|
||||
"cache",
|
||||
[ "markDirty" ]
|
||||
);
|
||||
|
||||
capability = new EditablePersistenceCapability(
|
||||
mockPersistence,
|
||||
mockEditableObject,
|
||||
mockDomainObject,
|
||||
mockCache
|
||||
);
|
||||
});
|
||||
|
||||
it("marks objects as dirty (in the cache) upon persist", function () {
|
||||
capability.persist();
|
||||
expect(mockCache.markDirty)
|
||||
.toHaveBeenCalledWith(mockEditableObject);
|
||||
});
|
||||
|
||||
it("does not invoke the underlying persistence capability", function () {
|
||||
capability.persist();
|
||||
expect(mockPersistence.persist).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
@ -1,11 +1,106 @@
|
||||
/*global define,describe,it,expect,beforeEach,jasmine*/
|
||||
/*global define,describe,it,expect,beforeEach,waitsFor,runs,jasmine*/
|
||||
|
||||
define(
|
||||
["../../src/capabilities/EditableContextCapability"],
|
||||
function (EditableContextCapability) {
|
||||
["../../src/capabilities/EditorCapability"],
|
||||
function (EditorCapability) {
|
||||
"use strict";
|
||||
|
||||
describe("An editable context capability", function () {
|
||||
var mockPersistence,
|
||||
mockEditableObject,
|
||||
mockDomainObject,
|
||||
mockCache,
|
||||
mockCallback,
|
||||
model,
|
||||
capability;
|
||||
|
||||
beforeEach(function () {
|
||||
mockPersistence = jasmine.createSpyObj(
|
||||
"persistence",
|
||||
[ "persist" ]
|
||||
);
|
||||
mockEditableObject = {
|
||||
getModel: function () { return model; }
|
||||
};
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getModel", "getCapability", "useCapability" ]
|
||||
);
|
||||
mockCache = jasmine.createSpyObj(
|
||||
"cache",
|
||||
[ "saveAll", "markClean" ]
|
||||
);
|
||||
mockCallback = jasmine.createSpy("callback");
|
||||
|
||||
model = { someKey: "some value", x: 42 };
|
||||
|
||||
capability = new EditorCapability(
|
||||
mockPersistence,
|
||||
mockEditableObject,
|
||||
mockDomainObject,
|
||||
mockCache
|
||||
);
|
||||
});
|
||||
|
||||
it("mutates the real domain object on save", function () {
|
||||
capability.save().then(mockCallback);
|
||||
|
||||
// Wait for promise to resolve
|
||||
waitsFor(function () {
|
||||
return mockCallback.calls.length > 0;
|
||||
}, 250);
|
||||
|
||||
runs(function () {
|
||||
expect(mockDomainObject.useCapability)
|
||||
.toHaveBeenCalledWith("mutation", jasmine.any(Function));
|
||||
// We should get the model from the editable object back
|
||||
expect(
|
||||
mockDomainObject.useCapability.mostRecentCall.args[1]()
|
||||
).toEqual(model);
|
||||
});
|
||||
});
|
||||
|
||||
it("marks the saved object as clean in the editing cache", function () {
|
||||
capability.save().then(mockCallback);
|
||||
|
||||
// Wait for promise to resolve
|
||||
waitsFor(function () {
|
||||
return mockCallback.calls.length > 0;
|
||||
}, 250);
|
||||
|
||||
runs(function () {
|
||||
expect(mockCache.markClean).toHaveBeenCalledWith(mockEditableObject);
|
||||
});
|
||||
});
|
||||
|
||||
it("tells the cache to save others", function () {
|
||||
capability.save().then(mockCallback);
|
||||
|
||||
// Wait for promise to resolve
|
||||
waitsFor(function () {
|
||||
return mockCallback.calls.length > 0;
|
||||
}, 250);
|
||||
|
||||
runs(function () {
|
||||
expect(mockCache.saveAll).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it("has no interactions on cancel", function () {
|
||||
capability.cancel().then(mockCallback);
|
||||
|
||||
// Wait for promise to resolve
|
||||
waitsFor(function () {
|
||||
return mockCallback.calls.length > 0;
|
||||
}, 250);
|
||||
|
||||
runs(function () {
|
||||
expect(mockDomainObject.useCapability).not.toHaveBeenCalled();
|
||||
expect(mockCache.markClean).not.toHaveBeenCalled();
|
||||
expect(mockCache.saveAll).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user