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
3 changes: 2 additions & 1 deletion src/js/_enqueues/wp/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -1781,8 +1781,9 @@ themes.view.Installer = themes.view.Appearance.extend({
$( 'body' ).removeClass( 'filters-applied show-filters' );
$( '.drawer-toggle' ).attr( 'aria-expanded', 'false' );

// Bail if this is already active.
// Bail if this is already active, restoring the URL if the filter drawer changed it.
if ( $el.hasClass( this.activeClass ) ) {
themes.router.navigate( themes.router.baseUrl( themes.router.browsePath + sort ) );
return;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/qunit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@
<script src="../../build/wp-admin/js/dashboard.js"></script>
<script src="../../build/wp-admin/js/password-strength-meter.js"></script>
<script src="../../build/wp-admin/js/postbox.js"></script>
<script>
window._wpThemeSettings = {"themes":[],"settings":{"isInstall":true,"adminUrl":"\/wp-admin\/"},"l10n":{},"installedThemes":[]};
</script>
<script src="../../build/wp-admin/js/theme.js"></script>
<script>
// Prevent the theme screens from booting on DOM ready; the tests exercise the views directly.
wp.themes.Run.init = wp.themes.RunInstaller.init = function() {};
</script>
<script src="../../build/wp-includes/js/dist/vendor/moment.js"></script>
<script src="../../build/wp-includes/js/dist/date.js"></script>
<script src="../../build/wp-includes/js/dist/i18n.js"></script>
Expand Down
47 changes: 47 additions & 0 deletions tests/qunit/wp-admin/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,51 @@
assert.equal( prevCalled, 0, 'Ctrl+Left does nothing' );
} );
} );
QUnit.module( 'Theme Installer sorting', function( hooks ) {
var originalRouter, originalSort, originalClearSearch, navigated, view;

hooks.beforeEach( function() {
navigated = [];
originalRouter = _.clone( wp.themes.router );
wp.themes.router.browsePath = '?browse=';
wp.themes.router.baseUrl = function( url ) {
return 'theme-install.php' + url;
};
wp.themes.router.navigate = function( url ) {
navigated.push( url );
};

$( '#qunit-fixture' ).html(
'<div class="wrap">' +
'<ul class="filter-links"><li><a href="#" class="current" data-sort="favorites">Favorites</a></li></ul>' +
'<button class="drawer-toggle" aria-expanded="true"></button>' +
'</div>'
);
$( 'body' ).addClass( 'show-filters' );

view = Object.create( wp.themes.view.Installer.prototype );
originalSort = view.sort;
originalClearSearch = view.clearSearch;
view.activeClass = 'current';
view.sort = function() {};
view.clearSearch = function() {};
} );

hooks.afterEach( function() {
wp.themes.router = originalRouter;
view.sort = originalSort;
view.clearSearch = originalClearSearch;
$( 'body' ).removeClass( 'show-filters filters-applied' );
} );

QUnit.test( 'Clicking the active tab restores its URL and closes the filter drawer', function( assert ) {
var $link = $( '.filter-links a' );

view.onSort( $.Event( 'click', { target: $link[ 0 ] } ) );

assert.strictEqual( navigated.length, 1, 'The router is updated once.' );
assert.ok( /\?browse=favorites$/.test( navigated[ 0 ] ), 'The URL is restored to the active tab.' );
assert.notOk( $( 'body' ).hasClass( 'show-filters' ), 'The filter drawer is closed.' );
} );
} );
})( jQuery );
Loading