Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/js/_enqueues/wp/updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
10 changes: 9 additions & 1 deletion tests/qunit/fixtures/updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,13 @@ window._wpUpdatesSettings = {
};
window._wpUpdatesItemCounts = {
plugins: {},
totals: {}
totals: {
counts: {
plugins: 2,
themes: 0,
wordpress: 0,
translations: 0,
total: 2
}
}
};
6 changes: 6 additions & 0 deletions tests/qunit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2314,6 +2314,12 @@ <h2>Preview</h2>
</li>
</ul>
</li>
<li class="wp-has-submenu wp-not-current-submenu menu-top menu-icon-appearance" id="menu-appearance">
<a href="themes.php" class="wp-has-submenu wp-not-current-submenu menu-top menu-icon-appearance" aria-haspopup="true">
<div class="wp-menu-image dashicons-before dashicons-admin-appearance"><br></div>
<div class="wp-menu-name">Appearance</div>
</a>
</li>
</ul>
</div>
</body>
Expand Down
15 changes: 15 additions & 0 deletions tests/qunit/wp-admin/js/updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.' );
Expand Down
Loading