Changeset 65349
- Timestamp:
- 11/09/2026 03:29:44 PM (7 days ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
src/js/_enqueues/wp/updates.js (modified) (2 diffs)
-
tests/qunit/wp-admin/js/updates.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/js/_enqueues/wp/updates.js
r64498 r65349 1448 1448 } 1449 1449 1450 // Remove from the other groups, such as those added through the `plugins_list` filter. 1451 _.each( _.keys( plugins ), function( group ) { 1452 var $view; 1453 1454 if ( 'all' === group || ! _.isArray( plugins[ group ] ) || -1 === _.indexOf( plugins[ group ], response.plugin ) ) { 1455 return; 1456 } 1457 1458 plugins[ group ] = _.without( plugins[ group ], response.plugin ); 1459 $view = $views.children( 'li.' + $.escapeSelector( group ) ); 1460 1461 if ( plugins[ group ].length ) { 1462 $view.find( '.count' ).text( '(' + plugins[ group ].length + ')' ); 1463 } else { 1464 $view.remove(); 1465 } 1466 } ); 1467 1450 1468 plugins.all = _.without( plugins.all, response.plugin ); 1451 1469 … … 1460 1478 } 1461 1479 } 1480 1481 // Remove the trailing separator left on the last view when the view after it was removed. 1482 $views.find( 'li:last' ).html( function() { return $( this ).children(); } ); 1462 1483 1463 1484 if ( $itemsCount.length && $currentView.length ) { -
trunk/tests/qunit/wp-admin/js/updates.js
r57987 r65349 109 109 assert.equal( jQuery.ajax.getCall( 0 ).args[0].data.slug, 'test' ); 110 110 } ); 111 111 112 QUnit.test( 'Installing a plugin should call the API', function( assert ) { 112 113 wp.updates.installPlugin( { slug: 'jetpack' } ); … … 116 117 assert.equal( jQuery.ajax.getCall( 0 ).args[0].data.slug, 'jetpack' ); 117 118 } ); 119 118 120 QUnit.test( 'Deleting a plugin should call the API', function( assert ) { 119 121 wp.updates.deletePlugin( { slug: 'jetpack', plugin: 'jetpack/jetpack.php' } ); … … 122 124 assert.equal( jQuery.ajax.getCall( 0 ).args[0].data.action, 'delete-plugin' ); 123 125 assert.equal( jQuery.ajax.getCall( 0 ).args[0].data.slug, 'jetpack' ); 126 } ); 127 128 QUnit.test( 'Deleting a plugin should update the counts of custom plugin groups', function( assert ) { 129 var plugins = window._wpUpdatesSettings.plugins; 130 131 $( '#qunit-fixture' ).append( 132 '<script type="text/html" id="tmpl-item-deleted-row"><tr class="plugin-deleted-tr"><td colspan="{{ data.colspan }}"></td></tr></script>' + 133 '<ul class="subsubsub">' + 134 '<li class="all"><a href="#">All <span class="count">(3)</span></a> |</li>' + 135 '<li class="inactive"><a href="#">Inactive <span class="count">(2)</span></a> |</li>' + 136 '<li class="demo_group"><a href="#">Demo Group <span class="count">(2)</span></a> |</li>' + 137 '<li class="single_group"><a href="#">Single Group <span class="count">(1)</span></a></li>' + 138 '</ul>' + 139 '<form id="bulk-action-form"><table><tbody id="the-list">' + 140 '<tr data-plugin="custom-a/custom-a.php"><td></td></tr>' + 141 '</tbody></table></form>' 142 ); 143 144 window._wpUpdatesSettings.plugins = { 145 all: [ 'custom-a/custom-a.php', 'custom-b/custom-b.php', 'other/other.php' ], 146 inactive: [ 'custom-a/custom-a.php', 'other/other.php' ], 147 demo_group: [ 'custom-a/custom-a.php', 'custom-b/custom-b.php' ], 148 single_group: [ 'custom-a/custom-a.php' ] 149 }; 150 151 // Run the fade out callback right away. 152 sinon.stub( $.fn, 'fadeOut' ).callsFake( function( speed, callback ) { 153 return this.each( callback ); 154 } ); 155 156 wp.updates.deletePluginSuccess( { slug: 'custom-a', plugin: 'custom-a/custom-a.php', pluginName: 'Custom A' } ); 157 158 $.fn.fadeOut.restore(); 159 160 assert.equal( $( '.subsubsub .all .count' ).text(), '(2)', 'The All count should go down.' ); 161 assert.equal( $( '.subsubsub .inactive .count' ).text(), '(1)', 'The Inactive count should go down only once.' ); 162 assert.equal( $( '.subsubsub .demo_group .count' ).text(), '(1)', 'The custom group count should go down.' ); 163 assert.strictEqual( $( '.subsubsub .single_group' ).length, 0, 'An empty custom group should be removed.' ); 164 assert.strictEqual( $( '.subsubsub .all' ).text(), 'All (2) |', 'Separators between views should be kept.' ); 165 assert.strictEqual( $( '.subsubsub .demo_group' ).text(), 'Demo Group (1)', 'The new last view should not end with a separator.' ); 166 assert.deepEqual( window._wpUpdatesSettings.plugins.demo_group, [ 'custom-b/custom-b.php' ], 'The deleted plugin should be removed from the custom group.' ); 167 168 window._wpUpdatesSettings.plugins = plugins; 169 } ); 170 171 QUnit.test( 'Deleting a plugin should only remove the view of an emptied custom group', function( assert ) { 172 var plugins = window._wpUpdatesSettings.plugins; 173 174 $( '#qunit-fixture' ).append( 175 '<script type="text/html" id="tmpl-item-deleted-row"><tr class="plugin-deleted-tr"><td colspan="{{ data.colspan }}"></td></tr></script>' + 176 '<ul class="subsubsub">' + 177 '<li class="all"><a href="#">All <span class="count">(2)</span></a> |</li>' + 178 '<li class="count"><a href="#">Count <span class="count">(1)</span></a></li>' + 179 '</ul>' + 180 '<form id="bulk-action-form"><table><tbody id="the-list">' + 181 '<tr data-plugin="custom-a/custom-a.php"><td></td></tr>' + 182 '</tbody></table></form>' 183 ); 184 185 // A group key that matches the class of the count elements. 186 window._wpUpdatesSettings.plugins = { 187 all: [ 'custom-a/custom-a.php', 'other/other.php' ], 188 count: [ 'custom-a/custom-a.php' ] 189 }; 190 191 sinon.stub( $.fn, 'fadeOut' ).callsFake( function( speed, callback ) { 192 return this.each( callback ); 193 } ); 194 195 wp.updates.deletePluginSuccess( { slug: 'custom-a', plugin: 'custom-a/custom-a.php', pluginName: 'Custom A' } ); 196 197 $.fn.fadeOut.restore(); 198 199 assert.strictEqual( $( '.subsubsub > li.count' ).length, 0, 'The emptied group view should be removed.' ); 200 assert.strictEqual( $( '.subsubsub .all' ).text(), 'All (1)', 'The All view should keep its count.' ); 201 202 window._wpUpdatesSettings.plugins = plugins; 124 203 } ); 125 204
Note:
See TracChangeset
for help on using the changeset viewer.