mirror of
https://github.com/nasa/openmct.git
synced 2024-12-19 13:17:53 +00:00
[Framework] Add spec for ExtensionResolver
WTD-518
This commit is contained in:
parent
69c6811f00
commit
5f7704f1b8
@ -1,14 +1,91 @@
|
|||||||
/*global define,Promise,describe,it,expect,beforeEach*/
|
/*global define,Promise,describe,it,expect,beforeEach,jasmine,waitsFor,runs*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ExtensionResolverSpec. Created by vwoeltje on 11/6/14.
|
* ExtensionResolverSpec. Created by vwoeltje on 11/6/14.
|
||||||
*/
|
*/
|
||||||
define(
|
define(
|
||||||
[],
|
["../../src/resolve/ExtensionResolver", "../../src/load/Bundle"],
|
||||||
function () {
|
function (ExtensionResolver, Bundle) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("", function () {
|
describe("", function () {
|
||||||
|
var mockLoader,
|
||||||
|
mockLog,
|
||||||
|
resolver;
|
||||||
|
|
||||||
|
// Test implementation, to load from the mock loader
|
||||||
|
function Constructor() { return { someKey: "some value" }; }
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
mockLoader = jasmine.createSpyObj("loader", ["load"]);
|
||||||
|
|
||||||
|
mockLog = jasmine.createSpyObj(
|
||||||
|
"$log",
|
||||||
|
["error", "warn", "info", "debug"]
|
||||||
|
);
|
||||||
|
|
||||||
|
mockLoader.load.andReturn(Promise.resolve(Constructor));
|
||||||
|
|
||||||
|
resolver = new ExtensionResolver(mockLoader, mockLog);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("requests implementations from the implementation loader", function () {
|
||||||
|
var bundle = new Bundle("w", {
|
||||||
|
sources: "x",
|
||||||
|
extensions: { tests: [ { implementation: "y/z.js" } ] }
|
||||||
|
}),
|
||||||
|
extension = bundle.getExtensions("tests")[0],
|
||||||
|
result;
|
||||||
|
|
||||||
|
resolver.resolve(extension).then(function (v) { result = v; });
|
||||||
|
|
||||||
|
waitsFor(
|
||||||
|
function () { return result !== undefined; },
|
||||||
|
"promise resolution",
|
||||||
|
250
|
||||||
|
);
|
||||||
|
|
||||||
|
runs(function () {
|
||||||
|
// Verify that the right file was requested
|
||||||
|
expect(mockLoader.load).toHaveBeenCalledWith("w/x/y/z.js");
|
||||||
|
|
||||||
|
// We should have resolved to the constructor from above
|
||||||
|
expect(typeof result).toEqual('function');
|
||||||
|
expect(result().someKey).toEqual("some value");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it("issues a warning and defaults to plain definition if load fails", function () {
|
||||||
|
var bundle = new Bundle("w", {
|
||||||
|
sources: "x",
|
||||||
|
extensions: { tests: [ {
|
||||||
|
someOtherKey: "some other value",
|
||||||
|
implementation: "y/z.js"
|
||||||
|
} ] }
|
||||||
|
}),
|
||||||
|
extension = bundle.getExtensions("tests")[0],
|
||||||
|
result;
|
||||||
|
|
||||||
|
mockLoader.load.andReturn(Promise.reject(new Error("test error")));
|
||||||
|
resolver.resolve(extension).then(function (v) { result = v; });
|
||||||
|
|
||||||
|
waitsFor(
|
||||||
|
function () { return result !== undefined; },
|
||||||
|
"promise resolution",
|
||||||
|
250
|
||||||
|
);
|
||||||
|
|
||||||
|
runs(function () {
|
||||||
|
// Should have gotten a warning
|
||||||
|
expect(mockLog.warn).toHaveBeenCalled();
|
||||||
|
|
||||||
|
// We should have resolved to the plain definition from above
|
||||||
|
expect(typeof result).not.toEqual('function');
|
||||||
|
expect(result.someOtherKey).toEqual("some other value");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user