mirror of
https://github.com/nasa/openmct.git
synced 2025-06-19 15:43:48 +00:00
[Framework] Add test case for BundleLoader
Add a test case for BundleLoader, to improve test coverage of framework layer. WTD-518.
This commit is contained in:
@ -23,15 +23,11 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
testBundles = [
|
testBundles = {
|
||||||
{
|
"bundles.json": [ "bundle/a", "bundle/b"],
|
||||||
|
"bundle/a/bundle.json": {"someValue": 6},
|
||||||
},
|
"bundle/b/bundle.json": {"someValue": 7}
|
||||||
{
|
};
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
];
|
|
||||||
|
|
||||||
mockCallback = jasmine.createSpy("callback");
|
mockCallback = jasmine.createSpy("callback");
|
||||||
mockHttp = jasmine.createSpyObj("$http", ["get"]);
|
mockHttp = jasmine.createSpyObj("$http", ["get"]);
|
||||||
@ -40,13 +36,13 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("accepts a JSON file name and loads all bundles", function () {
|
it("accepts a JSON file name and loads all bundles", function () {
|
||||||
// Set up; just return an empty set of bundles for this test
|
// Set up; return named bundles
|
||||||
mockHttp.get.andReturn(Promise.resolve({data: []}));
|
mockHttp.get.andReturn(Promise.resolve({ data: [] }));
|
||||||
|
|
||||||
// Call load bundles
|
// Call load bundles
|
||||||
loader.loadBundles("test-filename.json").then(mockCallback);
|
loader.loadBundles("test-filename.json").then(mockCallback);
|
||||||
|
|
||||||
waitsFor(mockCallbackResolved, "then-chain resolution", 100);
|
waitsFor(mockCallbackResolved, "then-chain resolution", 500);
|
||||||
|
|
||||||
runs(function () {
|
runs(function () {
|
||||||
// Should have loaded the file via $http
|
// Should have loaded the file via $http
|
||||||
@ -57,6 +53,31 @@ define(
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("accepts a list of bundle paths", function () {
|
||||||
|
// Set up; return named bundles
|
||||||
|
mockHttp.get.andCallFake(function (name) {
|
||||||
|
return Promise.resolve({data: testBundles[name]});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Call load bundles
|
||||||
|
loader.loadBundles(["bundle/a", "bundle/b"]).then(mockCallback);
|
||||||
|
|
||||||
|
waitsFor(mockCallbackResolved, "then-chain resolution", 500);
|
||||||
|
|
||||||
|
runs(function () {
|
||||||
|
// Should have gotten back two bundles
|
||||||
|
expect(mockCallback.mostRecentCall.args[0].length).toEqual(2);
|
||||||
|
|
||||||
|
// They should have the values we expect; don't care about order,
|
||||||
|
// some map/reduce the summation.
|
||||||
|
expect(mockCallback.mostRecentCall.args[0].map(function (call) {
|
||||||
|
return call.getDefinition().someValue;
|
||||||
|
}).reduce(function (a, b) {
|
||||||
|
return a + b;
|
||||||
|
}, 0)).toEqual(13);
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user