| 1 |
/* global QUnit, initSidebarQuickFilter */ |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
QUnit.module('admin.sidebar: filter', { |
| 5 |
beforeEach: function() { |
| 6 |
const $ = django.jQuery; |
| 7 |
$('#qunit-fixture').append($('#nav-sidebar-filter').text()); |
| 8 |
this.navSidebar = $('#nav-sidebar'); |
| 9 |
this.navFilter = $('#nav-filter'); |
| 10 |
initSidebarQuickFilter(); |
| 11 |
} |
| 12 |
}); |
| 13 |
|
| 14 |
QUnit.test('filter by a model name', function(assert) { |
| 15 |
assert.equal(this.navSidebar.find('th[scope=row] a').length, 2); |
| 16 |
|
| 17 |
this.navFilter.val('us'); // Matches 'users'. |
| 18 |
this.navFilter[0].dispatchEvent(new Event('change')); |
| 19 |
assert.equal(this.navSidebar.find('tr[class^="model-"]:visible').length, 1); |
| 20 |
|
| 21 |
this.navFilter.val('nonexistent'); |
| 22 |
this.navFilter[0].dispatchEvent(new Event('change')); |
| 23 |
assert.equal(this.navSidebar.find('tr[class^="model-"]:visible').length, 0); |
| 24 |
}); |