Tests for the inline search box
This adds tests for the following commits5f80c5d9f8
395e06aff5
This commit is contained in:
parent
5f80c5d9f8
commit
e08222ef15
@ -9,6 +9,87 @@ var Utils = require('select2/utils');
|
|||||||
|
|
||||||
var options = new Options({});
|
var options = new Options({});
|
||||||
|
|
||||||
|
test('backspace will remove a choice', function (assert) {
|
||||||
|
expect(3);
|
||||||
|
|
||||||
|
var KEYS = require('select2/keys');
|
||||||
|
|
||||||
|
var $container = $('#qunit-fixture .event-container');
|
||||||
|
var container = new MockContainer();
|
||||||
|
|
||||||
|
var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
|
||||||
|
|
||||||
|
var $element = $('#qunit-fixture .multiple');
|
||||||
|
var selection = new CustomSelection($element, options);
|
||||||
|
|
||||||
|
var $selection = selection.render();
|
||||||
|
selection.bind(container, $container);
|
||||||
|
|
||||||
|
// The unselect event should be triggered at some point
|
||||||
|
selection.on('unselect', function () {
|
||||||
|
assert.ok(true, 'A choice was unselected');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add some selections and render the search
|
||||||
|
selection.update([
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
text: 'One'
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
var $search = $selection.find('input');
|
||||||
|
var $choices = $selection.find('.select2-selection__choice');
|
||||||
|
|
||||||
|
assert.equal($search.length, 1, 'The search was visible');
|
||||||
|
assert.equal($choices.length, 1, 'The choice was rendered');
|
||||||
|
|
||||||
|
// Trigger the backspace on the search
|
||||||
|
var backspace = $.Event('keydown', {
|
||||||
|
which: KEYS.BACKSPACE
|
||||||
|
});
|
||||||
|
$search.trigger(backspace);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('backspace will set the search text', function (assert) {
|
||||||
|
expect(3);
|
||||||
|
|
||||||
|
var KEYS = require('select2/keys');
|
||||||
|
|
||||||
|
var $container = $('#qunit-fixture .event-container');
|
||||||
|
var container = new MockContainer();
|
||||||
|
|
||||||
|
var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
|
||||||
|
|
||||||
|
var $element = $('#qunit-fixture .multiple');
|
||||||
|
var selection = new CustomSelection($element, options);
|
||||||
|
|
||||||
|
var $selection = selection.render();
|
||||||
|
selection.bind(container, $container);
|
||||||
|
|
||||||
|
// Add some selections and render the search
|
||||||
|
selection.update([
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
text: 'One'
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
var $search = $selection.find('input');
|
||||||
|
var $choices = $selection.find('.select2-selection__choice');
|
||||||
|
|
||||||
|
assert.equal($search.length, 1, 'The search was visible');
|
||||||
|
assert.equal($choices.length, 1, 'The choice was rendered');
|
||||||
|
|
||||||
|
// Trigger the backspace on the search
|
||||||
|
var backspace = $.Event('keydown', {
|
||||||
|
which: KEYS.BACKSPACE
|
||||||
|
});
|
||||||
|
$search.trigger(backspace);
|
||||||
|
|
||||||
|
assert.equal($search.val(), 'One', 'The search text was set');
|
||||||
|
});
|
||||||
|
|
||||||
test('updating selection does not shift the focus', function (assert) {
|
test('updating selection does not shift the focus', function (assert) {
|
||||||
// Check for IE 8, which triggers a false negative during testing
|
// Check for IE 8, which triggers a false negative during testing
|
||||||
if (window.attachEvent && !window.addEventListener) {
|
if (window.attachEvent && !window.addEventListener) {
|
||||||
|
Loading…
Reference in New Issue
Block a user