diff --git a/tests/selection/focusing-tests.js b/tests/selection/focusing-tests.js index fcb2c6e7be..f54aa351ff 100644 --- a/tests/selection/focusing-tests.js +++ b/tests/selection/focusing-tests.js @@ -2,11 +2,47 @@ module('Selection containers - Managing focus'); var SingleSelection = require('select2/selection/single'); +var Dropdown = require('select2/dropdown'); +var DropdownSearch = Utils.Decorate( + Dropdown, + require('select2/dropdown/search') +); + var $ = require('jquery'); var Options = require('select2/options'); var options = new Options({}); +test('open sets the focus to the search control', function (assert) { + var $container = $('#qunit-fixture .event-container'); + var container = new MockContainer(); + var selection = new DropdownSearch( + $('#qunit-fixture .single'), + options + ); + + var $selection = selection.render(); + selection.bind(container, $container); + + $container.append($selection); + + var $search = $selection.find('input'); + + assert.notEqual( + document.activeElement, + $search[0], + 'The selection had focus originally' + ); + + container.trigger('open'); + + assert.equal( + document.activeElement, + $search[0], + 'After close, focus must be set to selection' + ); +}); + test('close sets the focus to the selection', function (assert) { var $container = $('#qunit-fixture .event-container'); var container = new MockContainer();