Hello Aditya, We changed the way the tests were running and we could remove the function. Instead of piggybackiung on a deprecated field we created a html fixture
$('body').append( '<div id="test-id">' + '<button id="btn-flash" disabled></button>' + '<button id="btn-cancel-query"></button>' + '</div>' ); With it we could use the real JQuery instead of mocking it. Now the tests look like this it('disables the run query button', () => { let buttonFlash = $('#btn-flash'); expect(buttonFlash.prop('disabled')).toEqual(true); }); Thanks Anthony & Joao On Thu, May 24, 2018 at 12:26 AM Aditya Toshniwal < aditya.toshni...@enterprisedb.com> wrote: > Hi, > > No luck with data-test-selector. :( > I added data-test-selector to html tags. I get undefined for > .data('test-selector') as well as for .attr('data-test-selector'). > > Thanks and Regards, > Aditya Toshniwal > Software Engineer | EnterpriseDB Software Solutions | Pune > "Don't Complain about Heat, Plant a tree" > > On Thu, May 24, 2018 at 9:17 AM, Aditya Toshniwal < > aditya.toshni...@enterprisedb.com> wrote: > >> Hi Victoria/Joao, >> >> Thank you for reviewing. The above function is probably the last solution >> which I added. >> The test cases >> in web/regression/javascript/sqleditor/execute_query_spec.js calls the >> execute query function of pgAdmin4 sqleditor. The execution >> disables/enables the buttons internally and is not done by the test cases. >> So there is spy on prop function (jqueryPropSpy = spyOn($.fn, 'prop')) of >> jQuery. The problem is, the spy jQuery object (in function >> findJQueryCallWithSelector) returned seems to have very less information, >> not sure why. I had tried using css selector for id, tried extracting id >> directly, class, but none of them were present in the object. >> >> I can try adding data-test-selector to the HTML5 tag, if it works then >> will send the updated patch. >> >> >> Thanks and Regards, >> Aditya Toshniwal >> Software Engineer | EnterpriseDB Software Solutions | Pune >> "Don't Complain about Heat, Plant a tree" >> >> On Wed, May 23, 2018 at 7:41 PM, Joao De Almeida Pereira < >> jdealmeidapere...@pivotal.io> wrote: >> >>> HI Aditya, >>> >>> Good job porting the app from the ancient version of JQuery to the >>> latest build :D >>> >>> The patch in general looks good, and the patches-bot says all tests >>> pass. >>> >>> The only thing that we would like to point out is this piece of code: >>> >>> /* jQuery has removed selector property in version 3.x >>> * To allow JS test cases to run, the below function is >>> * used to set the selector property >>> */ >>> function setPropAndSelector(selector, propName, propVal) { >>> let tmpObj = $(selector); >>> tmpObj['selector'] = selector; >>> tmpObj.prop(propName,propVal); >>> return tmpObj; >>> } >>> >>> As tests are also part of the code we believe that when there is a >>> change that affect testing we should change the tests to work accordingly. >>> So our suggestion is, instead of creating this function, why don’t we use a >>> CSS selector in the tests to do the clicking or even use the HTML5 tag >>> data-test-selector? >>> This way the tests will also be coherent with the upgrade from JQuery 1 >>> to 3 >>> >>> >>> Thanks >>> Victoria & Joao >>> >>> On Wed, May 23, 2018 at 6:44 AM Aditya Toshniwal < >>> aditya.toshni...@enterprisedb.com> wrote: >>> >>>> Hi Hackers, >>>> >>>> Please find the updated patch for upgrading the jQuery version to 3.x. >>>> The patch is only for pgAdmin4 code changes replacing old deprecated >>>> functions with new replacement. >>>> We need to look into external libraries used for any vulnerabilities. >>>> Request you to kindly review. >>>> >>>> Thanks and Regards, >>>> Aditya Toshniwal >>>> Software Engineer | EnterpriseDB Software Solutions | Pune >>>> "Don't Complain about Heat, Plant a tree" >>>> >>>> On Mon, May 14, 2018 at 1:23 PM, Aditya Toshniwal < >>>> aditya.toshni...@enterprisedb.com> wrote: >>>> >>>>> Hi Hackers, >>>>> >>>>> Please hold on with the patch. Will send the updated patch soon. >>>>> Apologies. >>>>> >>>>> >>>>> >>>>> Thanks and Regards, >>>>> Aditya Toshniwal >>>>> Software Engineer | EnterpriseDB Software Solutions | Pune >>>>> "Don't Complain about Heat, Plant a tree" >>>>> >>>>> On Mon, May 14, 2018 at 12:52 PM, Aditya Toshniwal < >>>>> aditya.toshni...@enterprisedb.com> wrote: >>>>> >>>>>> Hi Hackers, >>>>>> >>>>>> PFA patch for upgrading jQuery version to 3.3.1 from current version >>>>>> 1.12.4. Patch includes replacing deprecated functions of jquery to latest >>>>>> one. >>>>>> Kindly review. >>>>>> >>>>>> Thanks and Regards, >>>>>> Aditya Toshniwal >>>>>> Software Engineer | EnterpriseDB Software Solutions | Pune >>>>>> "Don't Complain about Heat, Plant a tree" >>>>>> >>>>> >>>>> >>>> >> >
diff --git a/libraries.txt b/libraries.txt index 17f85cf..4a33ef2 100644 --- a/libraries.txt +++ b/libraries.txt @@ -5,7 +5,7 @@ Library Version Licence URL ======= ======= ======= === QT 4.6.2+ LGPL v2.1/3 http://www.qt.io/ Bootstrap 3.3.4 MIT http://getbootstrap.com/ -jQuery 1.11.1 MIT http://jquery.com/ +jQuery 3.3.1 MIT http://jquery.com/ Modernizr 2.6.2 MIT/BSD http://modernizr.com/ AlertifyJS 1.7.1 MIT http://alertifyjs.com/ *** Do not update - changed to GPL3 in 1.8.0 *** CodeMirror 5.14.2 MIT http://codemirror.net/ diff --git a/web/package.json b/web/package.json index b9953b6..6ccc4ee 100644 --- a/web/package.json +++ b/web/package.json @@ -69,7 +69,7 @@ "immutability-helper": "^2.2.0", "imports-loader": "^0.7.1", "ip-address": "^5.8.9", - "jquery": "^1.12.4", + "jquery": "3.3.1", "jquery-contextmenu": "^2.6.4", "jquery-ui": "^1.12.1", "moment": "^2.20.1", diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/static/js/column.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/static/js/column.js index 72b6eb0..3eac530 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/static/js/column.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/static/js/column.js @@ -287,7 +287,7 @@ define('pgadmin.node.column', [ var command = new Backgrid.Command({key: 'Tab', keyCode: 9, which: 9}); self.model.trigger('backgrid:edited', self.model, self.column, command); - next_cell.focus(); + next_cell.trigger('focus'); } }, 20); }, diff --git a/web/pgadmin/browser/server_groups/servers/static/js/privilege.js b/web/pgadmin/browser/server_groups/servers/static/js/privilege.js index 64557a0..6758bf6 100644 --- a/web/pgadmin/browser/server_groups/servers/static/js/privilege.js +++ b/web/pgadmin/browser/server_groups/servers/static/js/privilege.js @@ -381,10 +381,10 @@ define(['sources/gettext', 'underscore', 'jquery', 'backbone', 'backform', 'header': true, })); } - self.$el.find('input[type=checkbox]').first().focus(); + self.$el.find('input[type=checkbox]').first().trigger('focus'); // Since blur event does not bubble we need to explicitly call parent's blur event. $(self.$el.find('input[type=checkbox]')).on('blur',function() { - self.$el.blur(); + self.$el.trigger('blur'); }); // Make row visible in when entering in edit mode. diff --git a/web/pgadmin/browser/server_groups/servers/static/js/variable.js b/web/pgadmin/browser/server_groups/servers/static/js/variable.js index 2c5bb07..9e48b4f 100644 --- a/web/pgadmin/browser/server_groups/servers/static/js/variable.js +++ b/web/pgadmin/browser/server_groups/servers/static/js/variable.js @@ -395,7 +395,7 @@ define([ // Add button callback if (!(data.disabled || data.canAdd == false)) { - $gridBody.find('button.add').first().click(function(e) { + $gridBody.find('button.add').first().on('click',(e) => { e.preventDefault(); var canAddRow = _.isFunction(data.canAddRow) ? data.canAddRow.apply(self, [self.model]) : true; diff --git a/web/pgadmin/browser/static/js/browser.js b/web/pgadmin/browser/static/js/browser.js index d969348..b26738c 100644 --- a/web/pgadmin/browser/static/js/browser.js +++ b/web/pgadmin/browser/static/js/browser.js @@ -1609,7 +1609,7 @@ define('pgadmin.browser', [ jsonResp = ( contentType && contentType.indexOf('application/json') == 0 && - $.parseJSON(xhr.responseText) + JSON.parse(xhr.responseText) ) || {}; if (xhr.status == 410 && jsonResp.success == 0) { diff --git a/web/pgadmin/browser/static/js/keyboard.js b/web/pgadmin/browser/static/js/keyboard.js index e4e1da1..371faa5 100644 --- a/web/pgadmin/browser/static/js/keyboard.js +++ b/web/pgadmin/browser/static/js/keyboard.js @@ -142,18 +142,18 @@ _.extend(pgBrowser.keyboardNavigation, { bindMainMenuUpDown: function(event, combo) { // Handle Sub-menus if (combo === 'up' && $(event.target).parent().prev().prev('.dropdown-submenu').length > 0) { - $(event.target).parent().prev().prev('.dropdown-submenu').find('a:first').focus(); + $(event.target).parent().prev().prev('.dropdown-submenu').find('a:first').trigger('focus'); } else { if ($(event.target).parent().hasClass('dropdown-submenu')) { $(event.target).parent().parent().parent().find('a:first').dropdown('toggle'); - $(event.target).parent().parent().children().eq(2).find('a:first').focus(); + $(event.target).parent().parent().children().eq(2).find('a:first').trigger('focus'); } } }, bindLeftTree: function() { const tree = this.getTreeDetails(); - $('#tree').focus(); + $('#tree').trigger('focus'); tree.t.focus(tree.i); tree.t.select(tree.i); }, @@ -219,7 +219,7 @@ _.extend(pgBrowser.keyboardNavigation, { const top = $(event.srcElement).find('.aciTreeEntry').position().top + 70; tree.t.blur(tree.i); - $('#tree').blur(); + $('#tree').trigger('blur'); // Call context menu and set position tree.i.children().contextMenu({x: left, y: top}); }, diff --git a/web/pgadmin/browser/static/js/menu.js b/web/pgadmin/browser/static/js/menu.js index db3b92a..d236a89 100644 --- a/web/pgadmin/browser/static/js/menu.js +++ b/web/pgadmin/browser/static/js/menu.js @@ -95,10 +95,10 @@ define([ element.find('i').addClass('font-white'); element.find('i').removeClass('font-gray-4'); - span.mouseover(function() { + span.on('mouseover',() => { element.addClass('bg-gray-5'); }); - span.mouseout(function() { + span.on('mouseout',() => { element.removeClass('bg-gray-5'); }); }, diff --git a/web/pgadmin/browser/static/js/node.js b/web/pgadmin/browser/static/js/node.js index ad58248..460ab03 100644 --- a/web/pgadmin/browser/static/js/node.js +++ b/web/pgadmin/browser/static/js/node.js @@ -734,7 +734,7 @@ define('pgadmin.browser.node', [ /* Error from the server */ if (jqx.status == 417 || jqx.status == 410 || jqx.status == 500) { try { - var data = $.parseJSON(jqx.responseText); + var data = JSON.parse(jqx.responseText); msg = data.errormsg; } catch (e) { console.warn(e.stack || e); @@ -1140,7 +1140,7 @@ define('pgadmin.browser.node', [ icon: 'fa fa-lg fa-pencil-square-o', disabled: !that.canEdit, register: function(btn) { - btn.click(function() { + btn.on('click',() => { onEdit(); }); }, @@ -1154,7 +1154,7 @@ define('pgadmin.browser.node', [ icon: 'fa fa-lg fa-info', disabled: (that.sqlAlterHelp == '' && that.sqlCreateHelp == '') ? true : false, register: function(btn) { - btn.click(function() { + btn.on('click',() => { onSqlHelp(); }); }, @@ -1359,7 +1359,7 @@ define('pgadmin.browser.node', [ icon: 'fa fa-lg fa-info', disabled: (that.sqlAlterHelp == '' && that.sqlCreateHelp == '') ? true : false, register: function(btn) { - btn.click(function() { + btn.on('click',() => { onSqlHelp(); }); }, @@ -1371,7 +1371,7 @@ define('pgadmin.browser.node', [ icon: 'fa fa-lg fa-question', disabled: (that.dialogHelp == '') ? true : false, register: function(btn) { - btn.click(function() { + btn.on('click',() => { onDialogHelp(); }); }, @@ -1384,7 +1384,7 @@ define('pgadmin.browser.node', [ disabled: true, register: function(btn) { // Save the changes - btn.click(function() { + btn.on('click',() => { onSave.call(this, view, btn); }); }, @@ -1396,7 +1396,7 @@ define('pgadmin.browser.node', [ icon: 'fa fa-lg fa-close', disabled: false, register: function(btn) { - btn.click(function() { + btn.on('click',() => { // Removing the action-mode panel.$container.removeAttr('action-mode'); onCancelFunc.call(arguments); @@ -1410,7 +1410,7 @@ define('pgadmin.browser.node', [ icon: 'fa fa-lg fa-recycle', disabled: true, register: function(btn) { - btn.click(function() { + btn.on('click',() => { setTimeout(function() { editFunc.call(); }, 0); diff --git a/web/pgadmin/dashboard/static/js/dashboard.js b/web/pgadmin/dashboard/static/js/dashboard.js index 686cbf2..5c812bf 100644 --- a/web/pgadmin/dashboard/static/js/dashboard.js +++ b/web/pgadmin/dashboard/static/js/dashboard.js @@ -63,9 +63,9 @@ define('pgadmin.dashboard', [ // This will refresh the grid var refresh_grid = function() { if (is_server_dashboard) { - $('#btn_server_activity_refresh').click(); + $('#btn_server_activity_refresh').trigger('click'); } else if (is_database_dashboard) { - $('#btn_database_activity_refresh').click(); + $('#btn_database_activity_refresh').trigger('click'); } }; @@ -139,7 +139,7 @@ define('pgadmin.dashboard', [ ); this.delegateEvents(); if (this.grabFocus) - this.$el.focus(); + this.$el.trigger('focus'); return this; }, }); @@ -969,7 +969,7 @@ define('pgadmin.dashboard', [ }); // Handle button clicks - $('button').click(function() { + $('button').on('click',() => { switch (this.id) { case 'btn_server_activity_refresh': pgAdmin.Dashboard.render_grid_data(div_server_activity); @@ -1290,7 +1290,7 @@ define('pgadmin.dashboard', [ }); // Handle button clicks - $('button').click(function() { + $('button').on('click',() => { switch (this.id) { case 'btn_database_activity_refresh': pgAdmin.Dashboard.render_grid_data(div_database_activity); diff --git a/web/pgadmin/misc/file_manager/static/js/file_manager.js b/web/pgadmin/misc/file_manager/static/js/file_manager.js index 10de1ea..11fa2e7 100644 --- a/web/pgadmin/misc/file_manager/static/js/file_manager.js +++ b/web/pgadmin/misc/file_manager/static/js/file_manager.js @@ -574,7 +574,7 @@ define('misc.file_manager', [ $('.file_manager_ok').addClass('disabled'); $('.replace_file, .fm_dimmer').show(); - $yesBtn.click(function() { + $yesBtn.on('click',() => { $('.replace_file, .fm_dimmer').hide(); $yesBtn.off(); $noBtn.off(); @@ -586,7 +586,7 @@ define('misc.file_manager', [ $('.file_manager_ok').removeClass('disabled'); }); - $noBtn.click(function() { + $noBtn.on('click',() => { $('.replace_file, .fm_dimmer').hide(); $yesBtn.off(); $noBtn.off(); diff --git a/web/pgadmin/misc/file_manager/static/js/utility.js b/web/pgadmin/misc/file_manager/static/js/utility.js index 249b0fe..ce3cd17 100755 --- a/web/pgadmin/misc/file_manager/static/js/utility.js +++ b/web/pgadmin/misc/file_manager/static/js/utility.js @@ -133,13 +133,13 @@ define([ if (!has_capability(data, 'delete') || pgAdmin.FileUtils.hideButtons()) { $('.file_manager').find('button.delete').hide(); } else { - $('.file_manager').find('button.delete').click(function() { + $('.file_manager').find('button.delete').on('click',() => { // hide dimmer $('.fileinfo .delete_item, .fm_dimmer').show(); }); // take action based on pressed button yes or no - $('.fileinfo .delete_item button.btn_yes').unbind().on('click', function() { + $('.fileinfo .delete_item button.btn_yes').off().on('click', function() { var path; if ($('.fileinfo').data('view') == 'grid') { path = decodeURI($('.fileinfo').find('#contents li.selected .clip span').attr('data-alt')); @@ -168,7 +168,7 @@ define([ if (!has_capability(data, 'download') || pgAdmin.FileUtils.hideButtons()) { $('.file_manager').find('button.download').hide(); } else { - $('.file_manager').find('button.download').unbind().click(function() { + $('.file_manager').find('button.download').off().on('click',() => { var path; if ($('.fileinfo').data('view') == 'grid') { path = $('.fileinfo li.selected').find('.clip span').attr('data-alt'); @@ -266,7 +266,7 @@ define([ data.Filename = newName; // UnBind toolbar functions. - $('.fileinfo').find('button.rename, button.delete, button.download').unbind(); + $('.fileinfo').find('button.rename, button.delete, button.download').off(); Alertify.success(lg.successful_rename); } else { @@ -443,7 +443,7 @@ define([ } // navigate to directory or path when clicked on breadcrumbs - $('.file_manager a.breadcrumbs').unbind().on('click', function() { + $('.file_manager a.breadcrumbs').off().on('click', function() { var curr_path = $(this).attr('data-path'), current_dir = $(this).html(), move_to = curr_path.substring( @@ -669,7 +669,7 @@ define([ $('.fileinfo .file_listing').html(result); // rename file/folder - $('.file_manager button.rename').unbind().on('click', function(e) { + $('.file_manager button.rename').off().on('click', function(e) { if ($('.fileinfo').data('view') == 'grid') { e.stopPropagation(); @@ -681,11 +681,11 @@ define([ newvalue = decodeURI(orig_value); } - $this.find('input').toggle().val(newvalue).focus(); + $this.find('input').toggle().val(newvalue).trigger('focus'); $this.find('span').toggle(); // Rename folder/file on pressing enter key - $('.file_manager').unbind().on('keyup', function(e) { + $('.file_manager').off().on('keyup', function(e) { if (e.keyCode == 13) { e.stopPropagation(); $('.fileinfo #contents li.selected p').find( @@ -705,11 +705,11 @@ define([ newvalue = decodeURI(orig_value); } - $this.find('input').toggle().val(newvalue).focus(); + $this.find('input').toggle().val(newvalue).trigger('focus'); $this.find('span').toggle(); // Rename folder/file on pressing enter key - $('.file_manager').unbind().on('keyup', function(e) { + $('.file_manager').off().on('keyup', function(e) { if (e.keyCode == 13) { e.stopPropagation(); $('.fileinfo table#contents tr.selected td p').find( @@ -866,12 +866,12 @@ define([ } else { var is_valid_file = getFileInfo(path); if (is_valid_file && check_file_capability(e, data_cap, 'grid')) { - $('.file_manager_ok').click(); + $('.file_manager_ok').trigger('click'); } } }); - $('.fileinfo').find('#contents li').click(function(e) { + $('.fileinfo').find('#contents li').on('click',(e) => { e.stopPropagation(); var path = decodeURI($(this).find('.clip span').attr('data-alt')), is_protected = $(this).find( @@ -976,7 +976,7 @@ define([ if ( is_valid_file && check_file_capability(e, data_cap, 'table') ) { - $('.file_manager_ok').click(); + $('.file_manager_ok').trigger('click'); } } }); @@ -1131,7 +1131,7 @@ define([ // If user have preference to show hidden files if (config.options.show_hidden_files) { setTimeout(function() { - $('#show_hidden').click(); + $('#show_hidden').trigger('click'); }, 10); } // handle show hidden files functionality @@ -1199,7 +1199,7 @@ define([ ).on( 'click', function(e) { - $('#uploader .filemanager-btn-group').unbind().on( + $('#uploader .filemanager-btn-group').off().on( 'click', function() { $('.fileinfo .delete_item, .fileinfo .replace_file, .fileinfo .fm_dimmer').hide(); @@ -1221,7 +1221,7 @@ define([ }); // re-render the home view - $('.file_manager .home').click(function() { + $('.file_manager .home').on('click',() => { var currentViewMode = $('.fileinfo').data('view'); $('.fileinfo').data('view', currentViewMode); getFolderInfo('/'); @@ -1229,7 +1229,7 @@ define([ }); // Go one directory back - $('.file_manager .level-up').click(function() { + $('.file_manager .level-up').on('click',() => { var b = $('.currentpath').val(); // Enable/Disable level up button enab_dis_level_up(); @@ -1253,7 +1253,7 @@ define([ }); // set buttons to switch between grid and list views. - $('.file_manager .grid').click(function() { + $('.file_manager .grid').on('click',() => { setViewButtonsFor('grid'); $('.fileinfo').data('view', 'grid'); enable_disable_btn(); @@ -1262,7 +1262,7 @@ define([ }); // Show list mode - $('.file_manager .list').click(function() { + $('.file_manager .list').on('click',() => { setViewButtonsFor('list'); $('.fileinfo').data('view', 'list'); enable_disable_btn(); @@ -1387,7 +1387,7 @@ define([ $('.upload').remove(); $('.create').before('<button value="Upload" type="button" title="Upload File" name="upload" id="upload" class="btn fa fa-upload upload" tabindex="6"><span></span></button> '); - $('#uploader .upload').unbind().click(function() { + $('#uploader .upload').off().on('click',() => { // we create prompt var msg = '<div id="dropzone-container">' + '<button class="fa fa-times dz_cross_btn" tabindex="7"></button>' + @@ -1443,7 +1443,7 @@ define([ acceptedFiles: acceptFiles, autoProcessQueue: true, init: function() { - $('.dz_cross_btn').unbind().on('click', function() { + $('.dz_cross_btn').off().on('click', function() { $('.file_manager .upload_file').toggle(); }); }, @@ -1533,7 +1533,7 @@ define([ $('.storage_dialog #uploader .input-path').attr('data-path', path); // create new folder - $('.create').unbind().click(function() { + $('.create').off().on('click',() => { var foldername = lg.new_folder; var $file_element, $file_element_list, diff --git a/web/pgadmin/misc/static/explain/js/explain.js b/web/pgadmin/misc/static/explain/js/explain.js index f406c3c..61cf8f9 100644 --- a/web/pgadmin/misc/static/explain/js/explain.js +++ b/web/pgadmin/misc/static/explain/js/explain.js @@ -576,7 +576,7 @@ define('pgadmin.misc.explain', [ // Draw tooltip var image_data = this.toJSON(); - image.mouseover(function() { + image.on('mouseover',() => { // Empty the tooltip content if it has any and add new data toolTipContainer.empty(); @@ -618,7 +618,7 @@ define('pgadmin.misc.explain', [ }); // Remove tooltip when mouse is out from node's area - image.mouseout(function() { + image.on('mouseout',() => { toolTipContainer.empty(); toolTipContainer.css({ 'opacity': '0', @@ -851,7 +851,7 @@ define('pgadmin.misc.explain', [ 'height': h * curr_zoom_factor, }); planDiv.data('zoom-factor', curr_zoom_factor); - zoomInBtn.blur(); + zoomInBtn.trigger('blur'); }); zoomOutBtn.on('click', function() { @@ -867,7 +867,7 @@ define('pgadmin.misc.explain', [ 'height': h * curr_zoom_factor, }); planDiv.data('zoom-factor', curr_zoom_factor); - zoomOutBtn.blur(); + zoomOutBtn.trigger('blur'); }); zoomToNormal.on('click', function() { @@ -883,7 +883,7 @@ define('pgadmin.misc.explain', [ 'height': h * curr_zoom_factor, }); planDiv.data('zoom-factor', curr_zoom_factor); - zoomToNormal.blur(); + zoomToNormal.trigger('blur'); }); }); diff --git a/web/pgadmin/static/js/alertify.pgadmin.defaults.js b/web/pgadmin/static/js/alertify.pgadmin.defaults.js index 887d08f..7c49980 100644 --- a/web/pgadmin/static/js/alertify.pgadmin.defaults.js +++ b/web/pgadmin/static/js/alertify.pgadmin.defaults.js @@ -96,7 +96,7 @@ define([ if (contentType) { try { if (contentType.indexOf('application/json') == 0) { - var resp = $.parseJSON(msg); + var resp = JSON.parse(msg); if (resp.result != null && (!resp.errormsg || resp.errormsg == '') && onJSONResult && typeof(onJSONResult) == 'function') { @@ -253,7 +253,7 @@ define([ var contentType = xhr.getResponseHeader('Content-Type'), jsonResp = contentType && contentType.indexOf('application/json') == 0 && - $.parseJSON(xhr.responseText); + JSON.parse(xhr.responseText); if ( jsonResp && ( diff --git a/web/pgadmin/static/js/backform.pgadmin.js b/web/pgadmin/static/js/backform.pgadmin.js index 97c52e1..c7b9849 100644 --- a/web/pgadmin/static/js/backform.pgadmin.js +++ b/web/pgadmin/static/js/backform.pgadmin.js @@ -1081,7 +1081,7 @@ define([ // Add button callback if (!(data.disabled || data.canAdd == false)) { - $dialog.find('button.add').first().click(function(e) { + $dialog.find('button.add').first().on('click',(e) => { e.preventDefault(); var canAddRow = _.isFunction(data.canAddRow) ? data.canAddRow.apply(self, [self.model]) : true; @@ -1361,7 +1361,7 @@ define([ var $dialog = gridBody.append(subNodeGrid); // Add button callback - $dialog.find('button.add').click(function(e) { + $dialog.find('button.add').on('click',(e) => { e.preventDefault(); var canAddRow = _.isFunction(data.canAddRow) ? data.canAddRow.apply(self, [self.model]) : true; @@ -1379,7 +1379,7 @@ define([ grid.insertRow({}); var newRow = $(grid.body.rows[collection.length - 1].$el); - newRow.attr('class', 'new').click(function() { + newRow.attr('class', 'new').on('click',() => { $(this).attr('class', 'editable'); }); $(newRow).pgMakeVisible('backform-tab'); @@ -2367,7 +2367,7 @@ define([ if (widget) { setTimeout(function() { picker.toggle(); - self.$el.find('input').first().blur(); + self.$el.find('input').first().trigger('blur'); }, 10); } else { setTimeout(function() { @@ -2380,7 +2380,7 @@ define([ // blur the input setTimeout( function() { - self.$el.find('input').first().blur(); + self.$el.find('input').first().trigger('blur'); }, 10 ); } @@ -2390,7 +2390,7 @@ define([ var picker = this; setTimeout(function() { picker.toggle(); - self.$el.find('input').first().blur(); + self.$el.find('input').first().trigger('blur'); }, 10); } }, diff --git a/web/pgadmin/static/js/backgrid.pgadmin.js b/web/pgadmin/static/js/backgrid.pgadmin.js index eb4516a..2e87fbf 100644 --- a/web/pgadmin/static/js/backgrid.pgadmin.js +++ b/web/pgadmin/static/js/backgrid.pgadmin.js @@ -348,7 +348,7 @@ define([ this.$el.html('<i class=\'fa fa-pencil-square-o\' title=\'' + _('Edit row') + '\'></i>'); this.delegateEvents(); if (this.grabFocus) - this.$el.focus(); + this.$el.trigger('focus'); return this; }, exitEditMode: function() { @@ -465,7 +465,7 @@ define([ enterEditMode: function() { this.$el.addClass('editor'); - $(this.$el.find('input')).focus(); + $(this.$el.find('input')).trigger('focus'); }, exitEditMode: function() { @@ -537,7 +537,7 @@ define([ }); self.model.trigger('backgrid:edited', self.model, self.column, command); - gotoCell.focus(); + gotoCell.trigger('focus'); } }, 20); } diff --git a/web/pgadmin/static/js/keyboard_shortcuts.js b/web/pgadmin/static/js/keyboard_shortcuts.js index 4619456..996a591 100644 --- a/web/pgadmin/static/js/keyboard_shortcuts.js +++ b/web/pgadmin/static/js/keyboard_shortcuts.js @@ -84,7 +84,7 @@ function keyboardShortcutsDebugger($el, event, user_defined_shortcuts) { if(panel_content.length) { $input = $(panel_content).find('td.editable:first'); if($input.length) - $input.click(); + $input.trigger('click'); } } else if(this.validateShortcutKeys(next_panel_keys, event)) { this._stopEventPropagation(event); diff --git a/web/pgadmin/tools/backup/static/js/backup.js b/web/pgadmin/tools/backup/static/js/backup.js index 1b0b362..94ab8b7 100644 --- a/web/pgadmin/tools/backup/static/js/backup.js +++ b/web/pgadmin/tools/backup/static/js/backup.js @@ -755,7 +755,7 @@ commonUtils }, error: function(xhr) { try { - var err = $.parseJSON(xhr.responseText); + var err = JSON.parse(xhr.responseText); alertify.alert( gettext('Backup job failed.'), err.errormsg @@ -1041,7 +1041,7 @@ commonUtils }, error: function(xhr) { try { - var err = $.parseJSON(xhr.responseText); + var err = JSON.parse(xhr.responseText); alertify.alert( gettext('Backup job failed.'), err.errormsg diff --git a/web/pgadmin/tools/datagrid/static/js/datagrid.js b/web/pgadmin/tools/datagrid/static/js/datagrid.js index b0ed60f..42122ed 100644 --- a/web/pgadmin/tools/datagrid/static/js/datagrid.js +++ b/web/pgadmin/tools/datagrid/static/js/datagrid.js @@ -473,7 +473,7 @@ define('pgadmin.datagrid', [ } try { - var err = $.parseJSON(xhr.responseText); + var err = JSON.parse(xhr.responseText); alertify.alert(gettext('Query Tool Initialize Error'), err.errormsg ); diff --git a/web/pgadmin/tools/datagrid/templates/datagrid/index.html b/web/pgadmin/tools/datagrid/templates/datagrid/index.html index 26ef744..ad09026 100644 --- a/web/pgadmin/tools/datagrid/templates/datagrid/index.html +++ b/web/pgadmin/tools/datagrid/templates/datagrid/index.html @@ -222,7 +222,7 @@ </div> <div class="btn-group" role="group" aria-label=""> - <button id="btn-flash" type="button" class="btn btn-default" style="width: 40px;" + <button id="btn-flash" data-test-selector="execute-refresh-button" type="button" class="btn btn-default" style="width: 40px;" title="{{ _('Execute/Refresh') }}{{ _(' ({0})'.format(get_shortcut_text(shortcuts.execute_query))) }}" tabindex="0"> <i class="fa fa-bolt" aria-hidden="true"></i> diff --git a/web/pgadmin/tools/debugger/static/js/debugger.js b/web/pgadmin/tools/debugger/static/js/debugger.js index 6838335..14c2ccf 100644 --- a/web/pgadmin/tools/debugger/static/js/debugger.js +++ b/web/pgadmin/tools/debugger/static/js/debugger.js @@ -295,7 +295,7 @@ define([ }, error: function(xhr) { try { - var err = $.parseJSON(xhr.responseText); + var err = JSON.parse(xhr.responseText); if (err.success == 0) { Alertify.alert(gettext('Debugger Error'), err.errormsg); } @@ -415,7 +415,7 @@ define([ }, error: function(xhr) { try { - var err = $.parseJSON(xhr.responseText); + var err = JSON.parse(xhr.responseText); if (err.success == 0) { Alertify.alert(gettext('Debugger Error'), err.errormsg); } @@ -538,7 +538,7 @@ define([ }, error: function(xhr) { try { - var err = $.parseJSON(xhr.responseText); + var err = JSON.parse(xhr.responseText); if (err.success == 0) { Alertify.alert(gettext('Debugger Error'), err.errormsg); } diff --git a/web/pgadmin/tools/debugger/static/js/debugger_ui.js b/web/pgadmin/tools/debugger/static/js/debugger_ui.js index f9049d8..d88ac87 100644 --- a/web/pgadmin/tools/debugger/static/js/debugger_ui.js +++ b/web/pgadmin/tools/debugger/static/js/debugger_ui.js @@ -531,7 +531,7 @@ define([ var grid_checkbox = $(grid.el).find('input:checkbox').first(); if (grid_checkbox.length) { setTimeout(function() { - grid_checkbox.click(); + grid_checkbox.trigger('click'); }, 250); } diff --git a/web/pgadmin/tools/debugger/static/js/direct.js b/web/pgadmin/tools/debugger/static/js/direct.js index 42b2408..f7f8edf 100644 --- a/web/pgadmin/tools/debugger/static/js/direct.js +++ b/web/pgadmin/tools/debugger/static/js/direct.js @@ -690,7 +690,7 @@ define([ }, error: function(xhr) { try { - var err = $.parseJSON(xhr.responseText); + var err = JSON.parse(xhr.responseText); if (err.success == 0) { Alertify.alert(gettext('Debugger Error'), err.errormsg); } diff --git a/web/pgadmin/tools/grant_wizard/static/js/grant_wizard.js b/web/pgadmin/tools/grant_wizard/static/js/grant_wizard.js index 750887e..5ce0e2f 100644 --- a/web/pgadmin/tools/grant_wizard/static/js/grant_wizard.js +++ b/web/pgadmin/tools/grant_wizard/static/js/grant_wizard.js @@ -218,7 +218,6 @@ define([ // Generate wizard main container var $container = $('<div class=\'wizard_dlg\'></div>'); - return { main: function(title) { this.set('title', title); @@ -442,7 +441,7 @@ define([ 'did': encodeURI(did), } ), - dataType: 'jsonp', + dataType: 'json', }); }, diff --git a/web/pgadmin/tools/import_export/static/js/import_export.js b/web/pgadmin/tools/import_export/static/js/import_export.js index 3058f12..e64d3de 100644 --- a/web/pgadmin/tools/import_export/static/js/import_export.js +++ b/web/pgadmin/tools/import_export/static/js/import_export.js @@ -549,7 +549,7 @@ Backform, commonUtils }, error: function(xhr) { try { - var err = $.parseJSON(xhr.responseText); + var err = JSON.parse(xhr.responseText); Alertify.alert( gettext('Import/export job failed.'), err.errormsg diff --git a/web/pgadmin/tools/restore/static/js/restore.js b/web/pgadmin/tools/restore/static/js/restore.js index 585b972..7daa764 100644 --- a/web/pgadmin/tools/restore/static/js/restore.js +++ b/web/pgadmin/tools/restore/static/js/restore.js @@ -686,7 +686,7 @@ commonUtils }, error: function(xhr) { try { - var err = $.parseJSON(xhr.responseText); + var err = JSON.parse(xhr.responseText); alertify.alert( gettext('Restore failed.'), err.errormsg diff --git a/web/pgadmin/tools/user_management/static/js/user_management.js b/web/pgadmin/tools/user_management/static/js/user_management.js index dcf65cb..ec3d515 100644 --- a/web/pgadmin/tools/user_management/static/js/user_management.js +++ b/web/pgadmin/tools/user_management/static/js/user_management.js @@ -812,12 +812,12 @@ define([ userCollection.fetch(); - this.$content.find('a.close-error').click(function() { + this.$content.find('a.close-error').on('click',() => { $statusBar.find('.alert-text').empty(); $statusBar.css('visibility', 'hidden'); }); - this.$content.find('button.add').first().click(function(e) { + this.$content.find('button.add').first().on('click',(e) => { e.preventDefault(); var canAddRow = true; diff --git a/web/regression/javascript/selection/column_selector_spec.js b/web/regression/javascript/selection/column_selector_spec.js index b7f1475..53de6b2 100644 --- a/web/regression/javascript/selection/column_selector_spec.js +++ b/web/regression/javascript/selection/column_selector_spec.js @@ -273,7 +273,7 @@ describe('ColumnSelector', function () { describe('when the column is not selectable', function () { it('does not select the column', function () { - $(container.find('.slick-header-column:contains(some-non-selectable-column)')).click(); + $(container.find('.slick-header-column:contains(some-non-selectable-column)')).trigger('click'); var selectedRanges = cellSelectionModel.getSelectedRanges(); expect(selectedRanges.length).toEqual(0); diff --git a/web/regression/javascript/selection/grid_selector_spec.js b/web/regression/javascript/selection/grid_selector_spec.js index 33e2753..e3a758e 100644 --- a/web/regression/javascript/selection/grid_selector_spec.js +++ b/web/regression/javascript/selection/grid_selector_spec.js @@ -68,7 +68,7 @@ describe('GridSelector', function () { describe('when the cell for the select/deselect all is clicked', function () { it('selects the whole grid', function () { - container.find('[title=\'Select/Deselect All\']').parent().click(); + container.find('[title=\'Select/Deselect All\']').parent().trigger('click'); var selectedRanges = xCellSelectionModel.getSelectedRanges(); expect(selectedRanges.length).toBe(1); @@ -80,7 +80,7 @@ describe('GridSelector', function () { }); it('adds selected class', function () { - container.find('[title=\'Select/Deselect All\']').parent().click(); + container.find('[title=\'Select/Deselect All\']').parent().trigger('click'); expect($(container.find('[data-id=\'select-all\']')).hasClass('selected')).toBeTruthy(); }); @@ -89,7 +89,7 @@ describe('GridSelector', function () { describe('when the select all button in the corner gets selected', function () { it('selects all the cells', function () { - container.find('[title=\'Select/Deselect All\']').click(); + container.find('[title=\'Select/Deselect All\']').trigger('click'); var selectedRanges = xCellSelectionModel.getSelectedRanges(); expect(selectedRanges.length).toBe(1); @@ -102,11 +102,11 @@ describe('GridSelector', function () { describe('when the select all button in the corner gets deselected', function () { beforeEach(function () { - container.find('[title=\'Select/Deselect All\']').click(); + container.find('[title=\'Select/Deselect All\']').trigger('click'); }); it('deselects all the cells', function () { - container.find('[title=\'Select/Deselect All\']').click(); + container.find('[title=\'Select/Deselect All\']').trigger('click'); var selectedRanges = xCellSelectionModel.getSelectedRanges(); expect(selectedRanges.length).toBe(0); @@ -115,11 +115,11 @@ describe('GridSelector', function () { describe('and then the underlying selection changes', function () { beforeEach(function () { - container.find('[title=\'Select/Deselect All\']').click(); + container.find('[title=\'Select/Deselect All\']').trigger('click'); }); it('removes the selected class', function () { - container.find('[title=\'Select/Deselect All\']').parent().click(); + container.find('[title=\'Select/Deselect All\']').parent().trigger('click'); expect($(container.find('[data-id=\'select-all\']')).hasClass('selected')).toBeFalsy(); }); diff --git a/web/regression/javascript/slickgrid/cell_selector_spec.js b/web/regression/javascript/slickgrid/cell_selector_spec.js index a8db27e..4b33f57 100644 --- a/web/regression/javascript/slickgrid/cell_selector_spec.js +++ b/web/regression/javascript/slickgrid/cell_selector_spec.js @@ -54,7 +54,7 @@ describe('CellSelector', function () { describe('when the user clicks or tabs to a cell', function () { it('sets the selected range to that cell', function () { var row = 1, column = 0; - $(container.find('.slick-row .slick-cell.l' + column)[row]).click(); + $(container.find('.slick-row .slick-cell.l' + column)[row]).trigger('click'); var selectedRanges = cellSelectionModel.getSelectedRanges(); expect(selectedRanges.length).toBe(1); @@ -71,7 +71,7 @@ describe('CellSelector', function () { cellSelectionModel.setSelectedRanges(ranges); var row = 4, column = 1; - $(container.find('.slick-row .slick-cell.l' + column)[row]).click(); + $(container.find('.slick-row .slick-cell.l' + column)[row]).trigger('click'); expect(RangeSelectionHelper.isRangeSelected(cellSelectionModel.getSelectedRanges(), row2Range)) .toBe(false); diff --git a/web/regression/javascript/sqleditor/execute_query_spec.js b/web/regression/javascript/sqleditor/execute_query_spec.js index 06fefff..a874150 100644 --- a/web/regression/javascript/sqleditor/execute_query_spec.js +++ b/web/regression/javascript/sqleditor/execute_query_spec.js @@ -25,7 +25,7 @@ describe('ExecuteQuery', () => { const startTime = new Date(2018, 1, 29, 12, 15, 52); beforeEach(() => { networkMock = new MockAdapter(axios); - jasmine.addMatchers({jQuerytoHaveBeenCalledWith: jQuerytoHaveBeenCalledWith}); + // jasmine.addMatchers({jQuerytoHaveBeenCalledWith: jQuerytoHaveBeenCalledWith}); userManagementMock = jasmine.createSpyObj('UserManagement', [ 'isPgaLoginRequired', 'pgaLogin', @@ -1074,15 +1074,24 @@ describe('ExecuteQuery', () => { context('when the SQL statement is not empty', () => { let pollSpy; - let jqueryPropSpy; beforeEach(() => { - jqueryPropSpy = spyOn($.fn, 'prop'); sqlEditorMock.gridView = {}; sqlEditorMock.gridView.query_tool_obj = jasmine.createSpyObj( 'QueryToolObject', ['removeLineClass'] ); + + $('body').append( + '<div id="test-id">' + + '<button id="btn-flash" disabled></button>' + + '<button id="btn-cancel-query"></button>' + + '</div>' + ); + }); + + afterEach(function () { + $('body').remove('#test-id'); }); describe('before the backend request', () => { @@ -1108,15 +1117,15 @@ describe('ExecuteQuery', () => { }); it('disables the run query button', () => { - const callToProp = findJQueryCallWithSelector(jqueryPropSpy, '#btn-flash'); + let buttonFlash = $('#btn-flash'); - expect(callToProp).jQuerytoHaveBeenCalledWith('disabled', true); + expect(buttonFlash.prop('disabled')).toEqual(true); }); it('enable the cancel query button', () => { - const callToProp = findJQueryCallWithSelector(jqueryPropSpy, '#btn-cancel-query'); + let buttonFlash = $('#btn-cancel-query'); - expect(callToProp).jQuerytoHaveBeenCalledWith('disabled', false); + expect(buttonFlash.prop('disabled')).toEqual(false); }); it('disable the query tool buttons', () => { @@ -1235,9 +1244,9 @@ describe('ExecuteQuery', () => { it('disable the cancel query button', (done) => { setTimeout(() => { - const callToProp = findJQueryCallWithSelector(jqueryPropSpy, '#btn-cancel-query'); + let buttonFlash = $('#btn-cancel-query'); - expect(callToProp).jQuerytoHaveBeenCalledWith('disabled', true); + expect(buttonFlash.prop('disabled')).toEqual(true); done(); }, 0); }); @@ -1355,9 +1364,9 @@ describe('ExecuteQuery', () => { it('should disable the cancel button', (done) => { setTimeout( () => { - const callToProp = findJQueryCallWithSelector(jqueryPropSpy, '#btn-cancel-query'); + let buttonFlash = $('#btn-cancel-query'); - expect(callToProp).jQuerytoHaveBeenCalledWith('disabled', true); + expect(buttonFlash.prop('disabled')).toEqual(true); done(); }, 0); }); @@ -1413,9 +1422,9 @@ describe('ExecuteQuery', () => { it('should disable the cancel button', (done) => { setTimeout( () => { - const callToProp = findJQueryCallWithSelector(jqueryPropSpy, '#btn-cancel-query'); + let buttonFlash = $('#btn-cancel-query'); - expect(callToProp).jQuerytoHaveBeenCalledWith('disabled', true); + expect(buttonFlash.prop('disabled')).toEqual(true); done(); }, 0); }); @@ -1481,9 +1490,9 @@ describe('ExecuteQuery', () => { it('should disable the cancel button', (done) => { setTimeout( () => { - const callToProp = findJQueryCallWithSelector(jqueryPropSpy, '#btn-cancel-query'); + let buttonFlash = $('#btn-cancel-query'); - expect(callToProp).jQuerytoHaveBeenCalledWith('disabled', true); + expect(buttonFlash.prop('disabled')).toEqual(true); done(); }, 0); }); @@ -1552,9 +1561,9 @@ describe('ExecuteQuery', () => { it('should disable the cancel button', (done) => { setTimeout( () => { - const callToProp = findJQueryCallWithSelector(jqueryPropSpy, '#btn-cancel-query'); + let buttonFlash = $('#btn-cancel-query'); - expect(callToProp).jQuerytoHaveBeenCalledWith('disabled', true); + expect(buttonFlash.prop('disabled')).toEqual(true); done(); }, 0); }); @@ -1626,9 +1635,9 @@ describe('ExecuteQuery', () => { it('should disable the cancel button', (done) => { setTimeout( () => { - const callToProp = findJQueryCallWithSelector(jqueryPropSpy, '#btn-cancel-query'); + let buttonFlash = $('#btn-cancel-query'); - expect(callToProp).jQuerytoHaveBeenCalledWith('disabled', true); + expect(buttonFlash.prop('disabled')).toEqual(true); done(); }, 0); }); @@ -1682,43 +1691,5 @@ describe('ExecuteQuery', () => { }); }); - - let findJQueryCallWithSelector = (jquerySpy, selector) => { - let result = undefined; - - jquerySpy.calls.all().forEach((call) => { - if (call.object.selector === selector) { - result = call; - } - }); - return result; - }; }); -const jQuerytoHaveBeenCalledWith = function (util) { - return { - compare: function (actual) { - let result = {}; - let expectedArgs = jasmine.util.argsToArray(arguments).slice(1); - if (actual.object === undefined || actual.object.selector === undefined) { - throw new Error('Expected a JQuery object, but got ' + jasmine.pp(actual) + '.'); - } - - result.pass = util.equals(actual.args, expectedArgs, ''); - if (result.pass) { - result.message = 'larifo'; - } else { - result.message = - 'Expected jquery with selector "' + - actual.object.selector + - '" to have been called with ' + - jasmine.pp(expectedArgs) + - ' but was called with ' + - jasmine.pp(actual.args); - } - - return result; - }, - }; -}; -