1
0
mirror of synced 2024-11-25 06:16:08 +03:00

Added tests for focusing results

This adds three tests related to focusing selected items in the results.
The tests are for e897d00 and 9f58128.
This commit is contained in:
Kevin Brown 2016-05-14 21:04:03 -04:00
parent 9f581285d8
commit acd3306192
2 changed files with 140 additions and 0 deletions

View File

@ -0,0 +1,138 @@
module('Results - highlighting results');
test('results:all with no data skips results:focus', function (assert) {
expect(0);
var $ = require('jquery');
var $select = $('<select></select>');
var $parent = $('<div></div>');
var $container = $('<span></span>');
var container = new MockContainer();
$parent.appendTo($('#qunit-fixture'));
$select.appendTo($parent);
var Utils = require('select2/utils');
var Options = require('select2/options');
var Results = require('select2/results');
var results = new Results($select, new Options({}));
// Fake the data adapter for the `setClasses` method
results.data = {};
results.data.current = function (callback) {
callback([{ id: 'test' }]);
};
results.render();
results.bind(container, $container);
results.on('results:focus', function (params) {
assert.ok(false, 'The results:focus event was triggered');
});
container.trigger('results:all', {
data: {
results: []
}
});
});
test('results:all triggers results:focus on the first item', function (assert) {
expect(2);
var $ = require('jquery');
var $select = $('<select></select>');
var $parent = $('<div></div>');
var $container = $('<span></span>');
var container = new MockContainer();
$parent.appendTo($('#qunit-fixture'));
$select.appendTo($parent);
var Utils = require('select2/utils');
var Options = require('select2/options');
var Results = require('select2/results');
var results = new Results($select, new Options({}));
// Fake the data adapter for the `setClasses` method
results.data = {};
results.data.current = function (callback) {
callback([{ id: 'test' }]);
};
results.render();
results.bind(container, $container);
results.on('results:focus', function (params) {
assert.equal(params.data.id, 'test');
assert.equal(params.data.text, 'Test');
});
container.trigger('results:all', {
data: {
results: [
{
id: 'test',
text: 'Test'
}
]
}
});
});
test('results:append does not trigger results:focus', function (assert) {
expect(0);
var $ = require('jquery');
var $select = $('<select></select>');
var $parent = $('<div></div>');
var $container = $('<span></span>');
var container = new MockContainer();
$parent.appendTo($('#qunit-fixture'));
$select.appendTo($parent);
var Utils = require('select2/utils');
var Options = require('select2/options');
var Results = require('select2/results');
var results = new Results($select, new Options({}));
// Fake the data adapter for the `setClasses` method
results.data = {};
results.data.current = function (callback) {
callback([{ id: 'test' }]);
};
results.render();
results.bind(container, $container);
results.on('results:focus', function () {
assert.ok(false, 'The results:focus event was triggered');
});
container.trigger('results:append', {
data: {
results: [
{
id: 'test',
text: 'Test'
}
]
}
});
});

View File

@ -79,6 +79,8 @@
<script src="options/translation-tests.js" type="text/javascript"></script> <script src="options/translation-tests.js" type="text/javascript"></script>
<script src="options/width-tests.js" type="text/javascript"></script> <script src="options/width-tests.js" type="text/javascript"></script>
<script src="results/focusing-tests.js" type="text/javascript"></script>
<script src="selection/allowClear-tests.js" type="text/javascript"></script> <script src="selection/allowClear-tests.js" type="text/javascript"></script>
<script src="selection/containerCss-tests.js" type="text/javascript"></script> <script src="selection/containerCss-tests.js" type="text/javascript"></script>
<script src="selection/multiple-tests.js" type="text/javascript"></script> <script src="selection/multiple-tests.js" type="text/javascript"></script>