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

Migrates from requires to imports

- Fixes some related linter errors in the way
上级 e3e04979
...@@ -575,11 +575,9 @@ THE SOFTWARE. ...@@ -575,11 +575,9 @@ THE SOFTWARE.
<!-- <!--
The following profiles are required to integration the node/gulp build into this maven build. The following profiles are required to integration the node/yarn build into this maven build.
Hopefully we can push these profiles down into a parent pom. Hopefully we can push these profiles down into a parent pom.
See https://github.com/tfennelly/jenkins-js-builder#maven-integration
--> -->
<profile> <profile>
<id>yarn-execution</id> <id>yarn-execution</id>
<activation> <activation>
......
...@@ -35,6 +35,7 @@ $.when(getItems()).done(function(data) { ...@@ -35,6 +35,7 @@ $.when(getItems()).done(function(data) {
if (desc.indexOf('&lt;a href="') === -1) { if (desc.indexOf('&lt;a href="') === -1) {
return desc; return desc;
} }
// eslint-disable-next-line
var newDesc = desc.replace(/\&lt;/g,'<').replace(/\&gt;/g,'>'); var newDesc = desc.replace(/\&lt;/g,'<').replace(/\&gt;/g,'>');
return newDesc; return newDesc;
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Provides a wrapper to interact with the security configuration * Provides a wrapper to interact with the security configuration
*/ */
import jenkins from '../util/jenkins'; import jenkins from '../util/jenkins';
import { getWindow } from 'window-handle';
/** /**
* Calls a stapler post method to save the first user settings * Calls a stapler post method to save the first user settings
...@@ -13,13 +14,13 @@ function saveFirstUser($form, success, error) { ...@@ -13,13 +14,13 @@ function saveFirstUser($form, success, error) {
function(response) { function(response) {
var crumbRequestField = response.data.crumbRequestField; var crumbRequestField = response.data.crumbRequestField;
if (crumbRequestField) { if (crumbRequestField) {
require('window-handle').getWindow().crumb.init(crumbRequestField, response.data.crumb); getWindow().crumb.init(crumbRequestField, response.data.crumb);
} }
success(response); success(response);
}, { }, {
error: error error: error
}); });
}; }
function saveConfigureInstance($form, success, error){ function saveConfigureInstance($form, success, error){
jenkins.staplerPost( jenkins.staplerPost(
...@@ -28,13 +29,13 @@ function saveConfigureInstance($form, success, error){ ...@@ -28,13 +29,13 @@ function saveConfigureInstance($form, success, error){
function(response) { function(response) {
var crumbRequestField = response.data.crumbRequestField; var crumbRequestField = response.data.crumbRequestField;
if (crumbRequestField) { if (crumbRequestField) {
require('window-handle').getWindow().crumb.init(crumbRequestField, response.data.crumb); getWindow().crumb.init(crumbRequestField, response.data.crumb);
} }
success(response); success(response);
}, { }, {
error: error error: error
}); });
}; }
/** /**
* Calls a stapler post method to save the first user settings * Calls a stapler post method to save the first user settings
...@@ -47,7 +48,7 @@ function saveProxy($form, success, error) { ...@@ -47,7 +48,7 @@ function saveProxy($form, success, error) {
dataType: 'html', dataType: 'html',
error: error error: error
}); });
}; }
export default { export default {
saveFirstUser: saveFirstUser, saveFirstUser: saveFirstUser,
......
import $ from 'jquery'; import $ from 'jquery';
import windowHandle from 'window-handle'; import windowHandle from 'window-handle';
import page from './util/page';
import * as tabBarWidget from './widgets/config/tabbar';
var page = require('./util/page.js');
var isScrolling = false; var isScrolling = false;
var ignoreNextScrollEvent = false; var ignoreNextScrollEvent = false;
var pageHeaderHeight = page.pageHeaderHeight(); var pageHeaderHeight = page.pageHeaderHeight();
...@@ -25,8 +26,6 @@ function notify(event) { ...@@ -25,8 +26,6 @@ function notify(event) {
} }
$(function() { $(function() {
var tabBarWidget = require('./widgets/config/tabbar.js');
tabBarWidget.addPageTabs('.config-table.scrollspy', function(tabBar) { tabBarWidget.addPageTabs('.config-table.scrollspy', function(tabBar) {
tabbars.push(tabBar); tabbars.push(tabBar);
......
import $ from 'jquery'; import $ from 'jquery';
import jenkinsLocalStorage from './util/jenkinsLocalStorage';
import page from './util/page';
import * as tabBarWidget from './widgets/config/tabbar';
var page = require('./util/page.js'); export const tabs = []; // Useful for testing.
var jenkinsLocalStorage = require('./util/jenkinsLocalStorage.js');
exports.tabs = []; // Useful for testing.
$(function() { $(function() {
var tabBarWidget = require('./widgets/config/tabbar.js');
tabBarWidget.addPageTabs('.config-table.tabbed', function(tabBar) { tabBarWidget.addPageTabs('.config-table.tabbed', function(tabBar) {
exports.tabs.push(tabBar); tabs.push(tabBar);
// We want to merge some sections together. // We want to merge some sections together.
// Merge the "Advanced" section into the "General" section. // Merge the "Advanced" section into the "General" section.
......
...@@ -2,9 +2,8 @@ ...@@ -2,9 +2,8 @@
* Page initialisation tasks. * Page initialisation tasks.
*/ */
import $ from 'jquery'; import $ from 'jquery';
// Require this one to ensure jenkins-js-modules works all the time // Require this one to ensure jenkins-js-modules works all the time
var jsModules = require('jenkins-js-modules'); import jsModules from 'jenkins-js-modules';
$(function() { $(function() {
loadScripts(); loadScripts();
......
...@@ -33,4 +33,4 @@ export function enhanceJQueryWithBootstrap($) { ...@@ -33,4 +33,4 @@ export function enhanceJQueryWithBootstrap($) {
window.$ = _$; window.$ = _$;
window.jQuery = _jQuery; window.jQuery = _jQuery;
} }
}; }
...@@ -1266,7 +1266,5 @@ var createPluginSetupWizard = function(appendTarget) { ...@@ -1266,7 +1266,5 @@ var createPluginSetupWizard = function(appendTarget) {
})); }));
}; };
var exports = {};
// export wizard creation method // export wizard creation method
exports.init = createPluginSetupWizard; export default { init: createPluginSetupWizard };
export default exports;
import upgradePanel from './templates/upgradePanel.hbs';
import upgradeSuccessPanel from './templates/upgradeSuccessPanel.hbs';
import upgradeSkippedPanel from './templates/upgradeSkippedPanel.hbs';
/* globals onSetupWizardInitialized: true */ /* globals onSetupWizardInitialized: true */
onSetupWizardInitialized(function(wizard) { onSetupWizardInitialized(function(wizard) {
var jenkins = wizard.jenkins; // wizard-provided jenkins api var jenkins = wizard.jenkins; // wizard-provided jenkins api
var pluginManager = wizard.pluginManager; var pluginManager = wizard.pluginManager;
var upgradePanel = require('./templates/upgradePanel.hbs');
var upgradeSuccessPanel = require('./templates/upgradeSuccessPanel.hbs');
var upgradeSkippedPanel = require('./templates/upgradeSkippedPanel.hbs');
wizard.addActions({ wizard.addActions({
'.skip-recommended-plugins': function() { '.skip-recommended-plugins': function() {
......
function specify(selector, id, priority, behavior) {
// eslint-ignore-next-line
Behaviour.specify(selector, id, priority, behavior);
};
exports.specify = function(selector, id, priority, behavior) { export default { specify };
Behaviour.specify(selector, id, priority, behavior); // jshint ignore:line
};
\ No newline at end of file
var windowHandle = require('window-handle'); import { getWindow } from 'window-handle';
var storage = require('./localStorage.js'); import storage from './localStorage'
/** /**
* Store a Jenkins globally scoped value. * Store a Jenkins globally scoped value.
*/ */
exports.setGlobalItem = function(name, value) { function setGlobalItem(name, value) {
storage.setItem('jenkins:' + name, value); storage.setItem('jenkins:' + name, value);
}; }
/** /**
* Get a Jenkins globally scoped value. * Get a Jenkins globally scoped value.
*/ */
exports.getGlobalItem = function(name, defaultVal) { function getGlobalItem(name, defaultVal) {
return storage.getItem('jenkins:' + name, defaultVal); return storage.getItem('jenkins:' + name, defaultVal);
}; }
/** /**
* Store a Jenkins page scoped value. * Store a Jenkins page scoped value.
*/ */
exports.setPageItem = function(name, value) { function setPageItem(name, value) {
name = 'jenkins:' + name + ':' + windowHandle.getWindow().location.href; name = 'jenkins:' + name + ':' + getWindow().location.href;
storage.setItem(name, value); storage.setItem(name, value);
}; }
/** /**
* Get a Jenkins page scoped value. * Get a Jenkins page scoped value.
*/ */
exports.getPageItem = function(name, defaultVal) { function getPageItem(name, defaultVal) {
name = 'jenkins:' + name + ':' + windowHandle.getWindow().location.href; name = 'jenkins:' + name + ':' + getWindow().location.href;
return storage.getItem(name, defaultVal); return storage.getItem(name, defaultVal);
}; }
\ No newline at end of file
export default {
setGlobalItem,
getGlobalItem,
setPageItem,
getPageItem
};
var windowHandle = require('window-handle'); import { getWindow } from 'window-handle';
var win = windowHandle.getWindow();
var storage = win.localStorage;
exports.setMock = function() { let storage = getWindow().localStorage;
function setMock() {
storage = { storage = {
storage: {}, storage: {},
setItem: function (name, value) { setItem: function (name, value) {
...@@ -15,26 +15,33 @@ exports.setMock = function() { ...@@ -15,26 +15,33 @@ exports.setMock = function() {
delete this.storage[name]; delete this.storage[name];
} }
}; };
}; }
exports.setItem = function(name, value) { function setItem(name, value) {
storage.setItem(name, value); storage.setItem(name, value);
}; }
exports.getItem = function(name, defaultVal) { function getItem(name, defaultVal) {
var value = storage.getItem(name); var value = storage.getItem(name);
if (!value) { if (!value) {
value = defaultVal; value = defaultVal;
} }
return value; return value;
}; }
exports.removeItem = function(name) { function removeItem(name) {
return storage.removeItem(name); return storage.removeItem(name);
}; }
if (typeof storage === "undefined") { if (typeof storage === "undefined") {
console.warn('HTML5 localStorage not supported by this browser.'); console.warn('HTML5 localStorage not supported by this browser.');
// mock it... // mock it...
exports.setMock(); setMock();
} }
\ No newline at end of file
export default {
setMock,
setItem,
getItem,
removeItem,
};
import $ from 'jquery'; import $ from 'jquery';
import windowHandle from 'window-handle'; import { getWindow } from 'window-handle';
var timestamp = (new Date().getTime()); var timestamp = (new Date().getTime());
var loadedClass = 'jenkins-loaded-' + timestamp; var loadedClass = 'jenkins-loaded-' + timestamp;
...@@ -13,7 +13,7 @@ var loadedClass = 'jenkins-loaded-' + timestamp; ...@@ -13,7 +13,7 @@ var loadedClass = 'jenkins-loaded-' + timestamp;
* callback must return a boolean value of true if scanning is to continue. * callback must return a boolean value of true if scanning is to continue.
* @param contextEl The jQuery selector context (optional). * @param contextEl The jQuery selector context (optional).
*/ */
export var onload = function(selector, callback, contextEl) { function onload(selector, callback, contextEl) {
function registerRescan() { function registerRescan() {
setTimeout(scan, 50); setTimeout(scan, 50);
} }
...@@ -29,32 +29,32 @@ export var onload = function(selector, callback, contextEl) { ...@@ -29,32 +29,32 @@ export var onload = function(selector, callback, contextEl) {
} }
} }
scan(); scan();
}; }
export var winScrollTop = function() { function winScrollTop() {
var win = $(windowHandle.getWindow()); var win = $(getWindow());
return win.scrollTop(); return win.scrollTop();
}; }
export var onWinScroll = function(callback) { function onWinScroll(callback) {
$(windowHandle.getWindow()).on('scroll', callback); $(getWindow()).on('scroll', callback);
}; }
export var pageHeaderHeight = function() { function pageHeaderHeight() {
return elementHeight('#page-head'); return elementHeight('#page-head');
}; }
export var breadcrumbBarHeight = function() { function breadcrumbBarHeight() {
return elementHeight('#breadcrumbBar'); return elementHeight('#breadcrumbBar');
}; }
export var fireBottomStickerAdjustEvent = function() { function fireBottomStickerAdjustEvent() {
Event.fire(window, 'jenkins:bottom-sticker-adjust'); // jshint ignore:line Event.fire(window, 'jenkins:bottom-sticker-adjust'); // jshint ignore:line
}; }
// YUI Drag widget does not like to work on elements with a relative position. // YUI Drag widget does not like to work on elements with a relative position.
// This tells the element to switch to static position at the start of the drag, so it can work. // This tells the element to switch to static position at the start of the drag, so it can work.
export var fixDragEvent = function(handle) { function fixDragEvent(handle) {
var isReady = false; var isReady = false;
var $handle = $(handle); var $handle = $(handle);
var $chunk = $handle.closest('.repeated-chunk'); var $chunk = $handle.closest('.repeated-chunk');
...@@ -70,16 +70,27 @@ export var fixDragEvent = function(handle) { ...@@ -70,16 +70,27 @@ export var fixDragEvent = function(handle) {
isReady = false; isReady = false;
$chunk.removeClass('dragging'); $chunk.removeClass('dragging');
}); });
}; }
export var removeTextHighlighting = function(selector) { function removeTextHighlighting(selector) {
$('span.highlight-split', selector).each(function() { $('span.highlight-split', selector).each(function() {
var highlightSplit = $(this); var highlightSplit = $(this);
highlightSplit.before(highlightSplit.text()); highlightSplit.before(highlightSplit.text());
highlightSplit.remove(); highlightSplit.remove();
}); });
}; }
function elementHeight(selector) { function elementHeight(selector) {
return $(selector).height(); return $(selector).height();
} }
\ No newline at end of file
export default {
onload,
winScrollTop,
onWinScroll,
pageHeaderHeight,
breadcrumbBarHeight,
fireBottomStickerAdjustEvent,
fixDragEvent,
removeTextHighlighting
}
var jQD = require('../../../util/jquery-ext.js'); import { getJQuery } from '../../../util/jquery-ext';
module.exports = ConfigRowGrouping;
/* /*
* ======================================================================================= * =======================================================================================
* Configuration table row grouping i.e. row-set-*, optional-block-*, radio-block-* etc * Configuration table row grouping i.e. row-set-*, optional-block-*, radio-block-* etc
* *
* A ConfigSection maintains a list of ConfigRowGrouping and then ConfigRowGrouping * A ConfigSection maintains a list of ConfigRowGrouping and then ConfigRowGrouping
* itself maintains a list i.e. it's hierarchical. See ConfigSection.gatherRowGroups(). * itself maintains a list i.e. it's hierarchical. See ConfigSection.gatherRowGroups().
* ======================================================================================= * =======================================================================================
...@@ -65,7 +63,7 @@ ConfigRowGrouping.prototype.updateVisibility = function() { ...@@ -65,7 +63,7 @@ ConfigRowGrouping.prototype.updateVisibility = function() {
* the row-set rows should be made visible or not. * the row-set rows should be made visible or not.
*/ */
ConfigRowGrouping.prototype.findToggleWidget = function(row) { ConfigRowGrouping.prototype.findToggleWidget = function(row) {
var $ = jQD.getJQuery(); var $ = getJQuery();
var input = $(':input.block-control', row); var input = $(':input.block-control', row);
if (input.size() === 1) { if (input.size() === 1) {
this.toggleWidget = input; this.toggleWidget = input;
...@@ -73,3 +71,5 @@ ConfigRowGrouping.prototype.findToggleWidget = function(row) { ...@@ -73,3 +71,5 @@ ConfigRowGrouping.prototype.findToggleWidget = function(row) {
input.addClass('disable-behavior'); input.addClass('disable-behavior');
} }
}; };
export default ConfigRowGrouping;
var jQD = require('../../../util/jquery-ext.js'); import { getJQuery } from '../../../util/jquery-ext';
var util = require('./util.js'); import page from '../../../util/page.js';
var page = require('../../../util/page.js'); import { toId } from './util';
var ConfigRowGrouping = require('./ConfigRowGrouping.js'); import ConfigRowGrouping from './ConfigRowGrouping';
var pageHeaderHeight = page.pageHeaderHeight(); var pageHeaderHeight = page.pageHeaderHeight();
module.exports = ConfigSection;
/* /*
* ======================================================================================= * =======================================================================================
* Configuration table section. * Configuration table section.
...@@ -15,7 +13,7 @@ function ConfigSection(headerRow, parentCMD) { ...@@ -15,7 +13,7 @@ function ConfigSection(headerRow, parentCMD) {
this.headerRow = headerRow; this.headerRow = headerRow;
this.parentCMD = parentCMD; this.parentCMD = parentCMD;
this.title = headerRow.attr('title'); this.title = headerRow.attr('title');
this.id = util.toId(this.title); this.id = toId(this.title);
this.rowGroups = undefined; this.rowGroups = undefined;
this.activator = undefined; this.activator = undefined;
this.subSections = []; this.subSections = [];
...@@ -149,7 +147,7 @@ ConfigSection.prototype.markRowsAsActive = function() { ...@@ -149,7 +147,7 @@ ConfigSection.prototype.markRowsAsActive = function() {
}; };
ConfigSection.prototype.hasText = function(text) { ConfigSection.prototype.hasText = function(text) {
var $ = jQD.getJQuery(); var $ = getJQuery();
var selector = ":containsci('" + text + "')"; var selector = ":containsci('" + text + "')";
var sectionRows = this.getRows(); var sectionRows = this.getRows();
...@@ -255,7 +253,7 @@ ConfigSection.prototype.getRowGroupLabels = function() { ...@@ -255,7 +253,7 @@ ConfigSection.prototype.getRowGroupLabels = function() {
}; };
ConfigSection.prototype.highlightText = function(text) { ConfigSection.prototype.highlightText = function(text) {
var $ = jQD.getJQuery(); var $ = getJQuery();
var selector = ":containsci('" + text + "')"; var selector = ":containsci('" + text + "')";
var rows = this.getRows(); var rows = this.getRows();
...@@ -286,3 +284,5 @@ ConfigSection.prototype.highlightText = function(text) { ...@@ -286,3 +284,5 @@ ConfigSection.prototype.highlightText = function(text) {
this.subSections[i2].highlightText(text); this.subSections[i2].highlightText(text);
} }
}; };
export default ConfigSection;
/* /*
* Internal support module for config tables. * Internal support module for config tables.
*/ */
import { getJQuery } from '../../../util/jquery-ext';
import page from '../../../util/page';
import ConfigSection from './ConfigSection';
import { toId } from './util';
var jQD = require('../../../util/jquery-ext.js'); function markConfigTableParentForm(configTable) {
var ConfigSection = require('./ConfigSection.js');
var page = require('../../../util/page.js');
var util = require('./util.js');
exports.markConfigTableParentForm = function(configTable) {
var form = configTable.closest('form'); var form = configTable.closest('form');
form.addClass('jenkins-config'); form.addClass('jenkins-config');
return form; return form;
}; }
exports.findConfigTables = function() { function findConfigTables() {
var $ = jQD.getJQuery(); var $ = getJQuery();
// The config tables are the immediate child <table> elements of <form> elements // The config tables are the immediate child <table> elements of <form> elements
// with a name of "config"? // with a name of "config"?
return $('form[name="config"] > table'); return $('form[name="config"] > table');
}; }
exports.fromConfigTable = function(configTable) { function fromConfigTable(configTable) {
var $ = jQD.getJQuery(); var $ = getJQuery();
var sectionHeaders = $('.section-header', configTable); var sectionHeaders = $('.section-header', configTable);
var configForm = exports.markConfigTableParentForm(configTable); var configForm = markConfigTableParentForm(configTable);
// Mark the ancestor <tr>s of the section headers and add a title // Mark the ancestor <tr>s of the section headers and add a title
sectionHeaders.each(function () { sectionHeaders.each(function () {
...@@ -75,10 +74,10 @@ exports.fromConfigTable = function(configTable) { ...@@ -75,10 +74,10 @@ exports.fromConfigTable = function(configTable) {
var buttonsRow = $('#bottom-sticker', configTable).closest('tr'); var buttonsRow = $('#bottom-sticker', configTable).closest('tr');
buttonsRow.removeClass(curSection.id); buttonsRow.removeClass(curSection.id);
buttonsRow.addClass(util.toId('buttons')); buttonsRow.addClass(toId('buttons'));
return configTableMetadata; return configTableMetadata;
}; }
/* /*
* ======================================================================================= * =======================================================================================
...@@ -86,7 +85,7 @@ exports.fromConfigTable = function(configTable) { ...@@ -86,7 +85,7 @@ exports.fromConfigTable = function(configTable) {
* ======================================================================================= * =======================================================================================
*/ */
function ConfigTableMetaData(configForm, configTable) { function ConfigTableMetaData(configForm, configTable) {
this.$ = jQD.getJQuery(); this.$ = getJQuery();
this.configForm = configForm; this.configForm = configForm;
this.configTable = configTable; this.configTable = configTable;
this.configTableBody = this.$('> tbody', configTable); this.configTableBody = this.$('> tbody', configTable);
...@@ -110,13 +109,13 @@ ConfigTableMetaData.prototype.getFirstRow = function() { ...@@ -110,13 +109,13 @@ ConfigTableMetaData.prototype.getFirstRow = function() {
}; };
ConfigTableMetaData.prototype.addWidgetsContainer = function() { ConfigTableMetaData.prototype.addWidgetsContainer = function() {
var $ = jQD.getJQuery(); var $ = getJQuery();
this.configWidgets = $('<div class="jenkins-config-widgets"></div>'); this.configWidgets = $('<div class="jenkins-config-widgets"></div>');
this.configWidgets.insertBefore(this.configForm); this.configWidgets.insertBefore(this.configForm);
}; };
ConfigTableMetaData.prototype.addFindWidget = function() { ConfigTableMetaData.prototype.addFindWidget = function() {
var $ = jQD.getJQuery(); var $ = getJQuery();
var thisTMD = this; var thisTMD = this;
var findWidget = $('<div class="find-container"><div class="find"><span title="Clear" class="clear">x</span><input placeholder="find"/></div></div>'); var findWidget = $('<div class="find-container"><div class="find"><span title="Clear" class="clear">x</span><input placeholder="find"/></div></div>');
...@@ -268,7 +267,7 @@ ConfigTableMetaData.prototype.showSection = function(section) { ...@@ -268,7 +267,7 @@ ConfigTableMetaData.prototype.showSection = function(section) {
ConfigTableMetaData.prototype.hideSection = function() { ConfigTableMetaData.prototype.hideSection = function() {
var topRows = this.getTopRows(); var topRows = this.getTopRows();
var $ = jQD.getJQuery(); var $ = getJQuery();
$('.config-section-activator.active', this.activatorContainer).removeClass('active'); $('.config-section-activator.active', this.activatorContainer).removeClass('active');
topRows.filter('.active').removeClass('active'); topRows.filter('.active').removeClass('active');
...@@ -383,4 +382,10 @@ function isTestEnv() { ...@@ -383,4 +382,10 @@ function isTestEnv() {
} }
return false; return false;
} }
\ No newline at end of file
export default {
markConfigTableParentForm,
findConfigTables,
fromConfigTable
};
export function toId(string) {
exports.toId = function(string) {
string = string.trim(); string = string.trim();
return 'config_' + string.replace(/[\W_]+/g, '_').toLowerCase(); return 'config_' + string.replace(/[\W_]+/g, '_').toLowerCase();
}; }
\ No newline at end of file
import $ from 'jquery'; import $ from 'jquery';
import { getWindow } from 'window-handle';
var page = require('../../util/page.js'); import page from '../../util/page';
var jenkinsLocalStorage = require('../../util/jenkinsLocalStorage.js'); import tableMetadata from './model/ConfigTableMetaData';
var tableMetadata = require('./model/ConfigTableMetaData.js'); import behaviorShim from '../../util/behavior-shim';
var behaviorShim = require('../../util/behavior-shim'); import jenkinsLocalStorage from '../../util/jenkinsLocalStorage';
export var tabBarShowPreferenceKey = 'config:usetabs'; export var tabBarShowPreferenceKey = 'config:usetabs';
...@@ -32,7 +32,7 @@ export var addPageTabs = function(configSelector, onEachConfigTable, options) { ...@@ -32,7 +32,7 @@ export var addPageTabs = function(configSelector, onEachConfigTable, options) {
tabBar.deactivator.click(function() { tabBar.deactivator.click(function() {
jenkinsLocalStorage.setGlobalItem(tabBarShowPreferenceKey, "no"); jenkinsLocalStorage.setGlobalItem(tabBarShowPreferenceKey, "no");
require('window-handle').getWindow().location.reload(); getWindow().location.reload();
}); });
}); });
} else { } else {
...@@ -42,7 +42,7 @@ export var addPageTabs = function(configSelector, onEachConfigTable, options) { ...@@ -42,7 +42,7 @@ export var addPageTabs = function(configSelector, onEachConfigTable, options) {
tableMetadata.markConfigTableParentForm(configTable); tableMetadata.markConfigTableParentForm(configTable);
activator.click(function() { activator.click(function() {
jenkinsLocalStorage.setGlobalItem(tabBarShowPreferenceKey, "yes"); jenkinsLocalStorage.setGlobalItem(tabBarShowPreferenceKey, "yes");
require('window-handle').getWindow().location.reload(); getWindow().location.reload();
}); });
}); });
} }
......
...@@ -2,17 +2,28 @@ import jsTest from '@jenkins-cd/js-test'; ...@@ -2,17 +2,28 @@ import jsTest from '@jenkins-cd/js-test';
var debug = false; var debug = false;
// Registers needed handlebars helpers that are loaded through webpack
function registerHandlebars() {
// eslint-disable-next-line no-undef
const Handlebars = require('handlebars').default;
// eslint-disable-next-line no-undef
Handlebars.registerHelper('id', require('../../main/js/handlebars-helpers/id').default)
}
var getJQuery = function() { var getJQuery = function() {
// eslint-disable-next-line no-undef
var $ = require('jquery'); var $ = require('jquery');
$.fx.off = true; $.fx.off = true;
return $; return $;
}; };
var getJenkins = function() { var getJenkins = function() {
// eslint-disable-next-line no-undef
return require('../../main/js/util/jenkins').default; return require('../../main/js/util/jenkins').default;
} }
var getSetupWizardGui = function() { var getSetupWizardGui = function() {
// eslint-disable-next-line no-undef
return require('../../main/js/pluginSetupWizardGui').default; return require('../../main/js/pluginSetupWizardGui').default;
} }
...@@ -212,9 +223,7 @@ describe("pluginSetupWizard.js", function () { ...@@ -212,9 +223,7 @@ describe("pluginSetupWizard.js", function () {
let $body; let $body;
beforeEach(() => { beforeEach(() => {
// Registers needed handlebars helpers that are loaded through webpack registerHandlebars();
const Handlebars = require('handlebars').default;
Handlebars.registerHelper('id', require('../../main/js/handlebars-helpers/id').default)
// Create a new <body> tag for every test // Create a new <body> tag for every test
$ = getJQuery(); $ = getJQuery();
......
import { getWindow } from 'window-handle';
import localStorage from '../../../../main/js/util/localStorage';
// mock the behaviors stuff. // mock the behaviors stuff.
var behaviorShim = require('../../../../main/js/util/behavior-shim'); export function mockBehaviorShim() {
behaviorShim.specify = function(selector, id, priority, behavior) { const mockActualBehaviorShim = jest.requireActual('../../../../main/js/util/behavior-shim');
behavior();
};
// Mock out the fireBottomStickerAdjustEvent function ... it accesses Event. jest.mock('../../../../main/js/util/behavior-shim', () => ({
var page = require('../../../../main/js/util/page'); __esModule: true,
page.fireBottomStickerAdjustEvent = function() {}; default: {
...mockActualBehaviorShim.default,
specify: jest.fn((selector, id, priority, behavior) => behavior())
}
}));
}
// Mock out the Event.fire function
global.Event = { // eslint-disable-line no-undef
fire: jest.fn()
};
var windowHandle = require('window-handle'); getWindow(function() {
windowHandle.getWindow(function() {
var localStorage = require('../../../../main/js/util/localStorage');
localStorage.setMock(); localStorage.setMock();
}); });
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
import jsTest from '@jenkins-cd/js-test'; import jsTest from '@jenkins-cd/js-test';
import './mocks'; import { mockBehaviorShim } from './mocks';
const debug = false; const debug = false;
...@@ -24,13 +24,20 @@ describe("scrollspy-spec tests", function () { ...@@ -24,13 +24,20 @@ describe("scrollspy-spec tests", function () {
); );
beforeEach(() => { beforeEach(() => {
mockBehaviorShim();
jest.mock('../../../../main/js/util/page', () => ({ jest.mock('../../../../main/js/util/page', () => ({
__esModule: true,
...mockPageUtils, ...mockPageUtils,
winScrollTop: mockWinScrollTop, default: {
onWinScroll: mockOnWinScroll, ...mockPageUtils.default,
fireBottomStickerAdjustEvent: jest.fn(),
winScrollTop: mockWinScrollTop,
onWinScroll: mockOnWinScroll,
}
})); }));
mockConfigSection.prototype.isVisible = jest.fn(); mockConfigSection.default.prototype.isVisible = jest.fn();
jest.mock( jest.mock(
'../../../../main/js/widgets/config/model/ConfigSection', '../../../../main/js/widgets/config/model/ConfigSection',
() => mockConfigSection () => mockConfigSection
...@@ -65,12 +72,13 @@ describe("scrollspy-spec tests", function () { ...@@ -65,12 +72,13 @@ describe("scrollspy-spec tests", function () {
it("- test scrolling", function (done) { it("- test scrolling", function (done) {
// Needs to return true for the tests // Needs to return true for the tests
mockConfigSection.prototype.isVisible.mockReturnValue(true); mockConfigSection.default.prototype.isVisible.mockReturnValue(true);
jsTest.onPage(function () { jsTest.onPage(function () {
document.documentElement.innerHTML = htmlContent; document.documentElement.innerHTML = htmlContent;
var manualScroller = newManualScroller(); var manualScroller = newManualScroller();
// eslint-disable-next-line no-undef
var tabbars = require('../../../../main/js/config-scrollspy'); var tabbars = require('../../../../main/js/config-scrollspy');
tabbars.setScrollspeed(1); // speed up the scroll speed for testing tabbars.setScrollspeed(1); // speed up the scroll speed for testing
......
...@@ -2,7 +2,7 @@ import fs from 'fs'; ...@@ -2,7 +2,7 @@ import fs from 'fs';
import path from 'path'; import path from 'path';
import $ from 'jquery'; import $ from 'jquery';
import jsTest from '@jenkins-cd/js-test'; import jsTest from '@jenkins-cd/js-test';
import './mocks'; import { mockBehaviorShim } from './mocks';
const htmlConfigTabbedContent = fs.readFileSync( const htmlConfigTabbedContent = fs.readFileSync(
path.resolve(__dirname, './freestyle-config-tabbed.html'), path.resolve(__dirname, './freestyle-config-tabbed.html'),
...@@ -10,14 +10,41 @@ const htmlConfigTabbedContent = fs.readFileSync( ...@@ -10,14 +10,41 @@ const htmlConfigTabbedContent = fs.readFileSync(
); );
function getConfigTabbar() { function getConfigTabbar() {
// eslint-disable-next-line no-undef
return require('../../../../main/js/config-tabbar'); return require('../../../../main/js/config-tabbar');
} }
function getConfigTabbarWidget() { function getConfigTabbarWidget() {
// eslint-disable-next-line no-undef
return require('../../../../main/js/widgets/config/tabbar'); return require('../../../../main/js/widgets/config/tabbar');
} }
describe("tabbar-spec tests", function () { describe("tabbar-spec tests", function () {
// Need to mock the utils/page module because we will hijack the scroll events
const mockPageUtils = jest.requireActual('../../../../main/js/util/page');
beforeEach(() => {
mockBehaviorShim();
jest.mock('../../../../main/js/util/page', () => ({
__esModule: true,
...mockPageUtils,
default: {
...mockPageUtils.default,
fireBottomStickerAdjustEvent: jest.fn(),
}
}));
});
afterEach(() => {
jest.resetAllMocks()
});
afterAll(() => {
// Should call resetModules on afterAll because the test "test section activation"
// will break if resetModules is called on afterEach.
jest.resetModules();
});
it("- test section count", function (done) { it("- test section count", function (done) {
jsTest.onPage(function() { jsTest.onPage(function() {
...@@ -41,6 +68,7 @@ describe("tabbar-spec tests", function () { ...@@ -41,6 +68,7 @@ describe("tabbar-spec tests", function () {
}, htmlConfigTabbedContent); }, htmlConfigTabbedContent);
}); });
// This test may be deterministic, as it breaks if jest.resetModules is called on afterEach
it("- test section activation", function (done) { it("- test section activation", function (done) {
jsTest.onPage(function() { jsTest.onPage(function() {
document.documentElement.innerHTML = htmlConfigTabbedContent; document.documentElement.innerHTML = htmlConfigTabbedContent;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册