mirror of
https://github.com/nasa/openmct.git
synced 2025-05-05 10:13:07 +00:00
[Layout] Fill in non-layout specs
Complete specs for scripts introduced in support of Layout objects/views. WTD-535.
This commit is contained in:
parent
d3f0505385
commit
ecb4283df0
@ -5,17 +5,15 @@ define(
|
|||||||
function () {
|
function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function EditRepresenter($q, scope, element, attrs) {
|
function EditRepresenter($q, scope) {
|
||||||
var watches = [],
|
var watches = [],
|
||||||
domainObject,
|
domainObject,
|
||||||
key;
|
key;
|
||||||
|
|
||||||
function doPersist(model) {
|
function doPersist(model) {
|
||||||
return $q.when(function () {
|
return $q.when(domainObject.useCapability("mutation", function () {
|
||||||
return domainObject.useCapability("mutation", function () {
|
return model;
|
||||||
return model;
|
})).then(function (result) {
|
||||||
});
|
|
||||||
}).then(function (result) {
|
|
||||||
return result &&
|
return result &&
|
||||||
domainObject.getCapability("persistence").persist();
|
domainObject.getCapability("persistence").persist();
|
||||||
});
|
});
|
||||||
@ -23,12 +21,13 @@ define(
|
|||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
var model = scope.model,
|
var model = scope.model,
|
||||||
configuration = scope.configuration,
|
configuration = scope.configuration;
|
||||||
key = scope.key;
|
|
||||||
|
|
||||||
if (domainObject && domainObject.hasCapability("persistence")) {
|
if (domainObject && domainObject.hasCapability("persistence")) {
|
||||||
model.configuration = model.configuration || {};
|
if (key && configuration) {
|
||||||
model.configuration[key] = configuration;
|
model.configuration = model.configuration || {};
|
||||||
|
model.configuration[key] = configuration;
|
||||||
|
}
|
||||||
doPersist(model);
|
doPersist(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,91 @@ define(
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("The Edit mode representer", function () {
|
describe("The Edit mode representer", function () {
|
||||||
|
var mockQ,
|
||||||
|
mockScope,
|
||||||
|
testRepresentation,
|
||||||
|
mockDomainObject,
|
||||||
|
mockPersistence,
|
||||||
|
representer;
|
||||||
|
|
||||||
|
function mockPromise(value) {
|
||||||
|
return {
|
||||||
|
then: function (callback) {
|
||||||
|
return mockPromise(callback(value));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
mockQ = { when: mockPromise };
|
||||||
|
mockScope = jasmine.createSpyObj("$scope", ["$watch"]);
|
||||||
|
testRepresentation = { key: "test" };
|
||||||
|
mockDomainObject = jasmine.createSpyObj("domainObject", [
|
||||||
|
"getId",
|
||||||
|
"getModel",
|
||||||
|
"getCapability",
|
||||||
|
"useCapability",
|
||||||
|
"hasCapability"
|
||||||
|
]);
|
||||||
|
mockPersistence =
|
||||||
|
jasmine.createSpyObj("persistence", ["persist"]);
|
||||||
|
|
||||||
|
mockDomainObject.hasCapability.andReturn(true);
|
||||||
|
mockDomainObject.useCapability.andReturn(true);
|
||||||
|
mockDomainObject.getCapability.andReturn(mockPersistence);
|
||||||
|
|
||||||
|
representer = new EditRepresenter(mockQ, mockScope);
|
||||||
|
representer.represent(testRepresentation, mockDomainObject);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("watches for changes in view configuration", function () {
|
||||||
|
// Should watch the configuration field,
|
||||||
|
// provided by mct-representation
|
||||||
|
expect(mockScope.$watch).toHaveBeenCalledWith(
|
||||||
|
"configuration",
|
||||||
|
jasmine.any(Function),
|
||||||
|
true // should be a deep watch
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("watches for changes in domain object model", function () {
|
||||||
|
// Should watch the model field,
|
||||||
|
// provided by mct-representation
|
||||||
|
expect(mockScope.$watch).toHaveBeenCalledWith(
|
||||||
|
"model",
|
||||||
|
jasmine.any(Function),
|
||||||
|
true // should be a deep watch
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("mutates and persists upon observed changes", function () {
|
||||||
|
mockScope.model = { someKey: "some value" };
|
||||||
|
mockScope.configuration = { someConfiguration: "something" };
|
||||||
|
|
||||||
|
mockScope.$watch.mostRecentCall.args[1].call();
|
||||||
|
|
||||||
|
// Should have mutated the object...
|
||||||
|
expect(mockDomainObject.useCapability).toHaveBeenCalledWith(
|
||||||
|
"mutation",
|
||||||
|
jasmine.any(Function)
|
||||||
|
);
|
||||||
|
|
||||||
|
// ... and should have persisted the mutation
|
||||||
|
expect(mockPersistence.persist).toHaveBeenCalled();
|
||||||
|
|
||||||
|
// Finally, check that the provided mutation function
|
||||||
|
// includes both model and configuratioon
|
||||||
|
expect(
|
||||||
|
mockDomainObject.useCapability.mostRecentCall.args[1]()
|
||||||
|
).toEqual({
|
||||||
|
someKey: "some value",
|
||||||
|
configuration: {
|
||||||
|
test: { someConfiguration: "something" }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
@ -5,7 +5,125 @@ define(
|
|||||||
function (MCTDrag) {
|
function (MCTDrag) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var JQLITE_METHODS = [ "on", "off", "find" ];
|
||||||
|
|
||||||
describe("The mct-drag directive", function () {
|
describe("The mct-drag directive", function () {
|
||||||
|
var mockDocument,
|
||||||
|
mockScope,
|
||||||
|
mockElement,
|
||||||
|
testAttrs,
|
||||||
|
mockBody,
|
||||||
|
mctDrag;
|
||||||
|
|
||||||
|
function testEvent(x, y) {
|
||||||
|
return {
|
||||||
|
pageX: x,
|
||||||
|
pageY: y,
|
||||||
|
preventDefault: jasmine.createSpy("preventDefault")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
mockDocument =
|
||||||
|
jasmine.createSpyObj("$document", JQLITE_METHODS);
|
||||||
|
mockScope =
|
||||||
|
jasmine.createSpyObj("$scope", [ "$eval", "$apply" ]);
|
||||||
|
mockElement =
|
||||||
|
jasmine.createSpyObj("element", JQLITE_METHODS);
|
||||||
|
mockBody =
|
||||||
|
jasmine.createSpyObj("body", JQLITE_METHODS);
|
||||||
|
|
||||||
|
testAttrs = {
|
||||||
|
mctDragDown: "starting a drag",
|
||||||
|
mctDrag: "continuing a drag",
|
||||||
|
mctDragUp: "ending a drag"
|
||||||
|
};
|
||||||
|
|
||||||
|
mockDocument.find.andReturn(mockBody);
|
||||||
|
|
||||||
|
mctDrag = new MCTDrag(mockDocument);
|
||||||
|
mctDrag.link(mockScope, mockElement, testAttrs);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("is valid as an attribute", function () {
|
||||||
|
expect(mctDrag.restrict).toEqual("A");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("listens for mousedown on its element", function () {
|
||||||
|
expect(mockElement.on).toHaveBeenCalledWith(
|
||||||
|
"mousedown",
|
||||||
|
jasmine.any(Function)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Verify no interactions with body as well
|
||||||
|
expect(mockBody.on).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("invokes mctDragDown when dragging begins", function () {
|
||||||
|
mockElement.on.mostRecentCall.args[1](testEvent(42, 60));
|
||||||
|
expect(mockScope.$eval).toHaveBeenCalledWith(
|
||||||
|
testAttrs.mctDragDown,
|
||||||
|
{ delta: [0, 0] }
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("listens for mousemove after dragging begins", function () {
|
||||||
|
mockElement.on.mostRecentCall.args[1](testEvent(42, 60));
|
||||||
|
expect(mockBody.on).toHaveBeenCalledWith(
|
||||||
|
"mousemove",
|
||||||
|
jasmine.any(Function)
|
||||||
|
);
|
||||||
|
expect(mockBody.on).toHaveBeenCalledWith(
|
||||||
|
"mouseup",
|
||||||
|
jasmine.any(Function)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("invokes mctDrag expression during drag", function () {
|
||||||
|
mockElement.on.mostRecentCall.args[1](testEvent(42, 60));
|
||||||
|
|
||||||
|
// Find and invoke the mousemove listener
|
||||||
|
mockBody.on.calls.forEach(function (call) {
|
||||||
|
if (call.args[0] === 'mousemove') {
|
||||||
|
call.args[1](testEvent(52, 200));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Should have passed that delta to mct-drag expression
|
||||||
|
expect(mockScope.$eval).toHaveBeenCalledWith(
|
||||||
|
testAttrs.mctDrag,
|
||||||
|
{ delta: [10, 140] }
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("invokes mctDragUp expression after drag", function () {
|
||||||
|
mockElement.on.mostRecentCall.args[1](testEvent(42, 60));
|
||||||
|
|
||||||
|
// Find and invoke the mousemove listener
|
||||||
|
mockBody.on.calls.forEach(function (call) {
|
||||||
|
if (call.args[0] === 'mousemove') {
|
||||||
|
call.args[1](testEvent(52, 200));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Find and invoke the mousemove listener
|
||||||
|
mockBody.on.calls.forEach(function (call) {
|
||||||
|
if (call.args[0] === 'mouseup') {
|
||||||
|
call.args[1](testEvent(40, 71));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Should have passed that delta to mct-drag-up expression
|
||||||
|
// and that delta should have been relative to the
|
||||||
|
// initial position
|
||||||
|
expect(mockScope.$eval).toHaveBeenCalledWith(
|
||||||
|
testAttrs.mctDragUp,
|
||||||
|
{ delta: [-2, 11] }
|
||||||
|
);
|
||||||
|
|
||||||
|
// Should also have unregistered listeners
|
||||||
|
expect(mockBody.off).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
@ -6,31 +6,56 @@ define(
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("A gesture representer", function () {
|
describe("A gesture representer", function () {
|
||||||
|
var mockGestureService,
|
||||||
|
mockGestureHandle,
|
||||||
|
mockScope,
|
||||||
|
mockElement,
|
||||||
|
representer;
|
||||||
|
|
||||||
// it("attaches declared gestures, and detaches on refresh", function () {
|
beforeEach(function () {
|
||||||
// mctRepresentation.link(mockScope, mockElement);
|
mockGestureService = jasmine.createSpyObj(
|
||||||
//
|
"gestureService",
|
||||||
// mockScope.key = "uvw";
|
[ "attachGestures" ]
|
||||||
// mockScope.domainObject = mockDomainObject;
|
);
|
||||||
//
|
mockGestureHandle = jasmine.createSpyObj(
|
||||||
// // Trigger the watch
|
"gestureHandle",
|
||||||
// mockScope.$watch.mostRecentCall.args[1]();
|
[ "destroy" ]
|
||||||
//
|
);
|
||||||
// expect(mockGestureService.attachGestures).toHaveBeenCalledWith(
|
|
||||||
// mockElement,
|
mockElement = { someKey: "some value" };
|
||||||
// mockDomainObject,
|
|
||||||
// [ "testGesture", "otherTestGesture" ]
|
mockGestureService.attachGestures.andReturn(mockGestureHandle);
|
||||||
// );
|
|
||||||
//
|
representer = new GestureRepresenter(
|
||||||
// expect(mockGestureHandle.destroy).not.toHaveBeenCalled();
|
mockGestureService,
|
||||||
//
|
undefined, // Scope is not used
|
||||||
// // Refresh, expect a detach
|
mockElement
|
||||||
// mockScope.key = "abc";
|
);
|
||||||
// mockScope.$watch.mostRecentCall.args[1]();
|
});
|
||||||
//
|
|
||||||
// // Should have destroyed those old gestures
|
it("attaches declared gestures, and detaches on request", function () {
|
||||||
// expect(mockGestureHandle.destroy).toHaveBeenCalled();
|
// Pass in some objects, which we expect to be passed into the
|
||||||
// });
|
// gesture service accordingly.
|
||||||
|
var domainObject = { someOtherKey: "some other value" },
|
||||||
|
representation = { gestures: ["a", "b", "c"] };
|
||||||
|
|
||||||
|
representer.represent(representation, domainObject);
|
||||||
|
|
||||||
|
expect(mockGestureService.attachGestures).toHaveBeenCalledWith(
|
||||||
|
mockElement,
|
||||||
|
domainObject,
|
||||||
|
[ "a", "b", "c" ]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Should not have been destroyed yet...
|
||||||
|
expect(mockGestureHandle.destroy).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
// Destroy
|
||||||
|
representer.destroy();
|
||||||
|
|
||||||
|
// Should have destroyed those old gestures
|
||||||
|
expect(mockGestureHandle.destroy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user