Skip to content

Commit

Permalink
Add focus-on-open test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jayaddison committed May 24, 2023
1 parent eb043a8 commit 2d720e0
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/selection/focusing-tests.js
Expand Up @@ -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();
Expand Down

0 comments on commit 2d720e0

Please sign in to comment.