Skip to content

Commit 04e5f4f

Browse files
committed
Fix: Update Count - Value Should Change as Updates are Applied
1 parent e12ddb3 commit 04e5f4f

4 files changed

Lines changed: 32 additions & 3 deletions

File tree

src/js/_enqueues/wp/updates.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@
391391
$pluginsNavMenuUpdateCount.each( function( index, element ) {
392392
element.className = element.className.replace( /count-\d+/, 'count-' + settings.totals.counts.plugins );
393393
} );
394-
if ( settings.totals.counts.total > 0 ) {
394+
if ( settings.totals.counts.plugins > 0 ) {
395395
$pluginsNavMenuUpdateCount.find( '.plugin-count' ).text( settings.totals.counts.plugins );
396396
} else {
397397
$pluginsNavMenuUpdateCount.remove();
@@ -401,7 +401,7 @@
401401
$appearanceNavMenuUpdateCount.each( function( index, element ) {
402402
element.className = element.className.replace( /count-\d+/, 'count-' + settings.totals.counts.themes );
403403
} );
404-
if ( settings.totals.counts.total > 0 ) {
404+
if ( settings.totals.counts.themes > 0 ) {
405405
$appearanceNavMenuUpdateCount.find( '.theme-count' ).text( settings.totals.counts.themes );
406406
} else {
407407
$appearanceNavMenuUpdateCount.remove();

tests/qunit/fixtures/updates.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,13 @@ window._wpUpdatesSettings = {
5959
};
6060
window._wpUpdatesItemCounts = {
6161
plugins: {},
62-
totals: {}
62+
totals: {
63+
counts: {
64+
plugins: 2,
65+
themes: 0,
66+
wordpress: 0,
67+
translations: 0,
68+
total: 2
69+
}
70+
}
6371
};

tests/qunit/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,6 +2314,12 @@ <h2>Preview</h2>
23142314
</li>
23152315
</ul>
23162316
</li>
2317+
<li class="wp-has-submenu wp-not-current-submenu menu-top menu-icon-appearance" id="menu-appearance">
2318+
<a href="themes.php" class="wp-has-submenu wp-not-current-submenu menu-top menu-icon-appearance" aria-haspopup="true">
2319+
<div class="wp-menu-image dashicons-before dashicons-admin-appearance"><br></div>
2320+
<div class="wp-menu-name">Appearance</div>
2321+
</a>
2322+
</li>
23172323
</ul>
23182324
</div>
23192325
</body>

tests/qunit/wp-admin/js/updates.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ jQuery( function( $ ) {
3333
assert.equal( adminItemCount, 1 );
3434
});
3535

36+
QUnit.test( 'decrementCount removes the plugin badge when plugin count reaches zero', function( assert ) {
37+
// Arrange: set up 1 plugin update with a non-zero total so the admin bar stays visible.
38+
window._wpUpdatesSettings.totals.counts.plugins = 1;
39+
window._wpUpdatesSettings.totals.counts.themes = 2;
40+
window._wpUpdatesSettings.totals.counts.total = 3;
41+
wp.updates.refreshCount();
42+
43+
// Act: update the last plugin.
44+
wp.updates.decrementCount( 'plugin' );
45+
46+
// Assert: plugin badge is removed when its own count hits zero, not when total hits zero.
47+
assert.strictEqual( $( '#menu-plugins .plugin-count' ).length, 0, 'Plugin badge is removed when plugin count is zero.' );
48+
assert.strictEqual( parseInt( $( '#wp-admin-bar-updates .ab-label' ).text(), 10 ), 2, 'Admin bar total reflects remaining theme updates.' );
49+
} );
50+
3651
QUnit.test( '`beforeunload` should only fire when locked', function( assert ) {
3752
wp.updates.ajaxLocked = false;
3853
assert.notOk( wp.updates.beforeunload(), '`beforeunload` should not fire.' );

0 commit comments

Comments
 (0)