Add tests for removing a selection when disabled
These tests should fail because a selection can be removed even though the container is disabled. This is because the only thing preventing selections from being removed was the CSS which hid the remove buttons when the container was disabled.
This commit is contained in:
parent
671f5a2ce2
commit
7d8f86cbf8
@ -50,7 +50,7 @@ test('templateSelection can addClass', function (assert) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
var $container = selection.selectionContainer();
|
var $container = selection.selectionContainer();
|
||||||
|
|
||||||
var out = selection.display({
|
var out = selection.display({
|
||||||
text: 'test'
|
text: 'test'
|
||||||
}, $container);
|
}, $container);
|
||||||
@ -58,7 +58,7 @@ test('templateSelection can addClass', function (assert) {
|
|||||||
assert.ok(called);
|
assert.ok(called);
|
||||||
|
|
||||||
assert.equal(out, 'test');
|
assert.equal(out, 'test');
|
||||||
|
|
||||||
assert.ok($container.hasClass('testclass'));
|
assert.ok($container.hasClass('testclass'));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -99,3 +99,51 @@ test('escapeMarkup is being used', function (assert) {
|
|||||||
'The text should be escaped by default to prevent injection'
|
'The text should be escaped by default to prevent injection'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('clear button respects the disabled state', function (assert) {
|
||||||
|
var options = new Options({
|
||||||
|
disabled: true
|
||||||
|
});
|
||||||
|
|
||||||
|
var $select = $('#qunit-fixture .multiple');
|
||||||
|
|
||||||
|
var container = new MockContainer();
|
||||||
|
var $container = $('<div></div>');
|
||||||
|
|
||||||
|
var selection = new MultipleSelection(
|
||||||
|
$select,
|
||||||
|
options
|
||||||
|
);
|
||||||
|
|
||||||
|
var $selection = selection.render();
|
||||||
|
$container.append($selection);
|
||||||
|
|
||||||
|
selection.bind(container, $container);
|
||||||
|
|
||||||
|
// Select an option
|
||||||
|
selection.update([{
|
||||||
|
text: 'Test'
|
||||||
|
}]);
|
||||||
|
|
||||||
|
var $rendered = $selection.find('.select2-selection__rendered');
|
||||||
|
|
||||||
|
var $pill = $rendered.find('.select2-selection__choice');
|
||||||
|
|
||||||
|
assert.equal($pill.length, 1, 'There should only be one selection');
|
||||||
|
|
||||||
|
var $remove = $pill.find('.select2-selection__choice__remove');
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
$remove.length,
|
||||||
|
1,
|
||||||
|
'The remove icon is displayed for the selection'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Set up the unselect handler
|
||||||
|
selection.on('unselect', function (params) {
|
||||||
|
assert.ok(false, 'The unselect handler should not be triggered');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Trigger the handler for the remove icon
|
||||||
|
$remove.trigger('click');
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user