diff --git a/src/js/_enqueues/wp/updates.js b/src/js/_enqueues/wp/updates.js index ef4b47e66093e..af407f7026d08 100644 --- a/src/js/_enqueues/wp/updates.js +++ b/src/js/_enqueues/wp/updates.js @@ -391,7 +391,7 @@ $pluginsNavMenuUpdateCount.each( function( index, element ) { element.className = element.className.replace( /count-\d+/, 'count-' + settings.totals.counts.plugins ); } ); - if ( settings.totals.counts.total > 0 ) { + if ( settings.totals.counts.plugins > 0 ) { $pluginsNavMenuUpdateCount.find( '.plugin-count' ).text( settings.totals.counts.plugins ); } else { $pluginsNavMenuUpdateCount.remove(); @@ -401,7 +401,7 @@ $appearanceNavMenuUpdateCount.each( function( index, element ) { element.className = element.className.replace( /count-\d+/, 'count-' + settings.totals.counts.themes ); } ); - if ( settings.totals.counts.total > 0 ) { + if ( settings.totals.counts.themes > 0 ) { $appearanceNavMenuUpdateCount.find( '.theme-count' ).text( settings.totals.counts.themes ); } else { $appearanceNavMenuUpdateCount.remove(); diff --git a/tests/qunit/fixtures/updates.js b/tests/qunit/fixtures/updates.js index 7e31370814880..4ee72d9eb4bff 100644 --- a/tests/qunit/fixtures/updates.js +++ b/tests/qunit/fixtures/updates.js @@ -59,5 +59,13 @@ window._wpUpdatesSettings = { }; window._wpUpdatesItemCounts = { plugins: {}, - totals: {} + totals: { + counts: { + plugins: 2, + themes: 0, + wordpress: 0, + translations: 0, + total: 2 + } + } }; diff --git a/tests/qunit/index.html b/tests/qunit/index.html index 9fd35f0c1ffc2..7dd58bbacaf20 100644 --- a/tests/qunit/index.html +++ b/tests/qunit/index.html @@ -2314,6 +2314,12 @@

Preview

+ diff --git a/tests/qunit/wp-admin/js/updates.js b/tests/qunit/wp-admin/js/updates.js index 9d3948811abfd..88ba5b395c2ea 100644 --- a/tests/qunit/wp-admin/js/updates.js +++ b/tests/qunit/wp-admin/js/updates.js @@ -33,6 +33,21 @@ jQuery( function( $ ) { assert.equal( adminItemCount, 1 ); }); + QUnit.test( 'decrementCount removes the plugin badge when plugin count reaches zero', function( assert ) { + // Arrange: set up 1 plugin update with a non-zero total so the admin bar stays visible. + window._wpUpdatesSettings.totals.counts.plugins = 1; + window._wpUpdatesSettings.totals.counts.themes = 2; + window._wpUpdatesSettings.totals.counts.total = 3; + wp.updates.refreshCount(); + + // Act: update the last plugin. + wp.updates.decrementCount( 'plugin' ); + + // Assert: plugin badge is removed when its own count hits zero, not when total hits zero. + assert.strictEqual( $( '#menu-plugins .plugin-count' ).length, 0, 'Plugin badge is removed when plugin count is zero.' ); + assert.strictEqual( parseInt( $( '#wp-admin-bar-updates .ab-label' ).text(), 10 ), 2, 'Admin bar total reflects remaining theme updates.' ); + } ); + QUnit.test( '`beforeunload` should only fire when locked', function( assert ) { wp.updates.ajaxLocked = false; assert.notOk( wp.updates.beforeunload(), '`beforeunload` should not fire.' );