mirror of
https://github.com/nasa/openmct.git
synced 2025-01-19 11:17:04 +00:00
[Core] Spec for view provider, capability
Add spec for view provider and capability to complete test coverage of the transitioned platform/core bundle. WTD-573.
This commit is contained in:
parent
84c7f3d71d
commit
2b27c1cabc
@ -9,6 +9,30 @@ define(
|
||||
"use strict";
|
||||
|
||||
describe("A view capability", function () {
|
||||
var mockViewService,
|
||||
mockDomainObject,
|
||||
views = [ {key: "someView"} ],
|
||||
view;
|
||||
|
||||
beforeEach(function () {
|
||||
mockViewService = jasmine.createSpyObj(
|
||||
"viewService",
|
||||
[ "getViews" ]
|
||||
);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getModel", "getCapability" ]
|
||||
);
|
||||
mockViewService.getViews.andReturn(views);
|
||||
view = new ViewCapability(mockViewService, mockDomainObject);
|
||||
});
|
||||
|
||||
it("issues invocations to the view service", function () {
|
||||
expect(view.invoke()).toEqual(views);
|
||||
expect(mockViewService.getViews).toHaveBeenCalledWith(
|
||||
mockDomainObject
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
@ -9,6 +9,67 @@ define(
|
||||
"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 = {},
|
||||
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);
|
||||
};
|
||||
|
||||
capabilities = {};
|
||||
delegates = {};
|
||||
|
||||
delegation = {
|
||||
doesDelegateCapability: function (c) {
|
||||
return delegates[c] !== undefined;
|
||||
}
|
||||
};
|
||||
|
||||
provider = new ViewProvider([viewA, viewB, viewC]);
|
||||
});
|
||||
|
||||
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]);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user