mirror of
https://github.com/nasa/openmct.git
synced 2024-12-24 07:16:39 +00:00
[Views] Add tests for type-view restrictions
Add tests for type-view restrictions added to support stricter coupling of Packet objects to Autoflow Tabular View, WTD-644.
This commit is contained in:
parent
65a0a92133
commit
f9a4ac548c
@ -84,7 +84,7 @@ define(
|
||||
// Check if a view and domain object type can be paired;
|
||||
// both can restrict the others they accept.
|
||||
function viewMatchesType(view, type) {
|
||||
var views = type && type.getDefinition().views,
|
||||
var views = type && (type.getDefinition() || {}).views,
|
||||
matches = true;
|
||||
|
||||
// View is restricted to a certain type
|
||||
|
@ -87,6 +87,57 @@ define(
|
||||
expect(mockLog.warn).toHaveBeenCalledWith(jasmine.any(String));
|
||||
});
|
||||
|
||||
it("restricts typed views to matching types", function () {
|
||||
var testType = "testType",
|
||||
testView = { key: "x", type: testType },
|
||||
provider = new ViewProvider([testView], mockLog);
|
||||
|
||||
// Include a "type" capability
|
||||
capabilities.type = jasmine.createSpyObj(
|
||||
"type",
|
||||
["instanceOf", "invoke", "getDefinition"]
|
||||
);
|
||||
capabilities.type.invoke.andReturn(capabilities.type);
|
||||
|
||||
// Should be included when types match
|
||||
capabilities.type.instanceOf.andReturn(true);
|
||||
expect(provider.getViews(mockDomainObject))
|
||||
.toEqual([testView]);
|
||||
expect(capabilities.type.instanceOf)
|
||||
.toHaveBeenCalledWith(testType);
|
||||
|
||||
// ...but not when they don't
|
||||
capabilities.type.instanceOf.andReturn(false);
|
||||
expect(provider.getViews(mockDomainObject))
|
||||
.toEqual([]);
|
||||
|
||||
});
|
||||
|
||||
it("enforces view restrictions from types", function () {
|
||||
var testType = "testType",
|
||||
testView = { key: "x" },
|
||||
provider = new ViewProvider([testView], mockLog);
|
||||
|
||||
// Include a "type" capability
|
||||
capabilities.type = jasmine.createSpyObj(
|
||||
"type",
|
||||
["instanceOf", "invoke", "getDefinition"]
|
||||
);
|
||||
capabilities.type.invoke.andReturn(capabilities.type);
|
||||
|
||||
// Should be included when view keys match
|
||||
capabilities.type.getDefinition
|
||||
.andReturn({ views: [testView.key]});
|
||||
expect(provider.getViews(mockDomainObject))
|
||||
.toEqual([testView]);
|
||||
|
||||
// ...but not when they don't
|
||||
capabilities.type.getDefinition
|
||||
.andReturn({ views: ["somethingElse"]});
|
||||
expect(provider.getViews(mockDomainObject))
|
||||
.toEqual([]);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
Loading…
Reference in New Issue
Block a user