diff options
| author | Gav O'Connor <scalamoosh@gmail.com> | 2022-08-09 17:31:27 +0100 |
|---|---|---|
| committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2022-09-06 10:38:28 +0200 |
| commit | fc220d27c624ba5e78988d0545bb241e2c0a8c22 (patch) | |
| tree | 86203848d1d3f8afe98eec6e2961ede2a53b8d96 /js_tests | |
| parent | 69fa2e8eb25d9bdd395fa8857177d4637aaf4c55 (diff) | |
Refs #24179 -- Added extra JS tests for admin vertical/horizontal filters.
Diffstat (limited to 'js_tests')
| -rw-r--r-- | js_tests/admin/SelectFilter2.test.js | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/js_tests/admin/SelectFilter2.test.js b/js_tests/admin/SelectFilter2.test.js index f65965c4fb..32a30c5889 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; + $('<form><select multiple id="select"></select></form>').appendTo('#qunit-fixture'); + $('<option value="1" title="Red">Red</option>').appendTo('#select'); + $('<option value="2" title="Blue">Blue</option>').appendTo('#select'); + $('<option value="3" title="Green">Green</option>').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; + $('<form><select multiple id="select"></select></form>').appendTo('#qunit-fixture'); + $('<option value="1" title="Red">Red</option>').appendTo('#select'); + $('<option value="2" title="Blue">Blue</option>').appendTo('#select'); + $('<option value="3" title="Green">Green</option>').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; + $('<form><select multiple id="select"></select></form>').appendTo('#qunit-fixture'); + $('<option value="1" title="Red">Red</option>').appendTo('#select'); + $('<option value="2" title="Blue">Blue</option>').appendTo('#select'); + $('<option value="3" title="Green">Green</option>').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(); + }); +}); |
