From fc220d27c624ba5e78988d0545bb241e2c0a8c22 Mon Sep 17 00:00:00 2001 From: Gav O'Connor Date: Tue, 9 Aug 2022 17:31:27 +0100 Subject: [PATCH] Refs #24179 -- Added extra JS tests for admin vertical/horizontal filters. --- js_tests/admin/SelectFilter2.test.js | 66 ++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/js_tests/admin/SelectFilter2.test.js b/js_tests/admin/SelectFilter2.test.js index f65965c4fb8..32a30c5889e 100644 --- a/js_tests/admin/SelectFilter2.test.js +++ b/js_tests/admin/SelectFilter2.test.js @@ -16,3 +16,69 @@ QUnit.test('init', function(assert) { assert.equal($('.selector-remove').text(), "Remove"); assert.equal($('.selector-clearall').text(), "Remove all"); }); + +QUnit.test('filtering available options', function(assert) { + const $ = django.jQuery; + $('
').appendTo('#qunit-fixture'); + $('').appendTo('#select'); + $('').appendTo('#select'); + $('').appendTo('#select'); + SelectFilter.init('select', 'items', 0); + assert.equal($('#select_from option').length, 3); + assert.equal($('#select_to option').length, 0); + const done = assert.async(); + const search_term = 'r'; + const event = new KeyboardEvent('keyup', {'key': search_term}); + $('#select_input').val(search_term); + SelectFilter.filter_key_up(event, 'select'); + setTimeout(() => { + assert.equal($('#select_from option').length, 2); + assert.equal($('#select_to option').length, 0); + assert.equal($('#select_from option')[0].value, '1'); + assert.equal($('#select_from option')[1].value, '3'); + done(); + }); +}); + +QUnit.test('filtering available options to nothing', function(assert) { + const $ = django.jQuery; + $('
').appendTo('#qunit-fixture'); + $('').appendTo('#select'); + $('').appendTo('#select'); + $('').appendTo('#select'); + SelectFilter.init('select', 'items', 0); + assert.equal($('#select_from option').length, 3); + assert.equal($('#select_to option').length, 0); + const done = assert.async(); + const search_term = 'x'; + const event = new KeyboardEvent('keyup', {'key': search_term}); + $('#select_input').val(search_term); + SelectFilter.filter_key_up(event, 'select'); + setTimeout(() => { + assert.equal($('#select_from option').length, 0); + assert.equal($('#select_to option').length, 0); + done(); + }); +}); + +QUnit.test('selecting option', function(assert) { + const $ = django.jQuery; + $('
').appendTo('#qunit-fixture'); + $('').appendTo('#select'); + $('').appendTo('#select'); + $('').appendTo('#select'); + SelectFilter.init('select', 'items', 0); + assert.equal($('#select_from option').length, 3); + assert.equal($('#select_to option').length, 0); + // move to the right + const done = assert.async(); + $('#select_from')[0].selectedIndex = 0; + const event = new KeyboardEvent('keydown', {'keyCode': 39, 'charCode': 39}); + SelectFilter.filter_key_down(event, 'select'); + setTimeout(() => { + assert.equal($('#select_from option').length, 2); + assert.equal($('#select_to option').length, 1); + assert.equal($('#select_to option')[0].value, '1'); + done(); + }); +});