diff --git a/war/src/main/js/util/jenkins.js b/war/src/main/js/util/jenkins.js index a16bd8df3ccfd866552bd2e8376e2577e3924be0..b5aa8d0e76afd76b5cac23e228b5cf929b9d1890 100644 --- a/war/src/main/js/util/jenkins.js +++ b/war/src/main/js/util/jenkins.js @@ -1,8 +1,9 @@ /** * Jenkins JS Modules common utility functions */ -import $ from 'jquery' -import wh from 'window-handle' +import $ from 'jquery'; +import wh from 'window-handle'; +import Handlebars from 'handlebars'; var debug = false; var jenkins = {}; @@ -130,6 +131,13 @@ jenkins.post = function(url, data, success, options) { $.ajax(args); }; +/** + * handlebars setup, done for backwards compatibility because some plugins depend on it + */ +jenkins.initHandlebars = function() { + return Handlebars; +} + /** * Load translations for the given bundle ID, provide the message object to the handler. * Optional error handler as the last argument. diff --git a/war/src/test/js/pluginSetupWizard.spec.js b/war/src/test/js/pluginSetupWizard.spec.js index d1a707641d2bba3d0415265cf6b9f6c3cb3b70b6..6725c2333c8a895a868e98404c14f3f696bb84bd 100644 --- a/war/src/test/js/pluginSetupWizard.spec.js +++ b/war/src/test/js/pluginSetupWizard.spec.js @@ -505,4 +505,40 @@ describe("pluginSetupWizard.js", function () { goButton.click(); }, { ajaxMappings, $, $body }); }); + + describe('running extension callbacks', function () { + beforeEach(() => { + global.setupWizardExtensions = []; + global.onSetupWizardInitialized = function(extension) { + setupWizardExtensions.push(extension); + }; + + }); + + afterEach(() => { + delete global.setupWizardExtensions; + delete global.onSetupWizardInitialized; + }); + + it ('yields a jenkins object with the initHandlebars method', function(done) { + jsTest.onPage(function() { + + $.ajax = ajaxMocks(); + + onSetupWizardInitialized(wizard => { + const { jenkins } = wizard; + expect(jenkins).toBe(getJenkins()); + + // Test that the initHandlebars method returns a Handlebars instance + const handlebars = jenkins.initHandlebars(); + expect(handlebars.registerHelper).toBeInstanceOf(Function) + + done(); + }) + + const pluginSetupWizard = getSetupWizardGui(); + pluginSetupWizard.init($body); + }); + }); + }); });