Skip to content

Commit

Permalink
Add tests for removing a selection when disabled
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kevin-brown committed Aug 20, 2015
1 parent 671f5a2 commit 7d8f86c
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions tests/selection/multiple-tests.js
Expand Up @@ -50,15 +50,15 @@ test('templateSelection can addClass', function (assert) {
);

var $container = selection.selectionContainer();

var out = selection.display({
text: 'test'
}, $container);

assert.ok(called);

assert.equal(out, 'test');

assert.ok($container.hasClass('testclass'));
});

Expand Down Expand Up @@ -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 = $('<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');
});

0 comments on commit 7d8f86c

Please sign in to comment.