提交 60a0816c 编写于 作者: F Félix Queiruga

Fix: broken interface of the jenkins object yielded by the setupWizard

- Callbacks registered with `onSetupWizardInitialized` are yielded a `wizard` parameter, that contained a reference to the jenkins object.
- Some plugins called the method `jenkins.initHandlebars` from this callback, to receive a Handlebars intance.
- Added a unit test to ensure this regression does not happen again
上级 d1b833de
/**
* 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.
......
......@@ -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);
});
});
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册