[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:
Victor Woeltjen 2015-01-07 11:53:32 -08:00
parent 65a0a92133
commit f9a4ac548c
2 changed files with 52 additions and 1 deletions

View File

@ -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

View File

@ -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([]);
});
});
}
);