From 7d8f86cbf85ebd2179195ff6a2a7a1c5dcb9da58 Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Wed, 19 Aug 2015 20:59:39 -0400 Subject: [PATCH] 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. --- tests/selection/multiple-tests.js | 52 +++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) 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'); +});