mirror of
https://github.com/nasa/openmct.git
synced 2025-03-12 23:44:08 +00:00
[Representation] Update spec for mct-representation
...to reflect changes to data binding.
This commit is contained in:
parent
756e445a80
commit
1781e9be32
@ -44,6 +44,7 @@ define(
|
|||||||
mockChangeTemplate,
|
mockChangeTemplate,
|
||||||
mockScope,
|
mockScope,
|
||||||
mockElement,
|
mockElement,
|
||||||
|
testAttrs,
|
||||||
mockDomainObject,
|
mockDomainObject,
|
||||||
testModel,
|
testModel,
|
||||||
mctRepresentation;
|
mctRepresentation;
|
||||||
@ -57,7 +58,7 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fireWatch(expr, value) {
|
function fireWatch(expr, value) {
|
||||||
mockScope.$watch.calls.forEach(function (call) {
|
mockScope.$parent.$watch.calls.forEach(function (call) {
|
||||||
if (call.args[0] === expr) {
|
if (call.args[0] === expr) {
|
||||||
call.args[1](value);
|
call.args[1](value);
|
||||||
}
|
}
|
||||||
@ -102,6 +103,11 @@ define(
|
|||||||
testUrls[t.key] = "some URL " + String(i);
|
testUrls[t.key] = "some URL " + String(i);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testAttrs = {
|
||||||
|
"mctObject": "someExpr",
|
||||||
|
"key": "someOtherExpr"
|
||||||
|
};
|
||||||
|
|
||||||
mockRepresenters = ["A", "B"].map(function (name) {
|
mockRepresenters = ["A", "B"].map(function (name) {
|
||||||
var constructor = jasmine.createSpy("Representer" + name),
|
var constructor = jasmine.createSpy("Representer" + name),
|
||||||
representer = jasmine.createSpyObj(
|
representer = jasmine.createSpyObj(
|
||||||
@ -121,6 +127,8 @@ define(
|
|||||||
mockLog = jasmine.createSpyObj("$log", LOG_FUNCTIONS);
|
mockLog = jasmine.createSpyObj("$log", LOG_FUNCTIONS);
|
||||||
|
|
||||||
mockScope = jasmine.createSpyObj("scope", [ "$watch", "$on" ]);
|
mockScope = jasmine.createSpyObj("scope", [ "$watch", "$on" ]);
|
||||||
|
mockScope.$parent =
|
||||||
|
jasmine.createSpyObj('parent', ['$watch', '$eval']);
|
||||||
mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS);
|
mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS);
|
||||||
mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS);
|
mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS);
|
||||||
|
|
||||||
@ -138,7 +146,7 @@ define(
|
|||||||
mockLinker,
|
mockLinker,
|
||||||
mockLog
|
mockLog
|
||||||
);
|
);
|
||||||
mctRepresentation.link(mockScope, mockElement);
|
mctRepresentation.link(mockScope, mockElement, testAttrs);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("is restricted to elements", function () {
|
it("is restricted to elements", function () {
|
||||||
@ -150,15 +158,7 @@ define(
|
|||||||
.toHaveBeenCalledWith(mockScope, mockElement);
|
.toHaveBeenCalledWith(mockScope, mockElement);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("watches scope when linked", function () {
|
it("watches for model changes when linked", function () {
|
||||||
expect(mockScope.$watch).toHaveBeenCalledWith(
|
|
||||||
"key",
|
|
||||||
jasmine.any(Function)
|
|
||||||
);
|
|
||||||
expect(mockScope.$watch).toHaveBeenCalledWith(
|
|
||||||
"domainObject",
|
|
||||||
jasmine.any(Function)
|
|
||||||
);
|
|
||||||
expect(mockScope.$watch).toHaveBeenCalledWith(
|
expect(mockScope.$watch).toHaveBeenCalledWith(
|
||||||
"domainObject.getModel().modified",
|
"domainObject.getModel().modified",
|
||||||
jasmine.any(Function)
|
jasmine.any(Function)
|
||||||
@ -166,24 +166,16 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("recognizes keys for representations", function () {
|
it("recognizes keys for representations", function () {
|
||||||
mockScope.key = "abc";
|
fireWatch(testAttrs.key, "abc");
|
||||||
mockScope.domainObject = mockDomainObject;
|
fireWatch(testAttrs.mctObject, mockDomainObject);
|
||||||
|
|
||||||
// Trigger the watch
|
|
||||||
fireWatch('key', mockScope.key);
|
|
||||||
fireWatch('domainObject', mockDomainObject);
|
|
||||||
|
|
||||||
expect(mockChangeTemplate)
|
expect(mockChangeTemplate)
|
||||||
.toHaveBeenCalledWith(testUrls.abc);
|
.toHaveBeenCalledWith(testUrls.abc);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("recognizes keys for views", function () {
|
it("recognizes keys for views", function () {
|
||||||
mockScope.key = "xyz";
|
fireWatch(testAttrs.key, "xyz");
|
||||||
mockScope.domainObject = mockDomainObject;
|
fireWatch(testAttrs.mctObject, mockDomainObject);
|
||||||
|
|
||||||
// Trigger the watches
|
|
||||||
fireWatch('key', mockScope.key);
|
|
||||||
fireWatch('domainObject', mockDomainObject);
|
|
||||||
|
|
||||||
expect(mockChangeTemplate)
|
expect(mockChangeTemplate)
|
||||||
.toHaveBeenCalledWith(testUrls.xyz);
|
.toHaveBeenCalledWith(testUrls.xyz);
|
||||||
@ -192,25 +184,20 @@ define(
|
|||||||
it("does not load templates until there is an object", function () {
|
it("does not load templates until there is an object", function () {
|
||||||
mockScope.key = "xyz";
|
mockScope.key = "xyz";
|
||||||
|
|
||||||
// Trigger the watch
|
fireWatch(testAttrs.key, "xyz");
|
||||||
fireWatch('key', mockScope.key);
|
|
||||||
|
|
||||||
expect(mockChangeTemplate)
|
expect(mockChangeTemplate)
|
||||||
.not.toHaveBeenCalledWith(jasmine.any(String));
|
.not.toHaveBeenCalledWith(jasmine.any(String));
|
||||||
|
|
||||||
mockScope.domainObject = mockDomainObject;
|
fireWatch(testAttrs.mctObject, mockDomainObject);
|
||||||
fireWatch('domainObject', mockDomainObject);
|
|
||||||
|
|
||||||
expect(mockChangeTemplate)
|
expect(mockChangeTemplate)
|
||||||
.toHaveBeenCalledWith(jasmine.any(String));
|
.toHaveBeenCalledWith(jasmine.any(String));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("loads declared capabilities", function () {
|
it("loads declared capabilities", function () {
|
||||||
mockScope.key = "def";
|
fireWatch(testAttrs.key, "def");
|
||||||
mockScope.domainObject = mockDomainObject;
|
fireWatch(testAttrs.mctObject, mockDomainObject);
|
||||||
|
|
||||||
// Trigger the watch
|
|
||||||
mockScope.$watch.calls[0].args[1]();
|
|
||||||
|
|
||||||
expect(mockDomainObject.useCapability)
|
expect(mockDomainObject.useCapability)
|
||||||
.toHaveBeenCalledWith("testCapability");
|
.toHaveBeenCalledWith("testCapability");
|
||||||
@ -219,32 +206,27 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("logs when no representation is available for a key", function () {
|
it("logs when no representation is available for a key", function () {
|
||||||
mockScope.key = "someUnknownThing";
|
|
||||||
|
|
||||||
// Verify precondition
|
// Verify precondition
|
||||||
expect(mockLog.warn).not.toHaveBeenCalled();
|
expect(mockLog.warn).not.toHaveBeenCalled();
|
||||||
|
|
||||||
// Trigger the watch
|
// Trigger the watch
|
||||||
mockScope.$watch.calls[0].args[1]();
|
fireWatch(testAttrs.key, "someUnkownThing");
|
||||||
|
|
||||||
// Should have gotten a warning - that's an unknown key
|
// Should have gotten a warning - that's an unknown key
|
||||||
expect(mockLog.warn).toHaveBeenCalled();
|
expect(mockLog.warn).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("clears out obsolete peroperties from scope", function () {
|
it("clears out obsolete peroperties from scope", function () {
|
||||||
mockScope.key = "def";
|
|
||||||
mockScope.domainObject = mockDomainObject;
|
|
||||||
mockDomainObject.useCapability.andReturn("some value");
|
mockDomainObject.useCapability.andReturn("some value");
|
||||||
|
|
||||||
// Trigger the watch
|
// Trigger the watch
|
||||||
mockScope.$watch.calls[0].args[1]();
|
fireWatch(testAttrs.key, "def");
|
||||||
|
fireWatch(testAttrs.mctObject, mockDomainObject);
|
||||||
expect(mockScope.testCapability).toBeDefined();
|
expect(mockScope.testCapability).toBeDefined();
|
||||||
|
|
||||||
// Change the view
|
// Change the view; should clear capabilities from scope
|
||||||
mockScope.key = "xyz";
|
fireWatch(testAttrs.key, "xyz");
|
||||||
|
|
||||||
// Trigger the watch again; should clear capability from scope
|
|
||||||
mockScope.$watch.calls[0].args[1]();
|
|
||||||
expect(mockScope.testCapability).toBeUndefined();
|
expect(mockScope.testCapability).toBeUndefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user