From dac05d7841090532491efb66c6e2779c2957d685 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 6 Nov 2014 08:23:33 -0800 Subject: [PATCH] [Framework] Spec for ApplicationBootstrapper Add spec for the application bootstrapper; verify its interactions with Angular. WTD-518. --- .../bootstrap/ApplicationBootstrapperSpec.js | 79 ++++++++++++++++++- 1 file changed, 76 insertions(+), 3 deletions(-) diff --git a/platform/framework/test/bootstrap/ApplicationBootstrapperSpec.js b/platform/framework/test/bootstrap/ApplicationBootstrapperSpec.js index 8733cdbbd8..96c16b66ee 100644 --- a/platform/framework/test/bootstrap/ApplicationBootstrapperSpec.js +++ b/platform/framework/test/bootstrap/ApplicationBootstrapperSpec.js @@ -4,11 +4,84 @@ * ApplicationBootstrapperSpec. Created by vwoeltje on 11/6/14. */ define( - [], - function () { + ["../../src/bootstrap/ApplicationBootstrapper"], + function (ApplicationBootstrapper) { "use strict"; - describe("", function () { + describe("The application bootstrapper", function () { + // Test support variables + var bootstrapper, + captured, + mockAngular, + mockDocument, + mockLog, + mockApp; + + // Used to capture arguments to mocks + function capture() { + var names = Array.prototype.slice.apply(arguments, []); + return function () { + var values = arguments; + names.forEach(function (name, index) { + captured[name] = values[index]; + }); + }; + } + + // Set up the mocks before each run + beforeEach(function () { + captured = {}; + + mockAngular = { + element: function (selector) { + captured.selector = selector; + return { ready: capture("callback") }; + }, + bootstrap: capture("element", "appNames") + }; + + mockDocument = "I am just a value."; + + mockLog = { info: capture("info") }; + + mockApp = { name: "MockApp" }; + + bootstrapper = new ApplicationBootstrapper( + mockAngular, + mockDocument, + mockLog + ); + + bootstrapper.bootstrap(mockApp); + }); + + + // The tests. + + it("waits for the provided document element to be ready", function () { + // Should have provided Angular a selector... + expect(captured.selector).toBe(mockDocument); + // ...and called ready on the response. + expect(captured.callback).toBeDefined(); + }); + + it("issues a bootstrap call once ready", function () { + // Verify precondition; bootstrap not called + expect(captured.element).toBeUndefined(); + expect(captured.appNames).toBeUndefined(); + + // Call the "ready" function + captured.callback(); + + // Verify that bootstrap was called + expect(captured.element).toBe(mockDocument); + expect(captured.appNames).toEqual([mockApp.name]); + }); + + it("logs that the bootstrap phase has been reached", function () { + expect(captured.info).toBeDefined(); + expect(typeof captured.info).toEqual('string'); + }); }); }