[Views] Warn if view omits key

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.
This commit is contained in:
Victor Woeltjen
2015-01-06 10:14:38 -08:00
parent 0ef6c59643
commit 13f552ae81
3 changed files with 40 additions and 3 deletions

View File

@@ -25,6 +25,7 @@ define(
delegates = {},
delegation,
mockDomainObject = {},
mockLog,
provider;
beforeEach(function () {
@@ -38,6 +39,7 @@ define(
mockDomainObject.useCapability = function (c, v) {
return capabilities[c] && capabilities[c].invoke(v);
};
mockLog = jasmine.createSpyObj("$log", ["warn", "info", "debug"]);
capabilities = {};
delegates = {};
@@ -48,7 +50,7 @@ define(
}
};
provider = new ViewProvider([viewA, viewB, viewC]);
provider = new ViewProvider([viewA, viewB, viewC], mockLog);
});
it("reports views provided as extensions", function () {
@@ -71,6 +73,20 @@ define(
.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));
});
});
}
);