navigation.test.js 836 B

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