Warn if a view definition does not include a key, and prune it from the list of views. This avoids an underlying cause of WTD-628, which is fixed for plots specifically in the previous commit but could recur if other views were to omit keys.
92 lines
3.3 KiB
JavaScript
92 lines
3.3 KiB
JavaScript
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
|
|
|
/**
|
|
* ViewProviderSpec. Created by vwoeltje on 11/6/14.
|
|
*/
|
|
define(
|
|
["../../src/views/ViewProvider"],
|
|
function (ViewProvider) {
|
|
"use strict";
|
|
|
|
describe("The view provider", function () {
|
|
var viewA = {
|
|
key: "a"
|
|
},
|
|
viewB = {
|
|
key: "b",
|
|
needs: [ "someCapability" ]
|
|
},
|
|
viewC = {
|
|
key: "c",
|
|
needs: [ "someCapability" ],
|
|
delegation: true
|
|
},
|
|
capabilities = {},
|
|
delegates = {},
|
|
delegation,
|
|
mockDomainObject = {},
|
|
mockLog,
|
|
provider;
|
|
|
|
beforeEach(function () {
|
|
// Simulate the expected API
|
|
mockDomainObject.hasCapability = function (c) {
|
|
return capabilities[c] !== undefined;
|
|
};
|
|
mockDomainObject.getCapability = function (c) {
|
|
return capabilities[c];
|
|
};
|
|
mockDomainObject.useCapability = function (c, v) {
|
|
return capabilities[c] && capabilities[c].invoke(v);
|
|
};
|
|
mockLog = jasmine.createSpyObj("$log", ["warn", "info", "debug"]);
|
|
|
|
capabilities = {};
|
|
delegates = {};
|
|
|
|
delegation = {
|
|
doesDelegateCapability: function (c) {
|
|
return delegates[c] !== undefined;
|
|
}
|
|
};
|
|
|
|
provider = new ViewProvider([viewA, viewB, viewC], mockLog);
|
|
});
|
|
|
|
it("reports views provided as extensions", function () {
|
|
capabilities.someCapability = true;
|
|
expect(provider.getViews(mockDomainObject))
|
|
.toEqual([viewA, viewB, viewC]);
|
|
});
|
|
|
|
it("filters views by needed capabilities", function () {
|
|
//capabilities.someCapability = true;
|
|
expect(provider.getViews(mockDomainObject))
|
|
.toEqual([viewA]);
|
|
});
|
|
|
|
it("allows delegation of needed capabilities when specified", function () {
|
|
//capabilities.someCapability = true;
|
|
capabilities.delegation = delegation;
|
|
delegates.someCapability = true;
|
|
expect(provider.getViews(mockDomainObject))
|
|
.toEqual([viewA, viewC]);
|
|
});
|
|
|
|
it("warns if keys are omitted from views", function () {
|
|
// Verify that initial construction issued no warning
|
|
expect(mockLog.warn).not.toHaveBeenCalled();
|
|
// Recreate with no keys; that view should be filtered out
|
|
expect(
|
|
new ViewProvider(
|
|
[viewA, { some: "bad view" }],
|
|
mockLog
|
|
).getViews(mockDomainObject)
|
|
).toEqual([viewA]);
|
|
// We should have also received a warning, to support debugging
|
|
expect(mockLog.warn).toHaveBeenCalledWith(jasmine.any(String));
|
|
});
|
|
|
|
});
|
|
}
|
|
); |