[Framework] Add/update tests for sorting

Add/update framework tests to include the sorting of extensions
by priority, WTD-590.
This commit is contained in:
Victor Woeltjen
2015-01-07 17:06:09 -08:00
parent 9d8885d48f
commit 64ede1e917
3 changed files with 79 additions and 1 deletions

View File

@@ -11,14 +11,24 @@ define(
describe("The extension registrar", function () {
var mockApp,
mockLog,
mockSorter,
customRegistrars,
registrar;
beforeEach(function () {
mockApp = jasmine.createSpyObj("app", ["factory"]);
mockLog = jasmine.createSpyObj("$log", ["error", "warn", "debug", "info"]);
mockSorter = jasmine.createSpyObj("sorter", ["sort"]);
customRegistrars = {};
registrar = new ExtensionRegistrar(mockApp, customRegistrars, mockLog);
mockSorter.sort.andCallFake(function (v) { return v; });
registrar = new ExtensionRegistrar(
mockApp,
customRegistrars,
mockSorter,
mockLog
);
});
it("registers extensions using the factory", function () {
@@ -64,6 +74,23 @@ define(
expect(customRegistrars.things).toHaveBeenCalled();
});
it("sorts extensions before registering", function () {
// Some extension definitions to sort
var a = { a: 'a' }, b = { b: 'b' }, c = { c: 'c' };
// Fake sorting; just reverse the array
mockSorter.sort.andCallFake(function (v) { return v.reverse(); });
// Register the extensions
registrar.registerExtensions({ things: [ a, b, c ] });
// Verify registration interactions occurred in reverse-order
[ c, b, a ].forEach(function (extension, index) {
expect(mockApp.factory.calls[index].args[1][0]())
.toEqual(extension);
});
});
});
}
);