diff --git a/tests/selection/multiple-tests.js b/tests/selection/multiple-tests.js index 8efe39ea..0d0f9c2e 100644 --- a/tests/selection/multiple-tests.js +++ b/tests/selection/multiple-tests.js @@ -50,7 +50,7 @@ test('templateSelection can addClass', function (assert) { ); var $container = selection.selectionContainer(); - + var out = selection.display({ text: 'test' }, $container); @@ -58,7 +58,7 @@ test('templateSelection can addClass', function (assert) { assert.ok(called); assert.equal(out, 'test'); - + 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' ); }); + +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 = $('
'); + + 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'); +});